Skip to content

Commit

Permalink
add heatmap figure #156
Browse files Browse the repository at this point in the history
  • Loading branch information
JavierCladellas committed Jan 23, 2025
1 parent eb8a451 commit eebb027
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 2 deletions.
31 changes: 31 additions & 0 deletions docs/modules/tutorial/pages/configurationfiles/plots.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,36 @@ fig = figures[0].createFigure(model.master_df)
fig.show()
----

- `heatmap`

For this case, we will consider the `elements` (N) as `color_axis` and `performance_variable` for secondary axis (slider).

[%dynamic%open%hide_code,python]
----
figures = FigureFactory.create(Plot(**{
"title": "Absolute performance",
"plot_types": [ "heatmap" ],
"transformation": "performance",
"variables": [ "computation_time","communication_time" ],
"names": ["Time"],
"color_axis":{
"parameter":"elements",
"label":"N"
},
"yaxis":{"label":"Execution time (s)"},
"secondary_axis":{
"parameter":"performance_variable",
"label":"Performance variable"
},
"xaxis":{
"parameter":"nb_tasks.tasks",
"label":"Number of tasks"
}
}))
fig = figures[0].createFigure(model.master_df)
fig.show()
----

- `table`

[%dynamic%open%hide_code,python]
Expand Down Expand Up @@ -312,6 +342,7 @@ fig = figures[0].createFigure(model.master_df)
fig.show()
----


== Aggregations

Depending on the dashboard level that we are located at, it might be necessary to aggregate the data on the master dataframe.
Expand Down
2 changes: 1 addition & 1 deletion src/feelpp/benchmarking/reframe/config/configPlots.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def checkAgg(cls, v):

class Plot(BaseModel):
title:str
plot_types:List[Literal["scatter","table","stacked_bar","grouped_bar"]]
plot_types:List[Literal["scatter","table","stacked_bar","grouped_bar","heatmap"]]
transformation:Literal["performance","relative_performance","speedup"]
aggregations:Optional[List[Aggregation]] = None
variables:Optional[List[str]] = None
Expand Down
47 changes: 47 additions & 0 deletions src/feelpp/benchmarking/report/figureFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,51 @@ def createSimpleFigure(self,df):
"""
return go.Figure(self.createTraces(df))

class HeatmapFigure(Figure):
def __init__(self, plot_config, transformation_strategy):
super().__init__(plot_config, transformation_strategy)

def createTraces(self, df):
""" Creates the Heatmap traces for a given dataframe. Useful for animation creation.
Args:
- df (pd.DataFrame): The dataframe containing the figure data.
Returns: (go.Trace) The Heatmap traces to display in the scatter figure.
"""
return go.Heatmap(
x=df.index.astype(str),
y=df.columns.astype(str),
z=df.T.values,
colorbar = dict(
title = self.config.yaxis.label
)
)

def createMultiindexFigure(self, df):
""" Creates a plotly figure from a multiIndex dataframe
Args:
df (pd.DataFrame). The transformed dataframe (must be multiindex)
Returns:
go.Figure: Heatmap animation where the secondary_ axis corresponds to a specified parameter
"""
return self.createSliderAnimation(df)

def createSimpleFigure(self, df):
""" Creates a plotly figure from a given dataframe
Args:
df (pd.DataFrame). The transformed dataframe
Returns:
go.Figure: Heatmap plot
"""
return go.Figure(self.createTraces(df))

def updateLayout(self, fig):
""" Sets the title, yaxis and legend attributes of the layout"""
fig.update_layout(
title=self.config.title,
xaxis=dict(title=self.config.xaxis.label),
yaxis=dict(title=self.config.color_axis.label)
)
return fig

class FigureFactory:
""" Factory class to dispatch concrete figure elements"""
Expand All @@ -305,6 +350,8 @@ def create(plot_config):
figures.append(StackedBarFigure(plot_config,strategy))
elif plot_type == "grouped_bar":
figures.append(GroupedBarFigure(plot_config,strategy))
elif plot_type == "heatmap":
figures.append(HeatmapFigure(plot_config,strategy))
else:
raise NotImplementedError

Expand Down
3 changes: 2 additions & 1 deletion tests/report/test_figureFactory.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from feelpp.benchmarking.report.figureFactory import FigureFactory, ScatterFigure, TableFigure, StackedBarFigure, GroupedBarFigure
from feelpp.benchmarking.report.figureFactory import FigureFactory, ScatterFigure, TableFigure, StackedBarFigure, GroupedBarFigure, HeatmapFigure
from test_transformationFactory import PlotConfigMocker
import pytest

Expand All @@ -10,6 +10,7 @@
(["table"],[TableFigure]),
(["stacked_bar"],[StackedBarFigure]),
(["grouped_bar"],[GroupedBarFigure]),
(["heatmap"],[HeatmapFigure]),
(["unkown"],[])
])
def test_figureFactory(types,expected_classes):
Expand Down

0 comments on commit eebb027

Please sign in to comment.