qat.ir.instruction_builder module

class InstructionBuilder(hardware_model, instructions=[], _qubit_index_by_uuid=None, _qubits_ordered_by_index=None)

Bases: ABC

Abstract class for assembling quantum programs.

Provides a number of methods to deal with common quantum semantics, such as qubits, gates, measurements, and control flow. The details of how quantum operations are implemented are left to child classes.

abstract ECR(control, target)
S(target)
SX(target)
SXdg(target)
Sdg(target)
T(target)
Tdg(target)
abstract U(target, theta, phi, lamb, pulse_channel=None)
abstract X(target, theta=3.141592653589793, pulse_channel=None)
abstract Y(target, theta=3.141592653589793, pulse_channel=None)
abstract Z(target, theta=3.141592653589793, pulse_channel=None)
add(*instructions, flatten=False)

Add one or more instruction(s) into this builder. All methods should use this instead of accessing the instructions tree directly as it deals with composite instructions.

assign(name, value)
cX(controllers, target, theta=3.141592653589793)
cY(controllers, target, theta=3.141592653589793)
cZ(controllers, target, theta=3.141592653589793)
abstract ccnot(controllers, target)
cnot(control, target)
static constrain(angle)

Constrain the rotation angle to avoid redundant rotations around the Bloch sphere.

abstract controlled(controllers, builder)
cswap(controllers, target, destination)
flatten()

Flatten the instruction builder by removing nested structures like InstructionBlocks.

get_logical_qubit(index)

Returns the qubit assigned with the given logical index.

Parameters:

index (int) – The logical index of the qubit to return.

Return type:

Qubit

Returns:

The qubit with the given logical index.

get_physical_qubit(index)

Returns the qubit assigned with the given physical index.

Parameters:

index (int) – The index of the qubit to return.

Return type:

Qubit

Returns:

The qubit with the given index.

had(target)
property instructions
jump(label, condition=None)
abstract measure_single_shot_z(target, axis=SEQUENCE, output_variable=None)
property number_of_instructions
property qubits: list[Qubit]

Returns the list of qubits, sorted by index.

repeat(repeat_count)
abstract reset(targets, **kwargs)
results_processing(variable, res_format)
returns(variables=None)

Add return statement.

abstract swap(target, destination)
PydQuantumInstructionBuilder

alias of QuantumInstructionBuilder

class QuantumInstructionBuilder(*args, **kwargs)

Bases: InstructionBuilder

A pulse-level instruction builder, that provides implementations of quantum gates, and an API for pulse-level instructions.

ECR(control, target)
U(target, theta, phi, lamb, pulse_channel=None)

Adds an arbitrary rotation around the Bloch sphere with 3 Euler angles to the builder (see https://doi.org/10.48550/arXiv.1707.03429).

Parameters:
  • target (Qubit) – The qubit to be rotated.

  • theta (float) – Rotation angle.

  • phi (float) – Rotation angle.

  • lamb (float) – Rotation angle.

  • pulse_channel (Optional[PulseChannel]) – The pulse channel the pulses get sent to.

X(target, theta=3.141592653589793, *args, **kwargs)
Y(target, theta=3.141592653589793, *args, **kwargs)
Z(target, theta=3.141592653589793, *args, **kwargs)
ZX(target1, target2, theta=0.7853981633974483)

Adds a two-qubit interaction gate exp(-i heta Z x X) to the builder.

Parameters:
  • target1 (Qubit) – The qubit to which Z gets applied to.

  • target2 (Qubit) – The qubit to which X gets applied to.

  • theta (float) – The applied rotation angle.

acquire(target, delay=1e-06, **kwargs)
ccnot(controllers, target)
cnot(control, target)
controlled(controllers, builder)
create_pulse_channel(frequency, physical_channel, imbalance=1.0, phase_iq_offset=0.0, scale=1 + 0j, uuid=None)

Creates a pulse channel and adds stores it within the builder.

The channel can be provided as a physical channel which the logical channel is linked too, or use the physical channel of a provided pulse channel.

Return type:

PulseChannel

delay(target, duration)
frequency_shift(target, frequency)
get_pulse_channel(id)

Given an id, return the corresponding pulse channel.

Checks internally stored pulse channels, but can pull pulse channels from the hardware model if not found.

Return type:

PulseChannel

measure(targets, mode=INTEGRATOR, output_variable=None, sync_qubits=True)

Measure one or more qubits.

Parameters:
  • targets (Qubit | set[Qubit]) – The qubit(s) to be measured.

  • mode (AcquireMode) – The type of acquisition at the level of the control hardware.

  • sync_qubits (bool) – Flag determining whether to align the measurements of all qubits in targets or not. Sync between qubits is on by default.

Return type:

QuantumInstructionBuilder

measure_mean_signal(target, output_variable=None)

Measure the signal of a single qubit. Execution results in an array of complex numbers that show the war signal output form the hardware. Each entry is for each qubit measured, and is the mean of the results from measure_single_signal_shot.

Parameters:
  • target (Qubit) – The qubit to be measured.

  • output_variable (Optional[str]) – The variable where the output of the acquire should be saved.

measure_mean_z(target, axis=SEQUENCE, output_variable=None)

Measure a single qubit along the z-axis. Execution results in an array of floats centred around 0, where anything above 0 shows a bias towards a +Z measurement, and below 0 shows a bias towards a -Z measurement. Each entry is for each qubit measured, and is the mean of the results from measure_single_shot_z.

Parameters:
  • target (Qubit) – The qubit to be measured.

  • axis (ProcessAxis) – The type of axis which the post-processing of readouts should occur on.

  • output_variable (Optional[str]) – The variable where the output of the acquire should be saved.

measure_scope_mode(target, output_variable=None)

Measure the scope mode

Parameters:
  • target (Qubit) – The qubit to be measured.

  • output_variable (Optional[str]) – The variable where the output of the acquire should be saved.

measure_single_shot_binned(target, axis=SEQUENCE, output_variable=None)

Measure a single qubit along the z-axis. Execution results in an array of ±1s, where 1 indicates a +Z measurement, and -1 indicates a -Z measurement. It takes the results from measure_single_shot_z and applies a binning operation to round the results to ±1. The array is an ndarray, where the first dimension is for each of the qubits measured, the second dimension is for each shot run.

Parameters:
  • target (Qubit) – The qubit to be measured.

  • axis (ProcessAxis) – The type of axis which the post-processing of readouts should occur on.

  • output_variable (Optional[str]) – The variable where the output of the acquire should be saved.

measure_single_shot_signal(target, axis=SEQUENCE, output_variable=None)

Measure the signal of a single qubit. Execution results in an array of complex numbers that show the war signal output form the hardware. The array is an ndarray, where the first dimension is for each of the qubits measured, the second dimension is for each shot run.

Parameters:
  • target (Qubit) – The qubit to be measured.

  • axis (ProcessAxis) – The type of axis which the post-processing of readouts should occur on.

  • output_variable (Optional[str]) – The variable where the output of the acquire should be saved.

measure_single_shot_z(target, axis=SEQUENCE, output_variable=None)

Measure a single qubit along the z-axis. Execution results in an array of floats centred around 0, where anything above 0 shows a bias towards a +Z measurement, and below 0 shows a bias towards a -Z measurement. The array is an ndarray, where the first dimension is for each of the qubits measured, the second dimension is for each shot run.

Parameters:
  • target (Qubit) – The qubit to be measured.

  • axis (ProcessAxis) – The type of axis which the post-processing of readouts should occur on.

  • output_variable (Optional[str]) – The variable where the output of the acquire should be saved.

phase_shift(target, theta=3.141592653589793, *args, **kwargs)
post_processing(target, output_variable, process_type, axes=None, args=None)
pretty_print()
pulse(**kwargs)
reset(targets, **kwargs)
swap(target, destination)
synchronize(targets)