Skip to content

Commit

Permalink
Improve notebook display of AnalysisCards (#2899)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #2899

Display title and subtitle, and sort cards by level in display_cards. Useful for using with AxClient in a notebook.

Also add minimum_priority argument to display_cards, by default show everything but debug

Reviewed By: danielcohenlive

Differential Revision: D64495780

fbshipit-source-id: 816f0f7735b7228a14b3713ab4bfa6a45e64dd36
  • Loading branch information
mpolson64 authored and facebook-github-bot committed Oct 18, 2024
1 parent 37e5740 commit f5d6d4c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
16 changes: 12 additions & 4 deletions ax/analysis/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from ax.utils.common.base import Base
from ax.utils.common.logger import get_logger
from ax.utils.common.result import Err, ExceptionE, Ok, Result
from IPython.display import display
from IPython.display import display, Markdown

logger: Logger = get_logger(__name__)

Expand Down Expand Up @@ -79,15 +79,23 @@ def _ipython_display_(self) -> None:
By default, this method displays the raw data in a pandas DataFrame.
"""
display(Markdown(f"## {self.title}\n\n### {self.subtitle}"))
display(self.df)


def display_cards(cards: Iterable[AnalysisCard]) -> None:
def display_cards(
cards: Iterable[AnalysisCard], minimum_level: int = AnalysisCardLevel.LOW
) -> None:
"""
Display a collection of AnalysisCards in IPython environments (ex. Jupyter).
Args:
cards: Collection of AnalysisCards to display.
minimum_level: Minimum level of cards to display.
"""
for card in cards:
display(card)
for card in sorted(cards, key=lambda x: x.level, reverse=True):
if card.level >= minimum_level:
display(card)


class Analysis(Protocol):
Expand Down
2 changes: 1 addition & 1 deletion ax/analysis/markdown/markdown_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def _ipython_display_(self) -> None:
IPython display hook. This is called when the AnalysisCard is printed in an
IPython environment (ex. Jupyter). Here we want to render the Markdown.
"""
display(Markdown(self.blob))
display(Markdown(f"## {self.title}\n\n### {self.subtitle}\n\n{self.blob}"))


class MarkdownAnalysis(Analysis):
Expand Down
3 changes: 2 additions & 1 deletion ax/analysis/plotly/plotly_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from ax.analysis.analysis import Analysis, AnalysisCard
from ax.core.experiment import Experiment
from ax.core.generation_strategy_interface import GenerationStrategyInterface
from IPython.display import display
from IPython.display import display, Markdown
from plotly import graph_objects as go, io as pio


Expand All @@ -25,6 +25,7 @@ def _ipython_display_(self) -> None:
IPython display hook. This is called when the AnalysisCard is printed in an
IPython environment (ex. Jupyter). Here we want to display the Plotly figure.
"""
display(Markdown(f"## {self.title}\n\n### {self.subtitle}"))
display(self.get_figure())


Expand Down

0 comments on commit f5d6d4c

Please sign in to comment.