From 8f48eeffc5d8a98585867dd007556a16d7bed29b Mon Sep 17 00:00:00 2001 From: Javier Cladellas Date: Fri, 22 Nov 2024 16:16:56 +0100 Subject: [PATCH 1/7] add optitmal and half-optimal columns to speedup strategy #122 --- src/feelpp/benchmarking/report/strategies.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/feelpp/benchmarking/report/strategies.py b/src/feelpp/benchmarking/report/strategies.py index 4be78b75..9ee6cf8a 100644 --- a/src/feelpp/benchmarking/report/strategies.py +++ b/src/feelpp/benchmarking/report/strategies.py @@ -87,10 +87,15 @@ def calculate(self,df): pivot = super().calculate(df) if isinstance(pivot.index, pd.MultiIndex): - return pivot.xs(pivot.index.get_level_values(self.dimensions["xaxis"]).min(),level=self.dimensions["xaxis"],axis=0) / pivot + pivot = pivot.xs(pivot.index.get_level_values(self.dimensions["xaxis"]).min(),level=self.dimensions["xaxis"],axis=0) / pivot + pivot["optimal"] = pivot.index.get_level_values(self.dimensions["xaxis"]) / pivot.index.get_level_values(self.dimensions["xaxis"]).min() + pivot["half-optimal"] = pivot.index.get_level_values(self.dimensions["xaxis"]) / pivot.index.get_level_values(self.dimensions["xaxis"]).min() / 2 + return pivot else: - return pivot.loc[pivot.index.min(),:] / pivot - + pivot = pivot.loc[pivot.index.min(),:] / pivot + pivot["optimal"] = pivot.index / pivot.index.min() + pivot["half-optimal"] = pivot.index / pivot.index.min() /2 + return pivot class StrategyFactory: """ Factory class to dispatch concrete transformation strategies""" From e1ff6f8bbaa401c6c1f41b3b6b92cbf5493fb271 Mon Sep 17 00:00:00 2001 From: Javier Cladellas Date: Fri, 22 Nov 2024 16:17:12 +0100 Subject: [PATCH 2/7] aff a fill lines parameter to add an area to scatter #122 --- .../benchmarking/report/figureFactory.py | 44 +++++++++++++------ 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/src/feelpp/benchmarking/report/figureFactory.py b/src/feelpp/benchmarking/report/figureFactory.py index d0a984d4..c84e00fa 100644 --- a/src/feelpp/benchmarking/report/figureFactory.py +++ b/src/feelpp/benchmarking/report/figureFactory.py @@ -21,8 +21,9 @@ def createFigure(self,df): class ScatterFigure(Figure): """ Concrete Figure class for scatter figures """ - def __init__(self, plot_config,transformation_strategy): + def __init__(self, plot_config,transformation_strategy,fill_lines=[]): super().__init__(plot_config,transformation_strategy) + self.fill_lines = fill_lines def createAnimation(self,df): """ Creates a plotly figure from a multiIndex dataframe @@ -39,14 +40,19 @@ def createAnimation(self,df): for j,dim in enumerate(anim_dimension_values): frame_df = df.xs(dim,level=self.config.secondary_axis.parameter,axis=0) - frames.append([ - go.Scatter( - x = frame_df.index, - y = frame_df.loc[:,col], - name=col + + frame_traces = [] + for i,col in enumerate(self.fill_lines): + frame_traces.append( + go.Scatter( x = frame_df.index, y = frame_df.loc[:,col], name = col, fill='tonexty' if i > 0 else None) ) - for col in frame_df.columns - ]) + + for col in [c for c in frame_df.columns if c not in self.fill_lines]: + frame_traces.append( + go.Scatter( x = frame_df.index, y = frame_df.loc[:,col], name = col ) + ) + + frames.append(frame_traces) ranges.append([ frame_df.min().min() - frame_df.min().min()*range_epsilon, frame_df.max().max() + frame_df.min().min()*range_epsilon @@ -84,11 +90,7 @@ def createSimple(self,df): Returns: go.Figure: Scatter plot """ - return go.Figure( - data = [ - go.Scatter( x = df.index, y = df.loc[:,col], name = col ) - for col in df.columns - ], + figure = go.Figure( layout=go.Layout( title=self.config.title, xaxis=dict( title = self.config.xaxis.label ), @@ -96,6 +98,16 @@ def createSimple(self,df): legend=dict(title=self.config.color_axis.label if self.config.color_axis else "") ) ) + for i,col in enumerate(self.fill_lines): + figure.add_trace( + go.Scatter( x = df.index, y = df.loc[:,col], name = col, fill='tonexty' if i < len(self.fill_lines) else None) + ) + + for col in [c for c in df.columns if c not in self.fill_lines]: + figure.add_trace( + go.Scatter( x = df.index, y = df.loc[:,col], name = col ) + ) + return figure def createFigure(self,df): """ Creates a scatter plot from the master dataframe @@ -338,7 +350,11 @@ def create(plot_config): figures = [] for plot_type in plot_config.plot_types: if plot_type == "scatter": - figures.append(ScatterFigure(plot_config,strategy)) + if plot_config.transformation=="speedup": + fill_lines = ["optimal","half-optimal"] + else: + fill_lines = [] + figures.append(ScatterFigure(plot_config,strategy, fill_lines)) elif plot_type == "table": figures.append(TableFigure(plot_config,strategy)) elif plot_type == "stacked_bar": From 2a903a55d8466372c392649efe26e247caa21be6 Mon Sep 17 00:00:00 2001 From: Javier Cladellas Date: Fri, 22 Nov 2024 16:48:38 +0100 Subject: [PATCH 3/7] add optional layout_modifiers #122 --- .../reframe/config/configPlots.py | 1 + .../benchmarking/report/figureFactory.py | 29 ++++++++++++------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/feelpp/benchmarking/reframe/config/configPlots.py b/src/feelpp/benchmarking/reframe/config/configPlots.py index 755f04e7..5e7dedbd 100644 --- a/src/feelpp/benchmarking/reframe/config/configPlots.py +++ b/src/feelpp/benchmarking/reframe/config/configPlots.py @@ -27,6 +27,7 @@ class Plot(BaseModel): secondary_axis:Optional[PlotAxis] = None yaxis:PlotAxis color_axis:Optional[PlotAxis] = None + layout_modifiers: Optional[Dict] = {} @field_validator("xaxis","secondary_axis", mode="after") diff --git a/src/feelpp/benchmarking/report/figureFactory.py b/src/feelpp/benchmarking/report/figureFactory.py index c84e00fa..e5ba4627 100644 --- a/src/feelpp/benchmarking/report/figureFactory.py +++ b/src/feelpp/benchmarking/report/figureFactory.py @@ -119,9 +119,11 @@ def createFigure(self,df): df = self.transformation_strategy.calculate(df) if isinstance(df.index,MultiIndex): - return self.createAnimation(df) + figure = self.createAnimation(df) else: - return self.createSimple(df) + figure = self.createSimple(df) + figure.update_layout(self.plot_config.layout_modifiers) + return figure class TableFigure(Figure): @@ -175,10 +177,11 @@ def createFigure(self,df): df = self.transformation_strategy.calculate(df) if isinstance(df.index,MultiIndex): - return self.createMultiindex(df) + figure = self.createMultiindex(df) else: - return self.createSimple(df) - + figure = self.createSimple(df) + figure.update_layout(self.plot_config.layout_modifiers) + return figure class StackedBarFigure(Figure): """ Concrete Figure class for stacked bar charts""" @@ -248,9 +251,12 @@ def createFigure(self,df): df = self.transformation_strategy.calculate(df) if isinstance(df.index,MultiIndex): - return self.createGrouped(df) + figure = self.createGrouped(df) else: - return self.createSimple(df) + figure = self.createSimple(df) + + figure.update_layout(self.plot_config.layout_modifiers) + return figure class GroupedBarFigure(Figure): #TODO: FACTOR animation and bar... def __init__(self, plot_config, transformation_strategy): @@ -333,10 +339,12 @@ def createFigure(self,df): df = self.transformation_strategy.calculate(df) if isinstance(df.index,MultiIndex): - return self.createGrouped(df) + figure = self.createGrouped(df) else: - return self.createSimple(df) + figure = self.createSimple(df) + figure.update_layout(self.plot_config.layout_modifiers) + return figure class FigureFactory: """ Factory class to dispatch concrete figure elements""" @@ -350,10 +358,9 @@ def create(plot_config): figures = [] for plot_type in plot_config.plot_types: if plot_type == "scatter": + fill_lines = [] if plot_config.transformation=="speedup": fill_lines = ["optimal","half-optimal"] - else: - fill_lines = [] figures.append(ScatterFigure(plot_config,strategy, fill_lines)) elif plot_type == "table": figures.append(TableFigure(plot_config,strategy)) From 1cf972542e13698454dd97fe8f8337508a7ccefa Mon Sep 17 00:00:00 2001 From: Javier Cladellas Date: Wed, 18 Dec 2024 13:11:38 +0100 Subject: [PATCH 4/7] typo --- src/feelpp/benchmarking/report/figureFactory.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/feelpp/benchmarking/report/figureFactory.py b/src/feelpp/benchmarking/report/figureFactory.py index e5ba4627..9aef8777 100644 --- a/src/feelpp/benchmarking/report/figureFactory.py +++ b/src/feelpp/benchmarking/report/figureFactory.py @@ -122,7 +122,7 @@ def createFigure(self,df): figure = self.createAnimation(df) else: figure = self.createSimple(df) - figure.update_layout(self.plot_config.layout_modifiers) + figure.update_layout(self.config.layout_modifiers) return figure @@ -180,7 +180,7 @@ def createFigure(self,df): figure = self.createMultiindex(df) else: figure = self.createSimple(df) - figure.update_layout(self.plot_config.layout_modifiers) + figure.update_layout(self.config.layout_modifiers) return figure class StackedBarFigure(Figure): @@ -255,7 +255,7 @@ def createFigure(self,df): else: figure = self.createSimple(df) - figure.update_layout(self.plot_config.layout_modifiers) + figure.update_layout(self.config.layout_modifiers) return figure class GroupedBarFigure(Figure): #TODO: FACTOR animation and bar... @@ -343,7 +343,7 @@ def createFigure(self,df): else: figure = self.createSimple(df) - figure.update_layout(self.plot_config.layout_modifiers) + figure.update_layout(self.config.layout_modifiers) return figure class FigureFactory: From 58d2ad49ae6aab439f8b81777b906f82b2fa3f14 Mon Sep 17 00:00:00 2001 From: Javier Cladellas Date: Wed, 18 Dec 2024 13:45:59 +0100 Subject: [PATCH 5/7] fix half-optimal starting point #122 --- src/feelpp/benchmarking/report/strategies.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/feelpp/benchmarking/report/strategies.py b/src/feelpp/benchmarking/report/strategies.py index 9ee6cf8a..79d280ef 100644 --- a/src/feelpp/benchmarking/report/strategies.py +++ b/src/feelpp/benchmarking/report/strategies.py @@ -89,13 +89,12 @@ def calculate(self,df): if isinstance(pivot.index, pd.MultiIndex): pivot = pivot.xs(pivot.index.get_level_values(self.dimensions["xaxis"]).min(),level=self.dimensions["xaxis"],axis=0) / pivot pivot["optimal"] = pivot.index.get_level_values(self.dimensions["xaxis"]) / pivot.index.get_level_values(self.dimensions["xaxis"]).min() - pivot["half-optimal"] = pivot.index.get_level_values(self.dimensions["xaxis"]) / pivot.index.get_level_values(self.dimensions["xaxis"]).min() / 2 - return pivot else: pivot = pivot.loc[pivot.index.min(),:] / pivot pivot["optimal"] = pivot.index / pivot.index.min() - pivot["half-optimal"] = pivot.index / pivot.index.min() /2 - return pivot + + pivot["half-optimal"] = (pivot["optimal"] -1) / 2 + 1 + return pivot class StrategyFactory: """ Factory class to dispatch concrete transformation strategies""" From 3f7cfe7fe2bba6c1a3577ea1cef1c4e9e6f365dd Mon Sep 17 00:00:00 2001 From: Javier Cladellas Date: Wed, 18 Dec 2024 13:48:48 +0100 Subject: [PATCH 6/7] change color and line mode #122 --- src/feelpp/benchmarking/report/figureFactory.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/feelpp/benchmarking/report/figureFactory.py b/src/feelpp/benchmarking/report/figureFactory.py index 9aef8777..8c78bd64 100644 --- a/src/feelpp/benchmarking/report/figureFactory.py +++ b/src/feelpp/benchmarking/report/figureFactory.py @@ -44,7 +44,7 @@ def createAnimation(self,df): frame_traces = [] for i,col in enumerate(self.fill_lines): frame_traces.append( - go.Scatter( x = frame_df.index, y = frame_df.loc[:,col], name = col, fill='tonexty' if i > 0 else None) + go.Scatter( x = frame_df.index, y = frame_df.loc[:,col], name = col, fill='tonexty' if i > 0 else None, line=dict(color="black",dash="dash") ,mode="lines") ) for col in [c for c in frame_df.columns if c not in self.fill_lines]: @@ -100,7 +100,7 @@ def createSimple(self,df): ) for i,col in enumerate(self.fill_lines): figure.add_trace( - go.Scatter( x = df.index, y = df.loc[:,col], name = col, fill='tonexty' if i < len(self.fill_lines) else None) + go.Scatter( x = df.index, y = df.loc[:,col], name = col, fill='tonexty' if i < len(self.fill_lines) else None, line=dict(color="black",dash="dash") ,mode="lines") ) for col in [c for c in df.columns if c not in self.fill_lines]: From 654fb73abdc1aaa8decdb0c9058939b6d5573db2 Mon Sep 17 00:00:00 2001 From: Javier Cladellas Date: Wed, 18 Dec 2024 13:58:33 +0100 Subject: [PATCH 7/7] try fix line filling #122 --- src/feelpp/benchmarking/report/figureFactory.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/feelpp/benchmarking/report/figureFactory.py b/src/feelpp/benchmarking/report/figureFactory.py index 8c78bd64..4e06c483 100644 --- a/src/feelpp/benchmarking/report/figureFactory.py +++ b/src/feelpp/benchmarking/report/figureFactory.py @@ -100,7 +100,7 @@ def createSimple(self,df): ) for i,col in enumerate(self.fill_lines): figure.add_trace( - go.Scatter( x = df.index, y = df.loc[:,col], name = col, fill='tonexty' if i < len(self.fill_lines) else None, line=dict(color="black",dash="dash") ,mode="lines") + go.Scatter( x = df.index, y = df.loc[:,col], name = col, fill='tonexty' if i > 0 else None, line=dict(color="black",dash="dash") ,mode="lines") ) for col in [c for c in df.columns if c not in self.fill_lines]: