manual_layout#
- manual_layout(qubit_mapping: list[int]) Callable[[QuantumCircuit], QuantumCircuit][source]#
Create a pass that applies a manual qubit layout to the circuit.
- Parameters:
- qubit_mappinglist[int]
A list of physical qubit indices. The i-th logical qubit in the circuit is mapped to physical qubit
qubit_mapping[i].For example,
[2, 0, 1]means:Logical qubit 0 → Physical qubit 2
Logical qubit 1 → Physical qubit 0
Logical qubit 2 → Physical qubit 1
- Returns:
- Callable[[QuantumCircuit], QuantumCircuit]
A pass function that transforms the circuit.
- Raises:
- ValueError
If the mapping length does not match the circuit qubit count, if any index is negative, or if there are duplicate indices.
Examples
>>> from qrisp import QuantumCircuit, PassManager >>> from qrisp import manual_layout >>> qc = QuantumCircuit(3) >>> qc.h(0) >>> qc.cx(1, 2) >>> print(qc) ┌───┐ qb_0: ┤ H ├ └───┘ qb_1: ──■── ┌─┴─┐ qb_2: ┤ X ├ └───┘
>>> pm = PassManager() >>> pm += manual_layout([2, 0, 1]) # Logical 0→2, 1→0, 2→1 >>> new_layout_qc = pm.run(qc) >>> print(new_layout_qc) qb_1: ──■── ┌─┴─┐ qb_2: ┤ X ├ ├───┤ qb_0: ┤ H ├ └───┘