2

enter image description here

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

Kadija
  • 85
  • 4
  • probably just for illustrative purposes... to break the circuit into stages but nothing else – KAJ226 Jun 02 '22 at 15:37
  • take a look at these two videos from qiskit, https://www.youtube.com/watch?v=CdoCPz6TC9k , https://www.youtube.com/watch?v=tS2CMOyWFMQ – poig Jun 20 '22 at 19:29

1 Answers1

2

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.

ryanhill1
  • 2,493
  • 1
  • 9
  • 37