Skip to content

Commit

Permalink
MNT Rename ElogSummaryPlots, clean-up Executor-side processing
Browse files Browse the repository at this point in the history
  • Loading branch information
gadorlhiac committed May 17, 2024
1 parent 28ddd65 commit ac61d05
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 31 deletions.
49 changes: 23 additions & 26 deletions lute/execution/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,17 +405,14 @@ def _set_result_from_parameters(self) -> None:
"Cannot set result from TaskParameters. TaskParameters is None!"
)
return
if not hasattr(self._analysis_desc.task_parameters.Config, "set_result"):
if (
not hasattr(self._analysis_desc.task_parameters.Config, "set_result")
or not self._analysis_desc.task_parameters.Config.set_result
):
logger.debug(
(
"Cannot set result from TaskParameters. `set_result` not specified!"
" Perhaps this is not a ThirdPartyTask?"
" This method should only be used when running a ThirdPartyTask."
)
"Cannot set result from TaskParameters. `set_result` not specified!"
)
return
if not self._analysis_desc.task_parameters.Config.set_result:
return

# First try to set from result_from_params (faster)
if self._analysis_desc.task_parameters.Config.result_from_params is not None:
Expand All @@ -434,7 +431,6 @@ def _set_result_from_parameters(self) -> None:
for param, value in self._analysis_desc.task_parameters.dict().items():
param_attrs: Dict[str, Any] = schema["properties"][param]
if "is_result" in param_attrs:
# is_result: Union[str, bool] = param_attrs["is_result"]
is_result: bool = param_attrs["is_result"]
if isinstance(is_result, bool) and is_result:
logger.info(f"TaskResult specified as {value}.")
Expand Down Expand Up @@ -472,11 +468,6 @@ def _set_result_from_parameters(self) -> None:
" but no schema provided! Check model definition!"
)
)
# if hasattr(self._analysis_desc.task_parameters.Config, "impl_schemas"):
# impl_schemas: Optional[str] = (
# self._analysis_desc.task_parameters.Config.impl_schemas
# )
# self._analysis_desc.task_result.impl_schemas = impl_schemas

def process_results(self) -> None:
"""Perform any necessary steps to process TaskResults object.
Expand Down Expand Up @@ -640,19 +631,25 @@ def _process_results(self) -> None:
self._process_result_summary(task_result.summary)

def _process_result_payload(self, payload: Any) -> None:
if self._analysis_desc.task_parameters is None:
logger.debug("Please run Task before using this method!")
return
if isinstance(payload, ElogSummaryPlots):
# ElogSummaryPlots has figures and a navigation save name
try:
# Preferred use is panel.Tabs
if not os.path.isdir(payload.save_path):
os.makedirs(payload.save_path)
payload.figures.save(f"{payload.save_path}/report.html")
except AttributeError: # Not panel.Tabs
try:
# Attempt matplotlib...
...
except:
...
# ElogSummaryPlots has figures and a display name
# display name also serves as a path.
expmt: str = self._analysis_desc.task_parameters.lute_config.experiment
base_path: str = f"/sdf/data/lcls/ds/{expmt[:3]}/{expmt}/stats/summary"
full_path: str = f"{base_path}/{payload.display_name}"
if not os.path.isdir(full_path):
os.makedirs(full_path)

# Preferred plots are pn.Tabs objects which save directly as html
# Only supported plot type that has "save" method - do not want to
# import plot modules here to do type checks.
if hasattr(payload.figures, "save"):
payload.figures.save(f"{full_path}/report.html")
else:
...
elif isinstance(payload, str):
# May be a path to a file...
schemas: Optional[str] = self._analysis_desc.task_result.impl_schemas
Expand Down
12 changes: 7 additions & 5 deletions lute/tasks/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
parameters, env).
"""

from __future__ import annotations

__all__ = ["TaskResult", "TaskStatus", "DescribedAnalysis", "ElogSummaryPlots"]
__author__ = "Gabriel Dorlhiac"

Expand Down Expand Up @@ -85,15 +87,15 @@ class ElogSummaryPlots:
"""Holds a graphical summary intended for display in the eLog.
Attributes:
save_path (str): This represents both a path and how the result will be
displayed on the eLog. Can include "/" characters. E.g.
`navigation_display = "scans/my_motor_scan"` will have plots shown
display_name (str): This represents both a path and how the result will be
displayed in the eLog. Can include "/" characters. E.g.
`display_name = "scans/my_motor_scan"` will have plots shown
on a "my_motor_scan" page, under a "scans" tab. This format mirrors
how the file is stored on disk as well.
"""

save_path: str
figures: Union["pn.Tabs", "hv.Image", "plt.Figure"]
display_name: str
figures: Union[pn.Tabs, hv.Image, plt.Figure]


@dataclass
Expand Down

0 comments on commit ac61d05

Please sign in to comment.