quantify-scheduler exporter
The quantify-scheduler exporter (QuantifySchedulerExporter)
exports the circuit to a Schedule
object.
The bit string mapping has been deprecated
The QuantifySchedulerExporter used to return a bit string mapping next to the Schedule.
This bit string mapping has been deprecated.
To obtain a mapping from the measurements to the bit register index their outcomes are assigned to,
use the circuit property Circuit.measurement_to_bit_map, instead.
This mapping has the following structure:
{
<qubit-index: str> : [
<bit-index: int>,
<bit-index: int>,
...
],
<qubit-index: str> : [ ... ],
...
}
Each qubit at index \(i\) contains a list of bit indices. The index \(j\) of this list is the measurement index and denotes the order in which the qubit was measured. The values at \(j\) denote the bit register index \(k\) to which the measurement outcome was assigned in the circuit. Qubits that are not measured do not have an entry in the measurement to bit mapping.
Here are some important differences to take note of:
- All qubit register declarations
are combined into a single (virtual) qubit register (
q) statement. - Bit registers declarations
and assignments of measurement outcomes to bit register variables
are discarded; quantify-scheduler does not support bit registers or variables.
Note that the measurement statement is not discarded; the
measureinstruction is translated toMeasure. Furthermore, measurement outcomes are related to the (virtual) bit registers they were assigned to in the cQASM circuit. Their mapping can be obtained through theCircuit.measurement_to_bit_mapproperty, as described above. - The non-unitary
initinstruction is ignored andresetinstruction is translated toReset. Theresetinstruction can be used to set the state of the qubit to the \(|0\rangle\) state, similar to the effect of theinitinstruction. - Single gate multi qubit (SGMQ) notation is unpacked; the gate is applied to each qubit on a separate line.
- Control instructions (
barrierandwait) are currently not supported. Note: processing of the control instructions is currently under active development, but not yet part of the latest version of OpenSquirrel. - Angles are translated from radians to degrees.
Unsupported gates
The quantify-scheduler exporter does not support the Rn gate
in general.
Unless both the \(n_x\) and \(n_y\) components are zero, or just the \(n_z\) component is zero, it will raise an error
(UnSupportedGateError) if this gate is part of the circuit that is to be exported.
The same error is raised if the circuit to be exported contains a Hadamard, SWAP, or any arbitrary two-qubit gate that is not either a CNOT or CZ gate. Decomposition passes can be used to decompose the circuit to gates that the quantify-scheduler exporter supports.
The four examples below show how circuits written in cQASM are exported to a quantify-scheduler
Schedule.
circuit = Circuit.from_string(
"""
version 3.0
qubit[2] q
bit[2] b
H q[0]
CNOT q[0], q[1]
b = measure q
"""
)
exported_schedule = circuit.export(exporter=QuantifySchedulerExporter)
for schedulable in exported_schedule.schedulables.values():
print(exported_schedule.operations[schedulable["operation_id"]].name)
print('\n', "measurement to bit map: ", circuit.measurement_to_bit_map)
Rxy(90, 90, 'q[0]')
Rxy(180, 0, 'q[0]')
CNOT (q[0], q[1])
Measure q[0]
Measure q[1]
measurement to bit map: {"0": [0], "1": [1]}
Note that the bit register declaration and assignment to bit variables have been discarded (2.), the SGMQ notation has been unpacked (4.), and the angles have been translated from radians to degrees (6.). The numbers refer to the differences listed above.
According to the description of the measurement to bit mapping above, note that the outcome of the first measurement (\(j=0\)) on qubit at index \(i=0\), is mapped to the (virtual) bit variable at index \(k=0\), and the outcome of the first measurement (\(j=0\)) on qubit at index \(i=1\), is mapped to the (virtual) bit variable at index \(k=1\).
circuit = Circuit.from_string(
"""
version 3.0
qubit[2] qA
bit[3] bA
H qA[0]
CNOT qA[0], qA[1]
bA[1,2] = measure qA
qubit[3] qB
bit[2] bB
H qB[1]
CNOT qB[1], qA[1]
bB[0] = measure qB[1]
bB[1] = measure qA[1]
"""
)
exported_circuit = circuit.export(exporter=QuantifySchedulerExporter)
for schedulable in exported_schedule.schedulables.values():
print(exported_schedule.operations[schedulable["operation_id"]].name)
print('\n', "measurement to bit map: ", circuit.measurement_to_bit_map)
Rxy(90, 90, 'q[0]')
Rxy(180, 0, 'q[0]')
CNOT (q[0], q[1])
Measure q[0]
Measure q[1]
Rxy(90, 90, 'q[3]')
Rxy(180, 0, 'q[3]')
CNOT (q[3], q[1])
Measure q[3]
Measure q[1]
measurement to bit map: {"0": [1], "1": [2, 4], "3": [3]}
Note that all qubit register declarations are combined into a single (virtual) qubit register (1.), the bit register declaration and assignment to bit variables have been discarded (2.), the SGMQ notation has been unpacked (4.), and the angles have been translated from radians to degrees (6.). The numbers refer to the differences listed above.
In particular, this example illustrates that all qubit registers have been combined into a single (virtual)
qubit register q, i.e., the registers qA and qB have been concatenated into q,
such that qA[0], qA[1] = q[0], q[1] and qB[0], qB[1], qB[2] = q[2], q[3], q[4].
The qubit registers are concatenated in the order they are declared.
Moreover, even though the bit registers have been discarded in the circuit, the mapping from meausurement to
(virtual) bit variable has been stored in the measurement to bit mapping.
Note that, just like with the translation of the qubit register declarations to the single virtual register q,
the bit register declarations are also concatenated in the order they are declared into a single bit register
b.
In this example, the virtual bit register translation is as follows: bA[0], bA[1], bA[2] = b[0], b[1], b[2]
and bB[0], bB[1] = b[3], b[4].
For instance, the statement bB[1] = measure qA[1] in the original circuit becomes,
in terms of virtual registers, b[4] = measure q[1].
Note that in the measurement to bit mapping the outcome of the second measurement (measurement index \(j=1\))
on q[1], i.e. qubit at index \(i=1\), is assigned to the bit at index \(k=4\).
circuit = Circuit.from_string(
"""
version 3.0
qubit[2] q
bit[2] b
init q
H q[0]
CNOT q[0], q[1]
b = measure q
reset q
H q[0]
Z q[0]
CNOT q[0], q[1]
b = measure q
"""
)
exported_circuit = circuit.export(exporter=QuantifySchedulerExporter())
for schedulable in exported_schedule.schedulables.values():
print(exported_schedule.operations[schedulable["operation_id"]].name)
print('\n', "measurement to bit map: ", circuit.measurement_to_bit_map)
Reset q[0]
Reset q[1]
Rxy(90, 90, 'q[0]')
Rxy(180, 0, 'q[0]')
CNOT (q[0], q[1])
Measure q[0]
Measure q[1]
Reset q[0]
Reset q[1]
Rxy(90, 90, 'q[0]')
Rxy(180, 0, 'q[0]')
Rz(180, 'q[0]')
CNOT (q[0], q[1])
Measure q[0]
Measure q[1]
measurement to bit map: {"0": [0, 0], "1": [1, 1]}
Note that the bit register declaration and assignment to bit variables have been discarded (2.),
the init instructions have been ignored and the reset instructions have been translated to Reset,
the SGMQ notation has been unpacked (4.), and the angles have been translated from radians to degrees (6.).
The numbers refer to the differences listed above.
The quantify-scheduler operation library
does not distinguish between an init and a reset instruction.
For now, the init instruction is ignored and the reset instruction is translated to
Reset.
Note that one can us the reset instruction to set the state of the qubit to the \(|0\rangle\) state,
which is similar to the effect of the init instruction.
macOS ARM not supported
The quantify-scheduler exporter cannot run on macOS ARM, due to the fact that the required dependency
pyqt5-qt5==5.15.2 does provide binaries for that architecture.