3.5.1. qupulse.program.linspace

Functions

to_increment_commands(linspace_nodes)

translate the given linspace node tree to a minimal sequence of set and increment commands as well as loops.

transform_linspace_commands(command_list, ...)

Classes

DepKey(factors)

The key that identifies how a certain set command depends on iteration indices.

DepState(base, iterations)

Increment(channel, value, dependency_key)

LinSpaceArbitraryWaveform(waveform, channels)

This is just a wrapper to pipe arbitrary waveforms through the system.

LinSpaceBuilder(channels)

This program builder supports efficient translation of pulse templates that use symbolic linearly spaced voltages and durations.

LinSpaceHold(bases, factors, duration_base, ...)

Hold voltages for a given time.

LinSpaceIter(body, length)

Iteration in linear space are restricted to range 0 to length.

LinSpaceNode()

AST node for a program that supports linear spacing of set points as well as nested sequencing and repetitions

LinSpaceProgram(root, defined_channels)

LinSpaceRepeat(body, count)

Repeat the body count times.

LinSpaceVM(channels[, sample_resolution])

LoopJmp(idx)

LoopLabel(idx, count)

Play(waveform, channels)

Set(channel, value, key)

Wait(duration)

class DepKey(factors: Tuple[int, ...])[source]

Bases: object

The key that identifies how a certain set command depends on iteration indices. The factors are rounded with a given resolution to be independent on rounding errors.

These objects allow backends which support it to track multiple amplitudes at once.

factors: Tuple[int, ...]
classmethod from_voltages(voltages: Sequence[float], resolution: float)[source]
class DepState(base: float, iterations: Tuple[int, ...])[source]

Bases: object

base: float
iterations: Tuple[int, ...]
required_increment_from(previous: DepState, factors: Sequence[float]) float[source]

Calculate the required increment from the previous state to the current given the factors that determine the voltage dependency of each index.

By convention there are only two possible values for each iteration index integer in self: 0 or the last index The three possible increments for each iteration are none, regular and jump to next line.

The previous dependency state can have a different iteration length if the trailing factors now or during the last iteration are zero.

Parameters:
  • previous – The previous state to calculate the required increment from. It has to belong to the same DepKey.

  • factors – The number of factors has to be the same as the current number of iterations.

Returns:

The increment

class Increment(channel: int, value: float, dependency_key: qupulse.program.linspace.DepKey)[source]

Bases: object

channel: int
dependency_key: DepKey
value: float
class LinSpaceArbitraryWaveform(waveform: Waveform, channels: Tuple[int | str, ...])[source]

Bases: LinSpaceNode

This is just a wrapper to pipe arbitrary waveforms through the system.

channels: Tuple[int | str, ...]
dependencies() Mapping[int, set[Tuple[float, ...]]][source]

Returns a mapping from channel indices to the iteration indices dependencies that those channels have inside this node.

Returns:

Mapping from channel indices to the iteration indices dependencies

reversed(offset: int, lengths: list)[source]

Get the time reversed version of this linspace node. Since this is a non-local operation the arguments give the context.

Parameters:
  • offset – Active iterations that are not reserved

  • lengths – Lengths of the currently active iterations that have to be reversed

Returns:

Time reversed version.

waveform: Waveform
class LinSpaceBuilder(channels: Tuple[int | str, ...])[source]

Bases: BaseProgramBuilder

This program builder supports efficient translation of pulse templates that use symbolic linearly spaced voltages and durations.

The channel identifiers are reduced to their index in the given channel tuple.

Arbitrary waveforms are not implemented yet

inner_scope(scope: Scope) Scope[source]

This function is necessary to inject program builder specific parameter implementations into the build process.

measure(measurements: Sequence[Tuple[str, Real, Real]] | None)[source]

Ignores measurements

new_subprogram(global_transformation: Transformation = None) ContextManager[ProgramBuilder][source]

Create a context managed program builder whose contents are translated into a single waveform upon exit if it is not empty.

Returns:

A context manager that returns a ProgramBuilder on entering.

time_reversed() Iterable[LinSpaceBuilder][source]

This returns a new context manager that will reverse everything added to it in time upon exit.

Returns:

A context manager that returns a ProgramBuilder on entering.

to_program() LinSpaceProgram | None[source]

Generate the final program. This is allowed to invalidate the program builder.

Returns:

A program implementation. None if nothing was added to this program builder.

with_iteration(index_name: str, rng: range, measurements: Sequence[Tuple[str, Real, Real]] | None = None) Iterable[ProgramBuilder][source]

Create an iterable that represent the body of the iteration. This can be an iterable with an element for each step in the iteration or a single object that represents the complete iteration.

Parameters:
  • index_name – The name of index

  • rng – The range if the index

  • measurements – Measurements to add iff the iteration body is not empty.

with_repetition(repetition_count: int | VolatileRepetitionCount | DynamicLinearValue[int], measurements: Sequence[Tuple[str, Real, Real]] | None = None) Iterable[ProgramBuilder][source]

Start a new repetition context with given repetition count. The caller has to iterate over the return value and call :py:meth:.ProgramBuilder.inner_scope` inside the iteration context.

Parameters:
  • repetition_count – Repetition count

  • measurements – These measurements are added relative to the position at the start of the iteration iff the iteration is not empty.

Returns:

An iterable of ProgramBuilder instances.

with_sequence(measurements: Sequence[Tuple[str, Real, Real]] | None = None) Iterable[ProgramBuilder][source]

Start a new sequence context. The caller has to enter the returned context manager and add the sequenced elements there.

Measurements that are added in to the returned program builder are discarded if the sequence is empty on exit.

Parameters:
  • measurements – These measurements are added relative to the position at the start of the sequence iff the

  • empty. (sequence is not)

Returns:

A context manager that returns a ProgramBuilder on entering.

class LinSpaceHold(bases: Tuple[float, ...], factors: Tuple[Tuple[float, ...] | None, ...], duration_base: TimeType, duration_factors: Tuple[TimeType, ...] | None)[source]

Bases: LinSpaceNode

Hold voltages for a given time. The voltages and the time may depend on the iteration index.

bases: Tuple[float, ...]
dependencies() Mapping[int, set][source]

Returns a mapping from channel indices to the iteration indices dependencies that those channels have inside this node.

Returns:

Mapping from channel indices to the iteration indices dependencies

duration_base: TimeType
duration_factors: Tuple[TimeType, ...] | None
factors: Tuple[Tuple[float, ...] | None, ...]
reversed(offset: int, lengths: list)[source]

Get the time reversed version of this linspace node. Since this is a non-local operation the arguments give the context.

Parameters:
  • offset – Active iterations that are not reserved

  • lengths – Lengths of the currently active iterations that have to be reversed

Returns:

Time reversed version.

class LinSpaceIter(body: Tuple[LinSpaceNode, ...], length: int)[source]

Bases: LinSpaceNode

Iteration in linear space are restricted to range 0 to length.

Offsets and spacing are stored in the hold node.

body: Tuple[LinSpaceNode, ...]
dependencies()[source]

Returns a mapping from channel indices to the iteration indices dependencies that those channels have inside this node.

Returns:

Mapping from channel indices to the iteration indices dependencies

length: int
reversed(offset: int, lengths: list)[source]

Get the time reversed version of this linspace node. Since this is a non-local operation the arguments give the context.

Parameters:
  • offset – Active iterations that are not reserved

  • lengths – Lengths of the currently active iterations that have to be reversed

Returns:

Time reversed version.

class LinSpaceNode[source]

Bases: ABC

AST node for a program that supports linear spacing of set points as well as nested sequencing and repetitions

abstractmethod dependencies() Mapping[int, set[Tuple[float, ...]]][source]

Returns a mapping from channel indices to the iteration indices dependencies that those channels have inside this node.

Returns:

Mapping from channel indices to the iteration indices dependencies

reversed(offset: int, lengths: list)[source]

Get the time reversed version of this linspace node. Since this is a non-local operation the arguments give the context.

Parameters:
  • offset – Active iterations that are not reserved

  • lengths – Lengths of the currently active iterations that have to be reversed

Returns:

Time reversed version.

class LinSpaceProgram(root: Tuple[qupulse.program.linspace.LinSpaceNode, ...], defined_channels: Tuple[int | str, ...])[source]

Bases: Program

defined_channels: Tuple[int | str, ...]
dependencies()[source]
property duration: TimeType

The duration of the program in nanoseconds.

get_defined_channels() AbstractSet[str | int][source]

Get the set of channels that are used in this program.

get_waveforms_dict(channels: Sequence[str | int], channel_transformations: Mapping[str | int, ChannelTransformation]) Mapping[Waveform, Any][source]
root: Tuple[LinSpaceNode, ...]
class LinSpaceRepeat(body: Tuple[LinSpaceNode, ...], count: int)[source]

Bases: LinSpaceNode

Repeat the body count times.

body: Tuple[LinSpaceNode, ...]
count: int
dependencies()[source]

Returns a mapping from channel indices to the iteration indices dependencies that those channels have inside this node.

Returns:

Mapping from channel indices to the iteration indices dependencies

reversed(offset: int, counts: list)[source]

Get the time reversed version of this linspace node. Since this is a non-local operation the arguments give the context.

Parameters:
  • offset – Active iterations that are not reserved

  • lengths – Lengths of the currently active iterations that have to be reversed

Returns:

Time reversed version.

class LinSpaceVM(channels: int, sample_resolution: TimeType = TimeType(1, 2))[source]

Bases: object

change_state(cmd: Set | Increment | Wait | Play)[source]
history: List[Tuple[TimeType, List[float]]]
run()[source]
set_commands(commands: Sequence[Increment | Set | LoopLabel | LoopJmp | Wait | Play])[source]
step()[source]
class LoopJmp(idx: int)[source]

Bases: object

idx: int
class LoopLabel(idx: int, count: int)[source]

Bases: object

count: int
idx: int
class Play(waveform: qupulse.program.waveforms.Waveform, channels: Tuple[str | int])[source]

Bases: object

channels: Tuple[str | int]
waveform: Waveform
class Set(channel: int, value: float, key: qupulse.program.linspace.DepKey = <factory>)[source]

Bases: object

channel: int
key: DepKey
value: float
class Wait(duration: qupulse.utils.types.TimeType)[source]

Bases: object

duration: TimeType
to_increment_commands(linspace_nodes: LinSpaceProgram) List[Increment | Set | LoopLabel | LoopJmp | Wait | Play][source]

translate the given linspace node tree to a minimal sequence of set and increment commands as well as loops.

transform_linspace_commands(command_list: List[Increment | Set | LoopLabel | LoopJmp | Wait | Play], channel_transformations: Mapping[str | int, ChannelTransformation]) List[Increment | Set | LoopLabel | LoopJmp | Wait | Play][source]