Skip to content

Commit

Permalink
Removing plot generators
Browse files Browse the repository at this point in the history
  • Loading branch information
urig committed Jul 5, 2022
1 parent cb87c18 commit ced7b65
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 222 deletions.
44 changes: 0 additions & 44 deletions entropylab/pipeline/api/data_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
from typing import Any

import matplotlib
from bokeh.models import Renderer
from bokeh.plotting import Figure
from matplotlib.figure import Figure as matplotlibFigure
from plotly import graph_objects as go

Expand Down Expand Up @@ -75,48 +73,6 @@ class Debug:
extra: str


class PlotGenerator(ABC):
"""
An abstract class for plots.
Implementations of this class will let Entropy to save and view plots.
Every implementation can either implement all plotting functions
(within the different environments), or just part of it.
"""

def __init__(self) -> None:
super().__init__()

@abstractmethod
def plot_bokeh(self, figure: Figure, data, **kwargs) -> Renderer:
"""
plot the given data within the Bokeh Figure
:param figure: Bokeh figure to plot in
:param data: plot data
:param kwargs: extra parameters for plotting
"""
pass

@abstractmethod
def plot_matplotlib(self, figure: matplotlibFigure, data, **kwargs):
"""
plot the given data within the matplotlib Figure
:param figure: matplotlib figure
:param data: plot data
:param kwargs: extra parameters for plotting
"""
pass

@abstractmethod
def plot_plotly(self, figure: go.Figure, data, **kwargs) -> None:
"""
plot the given data within the plot.ly Figure
:param figure: plot.ly figure
:param data: plot data
:param kwargs: extra parameters for plotting
"""
pass


@dataclass
class NodeData:
"""
Expand Down
111 changes: 0 additions & 111 deletions entropylab/pipeline/api/plot.py

This file was deleted.

6 changes: 0 additions & 6 deletions entropylab/pipeline/tests/test_async_graph.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import asyncio

import numpy as np
from bokeh.plotting import Figure

from entropylab.pipeline.graph_experiment import (
Graph,
Expand Down Expand Up @@ -136,11 +135,6 @@ def test_async_graph():

results = graph.run().results
print(results.get_experiment_info())
plots = results.get_plots()
for plot in plots:
figure = Figure()
plot.generator.plot_bokeh(figure, plot.plot_data)
# save(figure, f"try{plot.label}.html")


def test_async_graph_run_to_node():
Expand Down
36 changes: 13 additions & 23 deletions entropylab/pipeline/tests/test_executor.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from datetime import datetime

import pytest
from plotly import express as px

from entropylab.pipeline.api.data_writer import PlotSpec
from entropylab.pipeline.api.execution import EntropyContext
from entropylab.pipeline.api.plot import CirclePlotGenerator, LinePlotGenerator
from entropylab.components.lab_topology import LabResources, ExperimentResources
from entropylab.pipeline.api.execution import EntropyContext
from entropylab.pipeline.results_backend.sqlalchemy.db import SqlAlchemyDB
from entropylab.pipeline.script_experiment import Script, script_experiment
from entropylab.pipeline.tests.mock_instruments import MockScope
Expand Down Expand Up @@ -64,14 +63,10 @@ def an_experiment_with_plot(experiment: EntropyContext):
experiment.add_result("b_result" + str(i), b1 + i + datetime.now().microsecond)

micro = datetime.now().microsecond
experiment.add_plot(
PlotSpec(
label="plot",
story="created this plot in experiment",
generator=CirclePlotGenerator,
),
data=[
[

experiment.add_figure(
px.scatter(
x=[
1 * micro,
2 * micro,
3 * micro,
Expand All @@ -81,20 +76,15 @@ def an_experiment_with_plot(experiment: EntropyContext):
7 * micro,
8 * micro,
],
[0, 1, 2, 3, 4, 5, 6, 7],
],
y=[0, 1, 2, 3, 4, 5, 6, 7],
)
)

experiment.add_plot(
PlotSpec(
label="another plot",
story="just showing off now",
generator=LinePlotGenerator,
),
data=[
[1, 2, 3, 4, 5, 6, 7, 8],
[4, 5, 6, 7, 0, 1, 2, 3],
],
experiment.add_figure(
px.line(
x=[1, 2, 3, 4, 5, 6, 7, 8],
y=[4, 5, 6, 7, 0, 1, 2, 3],
)
)


Expand Down
17 changes: 0 additions & 17 deletions entropylab/pipeline/tests/test_graph.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import asyncio
import os
from time import sleep

import pytest
from bokeh.io import save
from bokeh.plotting import Figure

from entropylab.pipeline.api.data_writer import PlotSpec
from entropylab.pipeline.api.execution import EntropyContext
from entropylab.pipeline.api.plot import CirclePlotGenerator
from entropylab.pipeline.graph_experiment import (
Graph,
PyNode,
Expand Down Expand Up @@ -52,10 +47,6 @@ def d(x, y):
async def e(y, z, context: EntropyContext):
print(f"Node e resting for {y / z}")
print(f"e Result: {y + z}")
context.add_plot(
PlotSpec(CirclePlotGenerator, "the best plot"),
data=[[0, 1, 2, 3, 4, 5], [y + z, 7, 6, 20, 10, 11]],
)
return {"y_z": [0, 1, 2, 3, 4, 5, y + z, 7, 6, 20, 10, 11]}


Expand Down Expand Up @@ -147,14 +138,6 @@ def test_sync_graph():

results = Graph(None, g, "run_a").run().results
print(results.get_experiment_info())
# TODO: Use figures instead of plots here
plots = results.get_plots()
for plot in plots:
figure = Figure()
plot.generator.plot_bokeh(figure, plot.plot_data)
if not os.path.exists("tests_cache"):
os.mkdir("tests_cache")
save(figure, f"tests_cache/bokeh-exported-{plot.label}.html")


def test_sync_graph_run_to_node():
Expand Down
21 changes: 0 additions & 21 deletions entropylab/pipeline/tests/test_plot.py

This file was deleted.

0 comments on commit ced7b65

Please sign in to comment.