2
$\begingroup$

enter image description here

Does the barrier here won't simplify the circuit between the two H-gates?

$\endgroup$
2

1 Answer 1

2
$\begingroup$

Correct, quoting What is a "barrier" in Qiskit Circuits?:

The barrier acts as a directive for circuit compilation to separate pieces of a circuit so that any optimizations or re-writes are constrained to only act between barriers (and if there are no barriers they act on the whole circuit)

However, in this example, the circuit cannot be further simplified, so transpiling the circuit without the barriers will not have any effect:

from qiskit import QuantumCircuit

qc = QuantumCircuit(3,1)
qc.h(0)
qc.cnot(0,1)
qc.h(2)
qc.h(0)

qc.draw()
     ┌───┐     ┌───┐
q_0: ┤ H ├──■──┤ H ├
     └───┘┌─┴─┐└───┘
q_1: ─────┤ X ├─────
     ┌───┐└───┘     
q_2: ┤ H ├──────────
     └───┘          
c: 1/═══════════════
from qiskit.compiler import transpile

qc_transp = transpile(qc)

qc_transp.draw()
     ┌───┐     ┌───┐
q_0: ┤ H ├──■──┤ H ├
     └───┘┌─┴─┐└───┘
q_1: ─────┤ X ├─────
     ┌───┐└───┘     
q_2: ┤ H ├──────────
     └───┘          
c: 1/═══════════════

Therefore, for the circuit you've given, the inclusion of the barriers does not serve any computational purpose. If more instructions were to be added, then the barriers could once again come into play.

$\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.