Skip to content

Instantly share code, notes, and snippets.

@primaryobjects
Created August 5, 2021 19:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save primaryobjects/8073208ab7b42cfc2abe39d49fab3e5e to your computer and use it in GitHub Desktop.
Save primaryobjects/8073208ab7b42cfc2abe39d49fab3e5e to your computer and use it in GitHub Desktop.
GHZ quantum circuit in Qiskit.

A GHZ quantum circuit is a quantum computing system that includes 3 entangled qubits.

A Greenberger–Horne–Zeilinger state (GHZ state) is a certain type of entangled quantum state that involves at least three subsystems.

Demo in IBM Quantum Composer.

def ghz():
"""
Create a GHZ (entangled 3-qubit system) quantum circuit.
"""
qc = QuantumCircuit(3)
qc.h(0)
qc.cx(0, 1)
qc.cx(0, 2)
qc.measure_all()
job = qiskit.execute(qc, qiskit.BasicAer.get_backend('qasm_simulator'), shots=1000)
print(job.result().get_counts())
{'000': 481, '111': 519}
@primaryobjects
Copy link
Author

ghz

@ttseeker19
Copy link

Hi. Are the 3-qubit GHZ and the 3-qubit cluster states exactly the same? If not, what is the difference?

Because from what I know, to generate a 3-qubit cluster state, we perform a Hadamard to all the 3 initial qubits (q0, q1, and q2). Why for the GHZ state we need to perform the Hadamard only on the first qubit?

Thank you.

@primaryobjects
Copy link
Author

Great question. They actually are different. A GHZ only uses an H on the first qubit and then CNOT (controlled inverse) for the other two qubits, which ties them all together in an entangled state. At this point, any change to the first qubit will be reflected on the other two entangled qubits.

If the qubits, instead, each had their own H gate, they would not be entangled. Changes on any one of the qubits would not effect the others.

@pamulism
Copy link

I think the correct way to create a 3-qubit GHZ state would be as follows :

    qc.h(0)
    qc.cx(0, 1)
    qc.cx(1, 2)

@primaryobjects
Copy link
Author

Great comment. In fact, both configurations are valid GHZ circuits.

The difference between the two GHZ state configurations lies in the order of the CNOT gates applied and which qubits serve as control and target. However, both methods result in the same final state.

Config 1

  • The first CNOT gate is applied between the first and second qubits.
  • The second CNOT gate is applied between the first and third qubits.

Config 2

  • The first CNOT gate is applied between the first and second qubits.
  • The second CNOT gate is applied between the second and third qubits.

Both sequences of CNOT gates achieve the ghz entanglement. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment