Pattern

class caqtus.shot_compilation.timed_instructions.Pattern(pattern: npt.ArrayLike, dtype: np.dtype[T] | None = None)

Bases: TimedInstruction, Generic

An instruction representing a sequence of values.

This is a fully explicit instruction for which each sample point must be given.

Parameters:
  • pattern – The sequence of values that this pattern represents.

  • dtype – The dtype of the pattern. If not provided, it is inferred from the values.

Raises:

ValueError – If the pattern contains non-finite values.

property dtype: numpy.dtype[T]

Returns the dtype of the instruction.

as_type(
dtype: dtype,
) Pattern

Returns a new instruction with the given dtype.

property depth: Depth

Returns the number of nested instructions.

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

to_pattern() Pattern[T]

Returns a flattened pattern of the instruction.

apply(func: Callable[[Array1D[T]], Array1D[S]]) Pattern[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.