Skip to content

laboneq.openqasm3

Experimental

The current implementation of OpenQASM support is considered experimental. Its interface may change in future releases of LabOne Q.

laboneq.openqasm3.gate_store

GateStore()

gate_map: Dict[str, str] = {} instance-attribute

gates: Dict[Tuple[str, Tuple[str, ...]], Callable[..., Section]] = {} instance-attribute

ports = {} instance-attribute

waveforms: Dict[str, Callable] = {} instance-attribute

lookup_gate(name, qubits, args=(), kwargs=None)

lookup_waveform(name)

map_gate(qasm_name, labone_q_name)

Define mapping from qasm gate name to LabOne Q gate name.

register_gate(name, qubit_name, pulse, signal, phase=None, id=None)

Register a pulse as a single-qubit gate.

register_gate_section(name, qubit_names, section_factory)

Register a LabOne Q section factory as a gate.

register_port(qasm_port, signal_line)

register_waveform(name, pulse)

laboneq.openqasm3.openqasm3_importer

exp_from_qasm(program, qubits, gate_store, inputs=None, externs=None, count=1, averaging_mode=AveragingMode.CYCLIC, acquisition_type=AcquisitionType.INTEGRATION, reset_oscillator_phase=False)

Create an experiment from an OpenQASM program.

Parameters:

Name Type Description Default
program str

OpenQASM program

required
qubits dict[str, Qubit]

Map from OpenQASM qubit names to LabOne Q DSL Qubit objects

required
gate_store GateStore

Map from OpenQASM gate names to LabOne Q DSL Gate objects

required
inputs dict[str, Any] | None

Inputs to the OpenQASM program.

None
externs dict[str, Callable] | None

Extern functions for the OpenQASM program.

None
count int

The number of acquire iterations.

1
averaging_mode AveragingMode

The mode of how to average the acquired data.

CYCLIC
acquisition_type AcquisitionType

The type of acquisition to perform.

INTEGRATION
reset_oscillator_phase bool

When true, reset all oscillators at the start of every acquistion loop iteration.

False

Returns:

Type Description
Experiment

The experiment generated from the OpenQASM program.

exp_from_qasm_list(programs, qubits, gate_store, inputs=None, externs=None, count=1, averaging_mode=AveragingMode.CYCLIC, acquisition_type=AcquisitionType.INTEGRATION, reset_oscillator_phase=False, repetition_time=0.001, batch_execution_mode='pipeline', do_reset=False, pipeline_chunk_count=None)

Process a list of openQASM programs into a single LabOne Q experiment that executes the QASM snippets sequentially.

At this time, the QASM programs must not include any measurements. We automatically append a measurement of all qubits to the end of each program.

The measurement results for each qubit are stored in a handle named f'meas{qasm_qubit_name}' where qasm_qubit_name is the key specified for the qubit in the qubits parameter.

Optionally, a reset operation on all qubits is prepended to each program. The duration between the reset and the final readout is fixed and must be specified as repetition_time. It must be chosen large enough to accommodate the longest of the programs. The repetition_time parameter is also required if the resets are disabled. In a future version we hope to make an explicit repetition_time optional.

For the measurement we require the gate store to be loaded with a measurement gate. Similarly, the optional reset requires a reset gate to be available.

Parameters:

Name Type Description Default
programs list[str]

the list of the QASM snippets

required
qubits dict[str, Qubit]

Map from OpenQASM qubit names to LabOne Q DSL Qubit objects

required
gate_store GateStore

Map from OpenQASM gate names to LabOne Q DSL Gate objects

required
inputs dict[str, Any] | None

Inputs to the OpenQASM program.

None
externs dict[str, Callable] | None

Extern functions for the OpenQASM program.

None
count int

The number of acquire iterations.

1
averaging_mode AveragingMode

The mode of how to average the acquired data.

CYCLIC
acquisition_type AcquisitionType

The type of acquisition to perform.

INTEGRATION
reset_oscillator_phase bool

When true, reset all oscillators at the start of every acquistion loop iteration.

False
repetition_time float

The length that any single program is padded to.

0.001
batch_execution_mode str

The execution mode for the sequence of programs. Can be any of the following:

  • "nt": The individual programs are dispatched by software.
  • "pipeline": The individual programs are dispatched by the sequence pipeliner.
  • "rt": All the programs are combined into a single real-time program.

"rt" offers the fastest execution, but is limited by device memory. In comparison, "pipeline" introduces non-deterministic delays between programs of up to a few 100 microseconds. "nt" is the slowest.

'pipeline'
do_reset bool

If True, an active reset operation is added to the beginning of each program.

False
pipeline_chunk_count int | None

The number of pipeline chunks to divide the experiment into.

The default chunk count is equal to the number of programs, so that there is one program per pipeliner chunk. Future versions of LabOne Q may use a more sophisticated default based on the program sizes.

Currently the number of programs must be a multiple of the chunk count so that there are the same number of programs in each chunk. This limitation will be removed in a future release of LabOne Q.

A ValueError is raised if the number of programs is not a multiple of the chunk count.

None

Returns:

Type Description
Experiment

The experiment generated from the OpenQASM programs.