SequenceContext#
Module: exa.core.sequence.context
- class SequenceContext(data, tracker_class=<class 'exa.core.sequence.experiment_tracker.ExperimentTracker'>, observation_stash=None, attribute_options=None, sequence_executor_class=<class 'exa.core.sequence.sequence_executor.SequenceExecutor'>, sequence_run_id=None)#
Bases:
objectA stateful object that provides the tools for Sequence execution and captures the inputs and outputs.
SequenceContext is a context object that captures the run IDs, analysis results, and analysis arguments for each
ExperimentorSequenceexecution done within the context.A user does not need to construct a SequenceContext. The intended way is to use it as a context manager, see
Sequence.context().If exceptions are caught in
execute_sequenceandexecute_experiment, error summary and traceback are stored in results. Execution errors are stored in sequence result data which will be stored to persistence. On the contrary, analysis errors are stored only locally in analyze results.Logging of errors is handled exclusively in
__exit__.- Parameters:
data (SequenceData) – The serializable part of the Sequence that will be executed with this context.
tracker_class (type[ExperimentTracker]) – Optional subclass of
ExperimentTracker. This class will be used when creating a tracker object withtrack().observation_stash (ObservationStash | None) – The stash to save observations to instead of the DB.
sequence_executer_class – Will be used when executing a sequence.
sequence_executor_class (type[SequenceExecutor])
sequence_run_id (UUID | None)
Attributes
Stores the observation stashes of any subsequences executed in this context (mapped to the
sequence_run_id).Methods
Get the captured data from an ExperimentTracker instance and store it to the context.
Run a single experiment and its analysis.
Execute and analyze another sequence in this context.
Converts the captured execution results into a
SequenceExecuteResultdata object.Create a tracker object that wraps an Experiment instance and captures the actions done with it.
- sub_stashes: dict[UUID, ObservationStash | None]#
Stores the observation stashes of any subsequences executed in this context (mapped to the
sequence_run_id).
- execute_experiment(experiment, custom_analysis=None, run_args=None, analyze_args=None, observation_stash=None)#
Run a single experiment and its analysis.
This includes:
running the experiment on hardware
analyzing the execution results with given arguments
tagging the observations from the analysis. Note: the
tagsentry ofSequence.optionswill be used for tagging, if any.saving the observations.
Under the hood, the Experiment is wrapped with
tracker_class, which means that a tracker class can be used to customize the behavior without callingtrack()explicitly.- Parameters:
experiment (Experiment | type[Experiment]) – The experiment to execute. Can be either an instance or a class, in which case a new instance is created.
custom_analysis (Callable[[...], AnalyzeResult] | None) – Custom analysis function for the experiment.
run_args (dict[str, Any] | None) – Arguments to pass to the
experiment.run, most commonly at least the list of components.analyze_args (dict[str, Any] | None) – Arguments to pass to the
experiment.analyze.observation_stash (ObservationStash | None) – The stash to save observations to instead of the DB. If not provided, will use the stash in
self._observation_stash, and if that is empty as well, the observations will be saved to the DB.
- Returns:
The result of the
experiment.analyze.- Return type:
- execute_sequence(sequence, analyze_args=None)#
Execute and analyze another sequence in this context.
The analyze_results of each Experiment or sub-sequence within sequence are captured.
If
sequencedoes not have a stash and the context hasself._observation_stashpopulated, will copy the contents ofself._observation_stashand runsequenceon that stash. At the end of execution, the stash ofsequencewill be saved (i.e. either merged toself._observation_stashor if that does not exist, saved to the DB) based on the value of the attribute optionsave_stash.- Parameters:
- Returns:
The analyzed result of executing sequence.
- Return type:
- to_result()#
Converts the captured execution results into a
SequenceExecuteResultdata object.As a side effect, the final result of this sequence is saved to persistence. The result is marked final after which further changes to it are prevented. Thus, this method is callable only once per object.
Should be called at the end of
Sequence.execute().- Returns:
A new instance of SequenceExecuteResult.
- Return type:
- track(experiment, observation_stash=None)#
Create a tracker object that wraps an Experiment instance and captures the actions done with it.
As an alternative to
execute_experiment(), the tracker allows a more fluent workflow with the experiment instance. The tracker behaves like a normal Experiment. The use cases are, for example, tuning settings, sweep ranges, and options before running.The tracker should only be used for one round of
run&analyze. After this,end_tracking()should be called.- Parameters:
experiment (Experiment | type[Experiment] | ExperimentTracker) – An Experiment instance or an Experiment class. In case of class, a new instance is created.
observation_stash (ObservationStash | None) – The stash to save observations to instead of the DB. If not provided, the observations
DB. (will be saved to the)
- Returns:
A new instance of ExperimentTracker. The created class is determined be
tracker_class.- Return type:
- end_tracking(tracker)#
Get the captured data from an ExperimentTracker instance and store it to the context.
This should be called after performing the desired
runandanalyzeactions with the tracker, so that the results and used arguments are stored.- Parameters:
tracker (ExperimentTracker) – the instance to get data from.
- Returns:
The AnalyzeResult captured by the tracker, if any.
- Return type:
- exception AnalyzeError#
Bases:
ExceptionInternal helper type for propagating analysis errors.
Analysis error can happen:
subsequence or experiment analysis in
execute_sequencemethod insidesequence.execute.in sequence analysis in
execute_sequencemethod.
Inheritance
