0
$\begingroup$

Well,it is not very important problem and I actually did what I wanted but I just noticed that when I want to draw circuit, qiskit draw method is not drawing the circuit with the correct order.. I wonder if there is a specific reason for it and I don't know it, or did I miss something or it is really not drawing....

Here is my circuit:

enter image description here

Here is my qiskit code:

qc_AB = QuantumCircuit(3)
qc_AB.h(2)
qc_AB.cx(1,2)
qc_AB.tdg(2)
qc_AB.cx(0,2)
qc_AB.t(2)
qc_AB.cx(1,2)
qc_AB.tdg(2)
qc_AB.cx(0,2)
qc_AB.t(1)
qc_AB.t(2)
qc_AB.cx(0,1)
qc_AB.h(2)
qc_AB.t(0)
qc_AB.tdg(1)
qc_AB.cx(0,1)
qc_AB.draw()

And here is what qiskit draw fucntion showed me:

enter image description here

$\endgroup$
2
$\begingroup$

It's still the same circuit -- but the circuit drawer shows the gates "as soon as possible", which means it'll move them to the left if possible. In your example, you'll notice that the drawer moved the last T gate on the wire of q_1 further to the left, through the CX gate.

As this example shows, the common circuit representation is not unique! That's why Qiskit (and other packages) use a directed, acyclic Graph (DAG) representation of the circuit which doesn't have this problem.

$\endgroup$
1
$\begingroup$

As @Cryoris said in his answer, it's still the same circuit. However, if you want the circuit plot to have the same gate alignment, there is a simple trick to do that:

  1. Add a barrier before the t-gates.
  2. Set the draw method's option plot_barriers to False.
qc_AB = QuantumCircuit(3)
qc_AB.h(2)
qc_AB.cx(1,2)
qc_AB.tdg(2)
qc_AB.cx(0,2)
qc_AB.t(2)
qc_AB.cx(1,2)
qc_AB.tdg(2)
qc_AB.cx(0,2)
qc_AB.barrier() # <=== (1)
qc_AB.t(1)
qc_AB.t(2)
qc_AB.cx(0,1)
qc_AB.h(2)
qc_AB.t(0)
qc_AB.tdg(1)
qc_AB.cx(0,1)
qc_AB.draw(plot_barriers = False) # <=== (2)

The result will looks like:

                                                             ┌───┐      
q_0: ───────────────────■─────────────────────■──────────■───┤ T ├───■──
                        │                     │   ┌───┐┌─┴─┐┌┴───┴┐┌─┴─┐
q_1: ───────■───────────┼─────────■───────────┼───┤ T ├┤ X ├┤ Tdg ├┤ X ├
     ┌───┐┌─┴─┐┌─────┐┌─┴─┐┌───┐┌─┴─┐┌─────┐┌─┴─┐ ├───┤├───┤└─────┘└───┘
q_2: ┤ H ├┤ X ├┤ Tdg ├┤ X ├┤ T ├┤ X ├┤ Tdg ├┤ X ├─┤ T ├┤ H ├────────────
     └───┘└───┘└─────┘└───┘└───┘└───┘└─────┘└───┘ └───┘└───┘            
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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