mqt.predictor.rl.parsing¶
Helper methods necessary for parsing between circuit formats.
Module Contents¶
- class PreProcessTKETRoutingAfterQiskitLayout[source]¶
Pre-processing step to route a circuit with TKET after a Qiskit Layout pass has been applied.
The reason why we can apply the trivial layout here is that the circuit already got assigned a layout by qiskit. Implicitly, Qiskit is reordering its qubits in a sequential manner, i.e., the qubit with the lowest physical qubit first.
Assuming, the layouted circuit is given by
┌───┐ ░ ┌─┐
- q_2 -> 0 ┤ H ├──■────────░───────┤M├
└───┘┌─┴─┐ ░ ┌─┐└╥┘
- q_1 -> 1 ─────┤ X ├──■───░────┤M├─╫─
└───┘┌─┴─┐ ░ ┌─┐└╥┘ ║
- q_0 -> 2 ──────────┤ X ├─░─┤M├─╫──╫─
└───┘ ░ └╥┘ ║ ║
- ancilla_0 -> 3 ───────────────────╫──╫──╫─
║ ║ ║
- ancilla_1 -> 4 ───────────────────╫──╫──╫─
║ ║ ║
- meas: 3/═══════════════════╩══╩══╩═
0 1 2
Applying the trivial layout, we get the same qubit order as in the original circuit and can be respectively routed. This results in:
┌───┐ ░ ┌─┐
- q_0: ┤ H ├──■────────░───────┤M├
└───┘┌─┴─┐ ░ ┌─┐└╥┘
- q_1: ─────┤ X ├──■───░────┤M├─╫─
└───┘┌─┴─┐ ░ ┌─┐└╥┘ ║
- q_2: ──────────┤ X ├─░─┤M├─╫──╫─
└───┘ ░ └╥┘ ║ ║
- q_3: ───────────────────╫──╫──╫─
║ ║ ║
- q_4: ───────────────────╫──╫──╫─
║ ║ ║
- meas: 3/═══════════════════╩══╩══╩═
0 1 2
- If we would not apply the trivial layout, no layout would be considered resulting, e.g., in the following circuit:
┌───┐ ░ ┌─┐
- q_0: ─────┤ X ├─────■───░────┤M├───
┌───┐└─┬─┘ ┌─┴─┐ ░ ┌─┐└╥┘
- q_1: ┤ H ├──■───X─┤ X ├─░─┤M├─╫────
└───┘ │ └───┘ ░ └╥┘ ║ ┌─┐
- q_2: ───────────X───────░──╫──╫─┤M├
░ ║ ║ └╥┘
- q_3: ──────────────────────╫──╫──╫─
║ ║ ║
- q_4: ──────────────────────╫──╫──╫─
║ ║ ║
- meas: 3/══════════════════════╩══╩══╩═
0 1 2
- get_bqskit_native_gates(device: Target) list[Gate][source]¶
Returns the native gates of the given device.
- Parameters:
device – The device for which the native gates are returned.
- Returns:
The native gates of the given device as BQSKit gates.
- Raises:
ValueError – If a gate in the device is not supported in BQSKit.
- bqskit_to_qiskit(circuit: Circuit) QuantumCircuit[source]¶
Convert a BQSKit Circuit to Qiskit’s QuantumCircuit.
This function extends BQSKit’s built-in conversion by adding support for IQM’s native ‘r’ gate. BQSKit represents this as U1qGate, which is converted to Qiskit’s RGate by rewriting the OpenQASM 2 output.
- Parameters:
circuit – The BQSKit circuit to convert.
- Returns:
The equivalent Qiskit QuantumCircuit with ‘r’ gates properly mapped.
- final_layout_pytket_to_qiskit(pytket_circuit: pytket.Circuit, qiskit_circuit: QuantumCircuit) Layout[source]¶
Converts a final layout from pytket to qiskit.
- final_layout_bqskit_to_qiskit(bqskit_initial_layout: tuple[int, Ellipsis], bqskit_final_layout: tuple[int, Ellipsis], compiled_qc: QuantumCircuit, initial_qc: QuantumCircuit) TranspileLayout[source]¶
Converts a final layout from bqskit to qiskit.
BQSKit provides an initial layout as a list[int] where each virtual qubit is mapped to a physical qubit similarly, it provides a final layout as a list[int] representing where each virtual qubit is mapped to at the end of the circuit.
- postprocess_vf2postlayout(qc: QuantumCircuit, post_layout: Layout, layout_before: TranspileLayout) tuple[QuantumCircuit, ApplyLayout][source]¶
Postprocess a quantum circuit after VF2 layout assignment.
- Parameters:
qc – The quantum circuit to transform.
post_layout – The layout computed after routing.
layout_before – The layout before post-routing adjustment.
- Returns:
A tuple of the transformed circuit and the ApplyLayout used.