compile
- GateCompiler.compile(circuit, initial_state=None)
Compile a Qiskit circuit into the target gate set’s native operations.
The active
configselects the compilation path: aQiskitConfigcompiles through the Qiskit transpiler, any other configuration synthesizes the circuit’s unitary with thequasarcppbackend.An
idor adelayincircuitis dropped: neither changes the circuit’s unitary.A circuit may state two things its device does not perform literally, and
compile()converts both.A
resetsets the qubits it names to \(|0\rangle\). A device withspam_qubitsresets that group at once and reaches the other qubits only through it, so each run of resets is lowered together: a reset of the whole group, and an exchange with the group for any qubit outside it. The compiled circuit keeps every reset, between barriers, and compiles the gates between them on their own.lower_resets()performs the rewrite, and is callable on its own to see what the device is asked to do before the rest of the circuit is compiled.A trailing instruction says which Pauli string is wanted. A device reads out one fixed thing, so the request becomes a Clifford turning that readout into the requested one.
Everything else is compiled as one unitary – unless
initial_statenames the state the register starts in, which makes the circuit’s action on that one state the whole demand, and compiles it as a preparation (seecompile_state()).A Pauli string is requested by appending a
PauliProductMeasurementas the very last instruction ofcircuit, e.g.circuit.append(PauliProductMeasurement(Pauli("XZ")), [0, 2], [creg[0]]). The measured qubits are the ones the instruction is placed on. Composing the returned circuit onward into a larger one, rather than physically reading it out, wants a plaincircuitwith no trailing measurement – the return value is then unchanged from a circuit that never had one.When a trailing request is present,
compile()strips it off and realizes the transformation the hardware’s own readout needs to equal the requested Pauli product’s expectation value on the original, uncompiled circuit. The device reads one fixed physical qubit (\(Z\) on the gate set’sspam_qubits, \(I\) elsewhere), and the transformation is the Clifford turning that readout into the requested one. It is not a no-op even when the request already looks like the fixed readout, since the compiled circuit’s own qubit assignment moves qubits around. On a synthesis strategy the transformation joins the unitary and is synthesized with the circuit, so the layout search and the error model both cover it, and every output assignment stays a candidate – which Clifford realizes the readout follows from the assignment. On the Qiskit path it is compiled separately and appended, in the compiled circuit’s output qubit assignment. The returned circuit then ends with its own trailing, single-qubitPauliProductMeasurement(Pauli("Z"))on the readable qubit, backed by a real classical bit – unlike the rest of the returned circuit, this last instruction is not lowered to gate-set natives.- Parameters:
circuit (
QuantumCircuit) – Input circuit to compile, optionally ending in aPauliProductMeasurementnaming the readout target.initial_state (
Any) – State the register starts in, as a basis-state index or aStatevector. Given, the circuit’s action on that one state is what gets compiled – a preparation rather than the whole unitary (seecompile_state()).
- Return type:
- Returns:
The native Qiskit circuit expressed in the target gate set, plus a trailing, single-qubit
PauliProductMeasurementand its classical bit whencircuitended with one. Like a transpiled Qiskit circuit, the native part carries no boundary permutation gates; the chosen input/output qubit relabeling is recorded on its.layout, a realTranspileLayouteven when it happens to be the identity permutation. Pass it toqiskit.quantum_info.Operator.from_circuit()to recover the original unitary with the layout applied, or tocompilation_error()to compare it with the source directly (both need a circuit with no readout request – remove one withremove_pauli_readouts()first). Lowering the circuit to pulses reads the same obligation: pulses land on the physical qubits its gates name, so state preparation and readout have to be expressed in the same relabeling. When a readout target was given, the requested Pauli basis is also recorded on.metadata["pauli_readout"], the device readout realizing it on.metadata["pauli_readout_native"], and the returned circuit realizes the source circuit and its readout transformation: on a synthesis strategy it joins the unitary before it is synthesized, so compare the circuit with both, not with the source alone..metadata["pauli_readout_products"]maps each string the readout delivers to the requested string it equals. With several readout targets, one readout also delivers the products of the native strings, each mapped to the product of the requested strings, with a leading"-"for the sign-1:{"IIZ": "IXX", "IZI": "IZZ", "IZZ": "-IYY"}for the targets"IXX"and"IZZ". Every string is in Qiskit’s order: its last letter is qubit0.- Raises:
ValidationError – If
initial_stateis given for a circuit holding a Pauli readout, a reset or a measurement.