Sequence

class caqtus.session.Sequence(path: PureSequencePath | str, session: ExperimentSession)

Bases: object

Represent a sequence in the experiment session.

Sequence objects can be obtained by calling ExperimentSession.get_sequence(). The returned sequence object is bound to the session and is only valid in the context where the session is active.

Parameters:
  • path – The path of the sequence.

  • session – The session to which the sequence belongs. The sequence is bound to the session and is only valid in the context where the session is active.

classmethod create(
path: PureSequencePath,
iteration_configuration: IterationConfiguration,
time_lanes: TimeLanes,
session: ExperimentSession,
) Self

Create a new sequence in the session.

Parameters:
  • path – The path at which to create the sequence.

  • iteration_configuration – How the sequence parameters should be iterated over.

  • time_lanes – How the shots should be run.

  • session – The session in which the sequence should be created. The session must be active.

get_state() State

Return the state of the sequence.

get_global_parameters() ParameterNamespace

Return a copy of the parameter tables set for this sequence.

Raises:

RuntimeError – If the sequence is in DRAFT state, since the global parameters are only set once the sequence has entered the PREPARING state.

get_iteration_configuration() IterationConfiguration

Return the iteration configuration of the sequence.

get_time_lanes() TimeLanes

Return the time lanes that define how a shot is run for this sequence.

set_time_lanes(
time_lanes: TimeLanes,
) None

Set the time lanes that define how a shot is run for this sequence.

get_shots() Iterable[Shot]

Return the shots that belong to this sequence.

The shots are returned sorted by index.

get_start_time() datetime | None

Return the time the sequence was started.

If the sequence has not been started, return None.

get_end_time() datetime | None

Return the time the sequence was ended.

If the sequence has not been ended, return None.

get_expected_number_of_shots() int | Unknown

Return the expected number of shots for the sequence.

If the sequence has not been started, return None.

duplicate(
target_path: PureSequencePath | str,
) Sequence

Duplicate the sequence to a new path.

The sequence created will be in the draft state and will have the same iteration configuration and time lanes as the original sequence.

get_device_configurations() dict[DeviceName, DeviceConfiguration]

Return the device configurations used when the sequence was launched.

get_local_parameters() set[DottedVariableName]

Return the name of the parameters specifically set for this sequence.

get_parameter_names(
which: Literal['all', 'sequence'],
) set[DottedVariableName]

Return the name of the parameters used to run this sequence.

Parameters:

which

Which parameters to return.

  • all: Return both sequence specific and global parameters.

  • local: Return only the parameters specifically set for this sequence.

Returns:

The names of the parameters used to run this sequence.

get_traceback_summary() TracebackSummary | None

Return the traceback summary of the sequence.

Returns:

The summary of the exception that crashed the sequence if one could be retrieved, otherwise None.

Raises:

SequenceNotCrashedError – If the sequence is not in the CRASHED state.

get_parameter_schema() ParameterSchema

Return the types of the parameters used to run this sequence.

Examples

Get the units of a parameter:

schema = sequence.get_parameter_schema()
schema["mot.detuning"].units
# Unit("MHz")
scan() LazyFrame

Lazily read the data of the shots that have been run for this sequence.

Calling this function does not yet load any data. Instead, you should apply operations on the returned lazyframe and then call polars.LazyFrame.collect() to load the data. This will only fetch the data necessary to perform the requested operations.

Returns:

A lazy dataframe that can be used to fetch the data of the shots that have been run for this sequence. Each row in the dataframe corresponds to a shot.

The first columns contain the following metadata:

  • sequence: The name of the sequence the shot belongs to.

  • shot_index: The index of the shot in the sequence.

  • shot_start_time: The time the shot started.

  • shot_end_time: The time the shot ended.

The dataframe then contains columns for all the shot parameters and generated data.

Example:

>>> data = sequence.scan().head().collect()
┌──────────┬────────────┬─────────────────────┬────────────────────┬──────────┬────────────────────┐
│ sequence ┆ shot_index ┆ shot_start_time     ┆ shot_end_time      ┆ exposure ┆ Camera\picture 1   │
│ ---      ┆ ---        ┆ ---                 ┆ ---                ┆ ---      ┆ ---                │
│ cat      ┆ u64        ┆ datetime[ms, UTC]   ┆ datetime[ms, UTC]  ┆ f64      ┆ array[u32, (100,   │
│          ┆            ┆                     ┆                    ┆          ┆ 100)]              │
╞══════════╪════════════╪═════════════════════╪════════════════════╪══════════╪════════════════════╡
│ \test    ┆ 0          ┆ 2025-03-15          ┆ 2025-03-15         ┆ 0.0      ┆ [[0, 0, … 0], [0,  │
│          ┆            ┆ 14:03:30.476 UTC    ┆ 14:03:30.476 UTC   ┆          ┆ 0, … 0], … […      │
│ \test    ┆ 1          ┆ 2025-03-15          ┆ 2025-03-15         ┆ 1.0      ┆ [[1, 1, … 1], [1,  │
│          ┆            ┆ 14:03:30.478 UTC    ┆ 14:03:30.478 UTC   ┆          ┆ 1, … 1], … […      │
│ \test    ┆ 2          ┆ 2025-03-15          ┆ 2025-03-15         ┆ 2.0      ┆ [[2, 2, … 2], [2,  │
│          ┆            ┆ 14:03:30.486 UTC    ┆ 14:03:30.486 UTC   ┆          ┆ 2, … 2], … […      │
│ \test    ┆ 3          ┆ 2025-03-15          ┆ 2025-03-15         ┆ 3.0      ┆ [[3, 3, … 3], [3,  │
│          ┆            ┆ 14:03:30.490 UTC    ┆ 14:03:30.490 UTC   ┆          ┆ 3, … 3], … […      │
│ \test    ┆ 4          ┆ 2025-03-15          ┆ 2025-03-15         ┆ 4.0      ┆ [[4, 4, … 4], [4,  │
│          ┆            ┆ 14:03:30.492 UTC    ┆ 14:03:30.492 UTC   ┆          ┆ 4, … 4], … […      │
└──────────┴────────────┴─────────────────────┴────────────────────┴──────────┴────────────────────┘
load_shots_data(
importer: DataImporter,
tags: polars.type_aliases.FrameInitTypes | None = None,
) Iterable[polars.DataFrame]

Load the data of the shots that have been run for this sequence.

Parameters:
  • importer – A function that takes a shot and returns the data of the shot. It will be called for each shot in the sequence.

  • tags – An optional object that can be converted to a 1-row DataFrame. The dataframe will be joined with the data of each shot. This allows to add extra information to the dataframes returned for this sequence.

Yields:

Dataframes containing the data of the shots in the sequence ordered by shot index.

Deprecated since version 6.24.0: Use scan() instead as it is faster and easier to use.