Sequence#

Module: exa.core.sequence.sequence

class Sequence(observation_stash=None, **kwargs)#

Bases: ABC

Base class for Sequences. New sequences are defined by subclassing this.

A subclass of Sequence should at least define name as a class attribute, and implement execute(), which is the main body of the sequence execution.

Parameters:
  • observation_stash (ObservationStash | None) – If provided, the observations created by the execution nodes will not be saved to the DB but to the given stash instead. In this case, any subsequences will by default copy that stash, add their observations to the copy, and only at the end of the subsequence execution, save them to the parent’s stash. The user may turn off the merging of stashes via the attribute save_stash and/or use a different stash (or no stash) for a given execution node in the actual implementation of execute().

  • kwargs – All keyword arguments to the constructor are copied to options attribute. The execute() can refer to the options to modify the behavior of the execution. The meaning of the options depends entirely on how they are used by execute(). The user may apply options to specific execution nodes via prefixing them with the node’s class names. E.g. to apply option foo = 1 for experiment class MyExperiment that is a part of the subsequence MySequence, the user should add MySequence_MyExperiment_foo = 1 to the kwargs.

Attributes

default_options

Required keys for the sequence options and their default values.

ignore_analyze_errors

Ignore analyze errors for this sequence and its subsequences.

save_stash

Whether to save this sequence's stash to the parent sequence's stash (or the DB if the parent does not have stash).

name

Identifier of the sequence type.

options

Options that modify the execution.

Methods

analysis

Function that performs sequence-level analysis based on the results of the executed nodes.

context

Generate a context manager inside execute().

execute

Executes the sequence.

set_attribute_options

Set the attribute values from options for the options defined in ATTRIBUTE_OPTIONS.

name: str#

Identifier of the sequence type.

static analysis(result, **kwargs)#

Function that performs sequence-level analysis based on the results of the executed nodes. It must take a SequenceResult as the first argument and return a SequenceAnalyzeResult. Other arguments are optional. analysis should be given as a class attribute, decorated with staticmethod. If a subclass does not define analysis, default_analysis() is used.

Parameters:

result (SequenceExecuteResult)

Return type:

SequenceAnalyzeResult

default_options: dict[str, Any] = {}#

Required keys for the sequence options and their default values.

tracker_class#

ExperimentTracker or a subclass of it. This class will be used when creating a tracker object in the execution context with track(). Giving your own tracker class allows modifying the execution of all experiments, for example by wrapping the run logic with custom conditions.

alias of ExperimentTracker

sequence_executor_class#

SequenceExecutor or a subclass of it. This class will be used when executing a sequence, and can be used to modify the sequence execution.

alias of SequenceExecutor

save_stash: bool = True#

Whether to save this sequence’s stash to the parent sequence’s stash (or the DB if the parent does not have stash). This attribute has an effect only if set at the subsequence level, and effect will not propagate to further subsequences. This attribute is also settable by including save_stash in the sequence options.

ignore_analyze_errors: bool | None = None#

Ignore analyze errors for this sequence and its subsequences. The observations and other analyze results will be retained if they were created successfully, but any analyze errors will still be shown in the report. If set, as True or False, the effect will propagate recursively to all subsequences and their experiments. This attribute is also settable by including ignore_analyze_errors in the sequence options.

options: dict[str, Any]#

Options that modify the execution. The values are either class-level defaults from default_options or kwargs given in the constructor. Options must contain only basic Python types.

context(sequence_run_id=None)#

Generate a context manager inside execute().

Parameters:

sequence_run_id (UUID | None) – If specified uses this id for the sequence.

Returns:

A new instance of SequenceContext.

Return type:

SequenceContext

set_attribute_options()#

Set the attribute values from options for the options defined in ATTRIBUTE_OPTIONS.

abstractmethod execute()#

Executes the sequence.

This is the main body of the execution code and should be implemented in a subclass.

Inside this method

  • A SequenceContext should be created by making a with self.context() as context: statement.

  • Under the with statement, all calls to Experiment.run(), Experiment.analyze(), and Sequence.execute() (of subsequences) should be made using the methods of context. Otherwise, those actions will not be tracked.

  • The method must end with return context.to_result(), called outside the scope of the above-mentioned with statement. It converts the captured results for further processing.

Returns:

A new instance of SequenceExecuteResult.

Return type:

SequenceExecuteResult

Inheritance

Inheritance diagram of exa.core.sequence.sequence.Sequence