1

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?

Anonymous
  • 25
  • 2

1 Answers1

0

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 ├
                                                          └───┘
luciano
  • 6,164
  • 1
  • 14
  • 34