Below I created a circuit and applied several gates to it:
n = 4
qubits = QuantumRegister(n, name='q')
ansilla = QuantumRegister(n - 1, name='ans')
circuit = QuantumCircuit(qubits, ansilla)
# I step
circuit.ccx(qubits[0], qubits[1], ansilla[0])
# II step
for i in range(2, n - 1):
circuit.ccx(qubits[i], ansilla[i-2], ansilla[i-1])
# III step
circuit.cx(ansilla[-1], qubits[-1])
When I draw a visualization with circuit.draw()
I got the following diagram:
It draws III step
before II
step.
Is it a bug or how can I overcome this problem?
I use qiskit version=0.8.2