TimedInstruction

class caqtus.shot_compilation.timed_instructions.TimedInstruction

Bases: ABC, Generic

An immutable representation of instructions to output on a sequencer.

This represents a high-level series of instructions to output on a sequencer. Each instruction is a compact representation of values to output at integer time steps. The length of the instruction is the number of time steps it takes to output all the values. The width of the instruction is the number of channels that are output at each time step.

Instructions can be concatenated in time using the + operator or the concatenate(). An instruction can be repeated using the * operator with an integer.

abstract property dtype: numpy.dtype[T]

Returns the dtype of the instruction.

abstractmethod as_type(
dtype: dtype,
) TimedInstruction

Returns a new instruction with the given dtype.

property width: Width

Returns the number of parallel channels that are output at each time step.

abstract property depth: Depth

Returns the number of nested instructions.

The invariant instruction.depth <= len(instruction) always holds.

abstractmethod to_pattern() Pattern[T]

Returns a flattened pattern of the instruction.

abstractmethod apply(
func: Callable[[Array1D[T]], Array1D[S]],
) TimedInstruction[S]

Applies an element-wise function to the values of the instruction.

Parameters:

func – The function to apply to the values of the instruction. It must take a 1D numpy array with the same dtype as the instruction and return a 1D numpy array with the same length and a (possibly) different dtype.

Returns:

A new instruction with the function applied to the values. The length of the new instruction is the same as the original instruction.

Raises:

ValueError – If the function does not return an array of the same length as the one given.