1
$\begingroup$

So I have an array which specifies the initial layout of a 4 qubit quantum circuit and I want to map the qubits to a 5 qubit quantum computer. As only 4 out of the 5 qubits will be used, Qiskit assigns one of the vacant qubits on the quantum computer as an ancilla qubit.

How do I specify this ancilla qubit in my initial_layout parameter when I am trying to transpile the circuit using qiskit.transpile? Or alternatively, how do I assign only 4 of these virtual qubits to 5 physical qubits using the same initial_layout parameter?

$\endgroup$

1 Answer 1

0
$\begingroup$

The initial_layout parameter needs to have the same size as the circuit to transpile. Otherwise LayoutError: 'Integer list length must equal number of qubits in circuit.'

Therefore, you should not specify the ancilla qubit but only the qubits in your circuit:

from qiskit import QuantumCircuit

circuit = QuantumCircuit(4)
circuit.cx(0, [1,2,3])
circuit.draw()
                    
q_0: ──■────■────■──
     ┌─┴─┐  │    │  
q_1: ┤ X ├──┼────┼──
     └───┘┌─┴─┐  │  
q_2: ─────┤ X ├──┼──
          └───┘┌─┴─┐
q_3: ──────────┤ X ├
               └───┘

In this case, the circuit has 4 qubits. To lay $q_0 \mapsto 4$, $q_1 \mapsto 0$, $q_2 \mapsto 2$, and $q_3 \mapsto 3$, you can set initial_layout with the codomain of that mapping: initial_layout=[4,0,2,3].

from qiskit import transpile
from qiskit.transpiler import CouplingMap

transpiled_circuit = transpile(circuit, 
                               coupling_map=CouplingMap([(0,1),(1,2),(2,3),(3,4)]),
                               initial_layout=[4,0,2,3])
transpiled_circuit.draw()
      q_1 -> 0 ─X──────────────────────────────────────────────
                │                                              
ancilla_0 -> 1 ─X───X───────────────────X──────────────────────
                    │  ┌───┐     ┌───┐  │  ┌───┐     ┌───┐     
      q_2 -> 2 ─────X──┤ H ├──■──┤ H ├──X──┤ H ├──■──┤ H ├─────
                  ┌───┐└───┘┌─┴─┐├───┤┌───┐└───┘┌─┴─┐├───┤     
      q_3 -> 3 ─X─┤ H ├─────┤ X ├┤ H ├┤ H ├─────┤ X ├┤ H ├──■──
                │ └───┘     └───┘└───┘└───┘     └───┘└───┘┌─┴─┐
      q_0 -> 4 ─X─────────────────────────────────────────┤ X ├
                                                          └───┘
$\endgroup$
1
  • $\begingroup$ This helps, thank you! $\endgroup$
    – Anonymous
    Jul 18, 2022 at 16:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.