1
$\begingroup$

I'm curious about something. I tried to do some qubit mapping using SABRE algorithm. Suppose I have two quantum circuits and apply SABRE algorithm to both of them. Then each of them has its own qubit mapping states. After that, I want to compose them to make it as one long quantum circuit. How can I do it? I used python code and qiskit. I have already searched qiskit API and used some functions (compose, combine, append). But the circuits could not be combined. How can I assemble two quantum circuit which have different qubit mapping state respectively?

Thank you

$\endgroup$
2
  • $\begingroup$ Would you be able to share exactly where you were experiencing difficulties? Some code snippets highlighting your problems would be pretty helpful $\endgroup$ Jul 1, 2021 at 6:04
  • $\begingroup$ I upload my new question please kindly check :) $\endgroup$
    – 김동민
    Jul 6, 2021 at 0:56

1 Answer 1

1
$\begingroup$

The short answer to composed circuit is the following. Given circuit1 and circuit2, you can do like this:

circuit = circuit1 + circuit2

You can also do that with transpiled circuits:

transpiled1 = transpile(circuit1, backend, routing_method='sabre')
transpiled2 = transpile(circuit2, backend, routing_method='sabre')

circuit = transpiled1 + transpiled2

Notice that the circuits to composed need to be the same size. After transpilation, that is ensured. transpile will make the circuit as big as the backend (given that you use the same backend during transpilation). The operation + will wire the links one-to-one.

Here is an example to compose circuit with different sizes:

circuit1 = QuantumCircuit(5)
circuit1.mcx([0, 1, 3, 4], 2)
print(circuit1)
circuit2 = QuantumCircuit(2)
circuit2.cx(0, 1)
print(circuit2)
          
q_0: ──■──
       │  
q_1: ──■──
     ┌─┴─┐
q_2: ┤ X ├
     └─┬─┘
q_3: ──■──
       │  
q_4: ──■──
          
          
q_0: ──■──
     ┌─┴─┐
q_1: ┤ X ├
     └───┘

In this case, you need to use compose(..., qubits=...). The parameter qubits indicates how to wire the circuits.

circuit = circuit1.compose(circuit2, qubits=[3,2])
print(circuit)
q_0: ──■───────
       │       
q_1: ──■───────
     ┌─┴─┐┌───┐
q_2: ┤ X ├┤ X ├
     └─┬─┘└─┬─┘
q_3: ──■────■──
       │       
q_4: ──■───────
$\endgroup$
1
  • $\begingroup$ Thank you for your opinion. But I already did '+' operation too. I think you misunderstand what I said. I will modify my question and upload my real question here later. $\endgroup$
    – 김동민
    Jul 5, 2021 at 0:58

Your Answer

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

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