GHZ States Tutorial¶

Introduction to GHZ States¶

The GHZ (Greenberger-Horne-Zeilinger) state is a maximally entangled quantum state involving three or more qubits. Named after physicists Daniel Greenberger, Michael Horne, and Anton Zeilinger, it represents one of the most fascinating examples of quantum entanglement.

Mathematical Representation¶

For n qubits, the GHZ state is:

|GHZ_n⟩ = (|00...0⟩ + |11...1⟩)/√2

Examples:

  • 3 qubits: |GHZ₃⟩ = (|000⟩ + |111⟩)/√2
  • 4 qubits: |GHZ₄⟩ = (|0000⟩ + |1111⟩)/√2
  • 5 qubits: |GHZ₅⟩ = (|00000⟩ + |11111⟩)/√2

Key Properties¶

  1. Maximal Entanglement: All qubits are maximally entangled with each other
  2. Correlated Outcomes: All qubits always measure the same value (all 0s or all 1s)
  3. Quantum Non-locality: Demonstrates stronger violations of local realism than Bell states
  4. Fragility: Loss of any single qubit destroys the entanglement (unlike W states)

API Authentication¶

Setting up the API configuration to run jobs on quantum hardware:

In [1]:
import sys
import os
import numpy as np
sys.path.append('../')

from dotenv import load_dotenv
load_dotenv()

from qpiai_quantum import QpiAIQuantumAuth
API_KEY = os.getenv("API_KEY")
QpiAIQuantumAuth.login(API_KEY)
Out[1]:
'API key stored. It will be validated on first cloud access.'

Verify the User API Configuration¶

Setting up the API configuration to run the jobs on quantum experiment:

In [2]:
QpiAIQuantumAuth.me()
Out[2]:
{'name': 'Quantum Hardware Super Admin',
 'email': 'xxxxxxxxxxxxxx@qpiai.tech',
 'api_key': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'}

Part 1: Creating a Basic GHZ State¶

Let's start by creating a 4-qubit GHZ state to understand the circuit construction.

Circuit Construction¶

The GHZ circuit uses:

  1. Hadamard (H) gate on the first qubit: Creates superposition (|0⟩ + |1⟩)/√2
  2. Chain of CNOT gates: Entangles all remaining qubits sequentially

For a 4-qubit GHZ state:

q0: ─H─●─────────[M]
       │
q1: ───X─●───────[M]
         │
q2: ─────X─●─────[M]
           │
q3: ───────X─────[M]
In [3]:
from qpiai_quantum.state_preparation import GHZStateGenerator

ghz = GHZStateGenerator(num_qubits=4)
circuit = ghz.build_circuit(measure=True)
circuit.show()
No description has been provided for this image

Execute on QpiAI Quantum Hardware¶

Now we'll execute the circuit and analyze the results:

In [5]:
shots = 10000
result = ghz.run(shots=shots, experiment_name='GHZ_circuit', device_type="qpu")
print(f"Counts : {result.get_counts()}")
Counts : {'0000': 5011, '1111': 4989}

Visualize Results¶

In [6]:
ghz.visualize('histogram', result=result)
No description has been provided for this image

Get Expected Outcomes¶

In [7]:
expected = ghz.get_expected_outcomes()
print(f"Expected outcomes: {expected}")
Expected outcomes: {'0000': 0.5, '1111': 0.5}

Part 2: Exploring Different GHZ State Sizes¶

One of the powerful features of GHZ states is the ability to scale to any number of qubits. Let's explore different sizes:

5-Qubit GHZ State¶

In [8]:
ghz_5 = GHZStateGenerator(num_qubits=5)
print("5-Qubit GHZ State Analysis")
print("="*60)

circuit_5 = ghz_5.build_circuit(measure=True)
circuit_5.show()

result_5 = ghz_5.run(shots=5000, experiment_name='GHZ_circuit', device_type="qpu")

print(f"\nExpected outcomes: {ghz_5.get_expected_outcomes()}")
print(f"Measurement counts: {result_5.get_counts()}")
print(f"Entanglement verified: {ghz_5.verify_entanglement(result_5)}")
print(f"Entanglement depth: {ghz_5.calculate_entanglement_depth()}")
print(f"Circuit depth: {ghz_5.get_circuit_depth()}")

ghz_5.visualize('histogram', result=result_5)
5-Qubit GHZ State Analysis
============================================================
No description has been provided for this image
Expected outcomes: {'00000': 0.5, '11111': 0.5}
Measurement counts: {'00000': 2506, '11111': 2494}
Entanglement verified: True
Entanglement depth: 5
Circuit depth: 5
No description has been provided for this image

7-Qubit GHZ State (Large Scale)¶

In [9]:
ghz_7 = GHZStateGenerator(num_qubits=7)
print("7-Qubit GHZ State Analysis (Large Scale)")
print("="*60)

# Build and show circuit
circuit_7 = ghz_7.build_circuit(measure=True)
circuit_7.show()

# Run and analyze
result_7 = ghz_7.run(shots=6000, experiment_name='GHZ_circuit', device_type="qpu")

print(f"\nExpected outcomes: {ghz_7.get_expected_outcomes()}")
print(f"Measurement counts: {result_7.get_counts()}")
print(f"Entanglement verified: {ghz_7.verify_entanglement(result_7)}")
print(f"Entanglement depth: {ghz_7.calculate_entanglement_depth()}")
print(f"Circuit depth: {ghz_7.get_circuit_depth()}")

# Visualize
ghz_7.visualize('histogram', result=result_7)
7-Qubit GHZ State Analysis (Large Scale)
============================================================
No description has been provided for this image
Expected outcomes: {'0000000': 0.5, '1111111': 0.5}
Measurement counts: {'0000000': 2953, '1111111': 3047}
Entanglement verified: True
Entanglement depth: 7
Circuit depth: 7
No description has been provided for this image

Summary and Key Takeaways¶

In this tutorial, we've comprehensively explored:

  1. GHZ State Fundamentals: Multi-qubit maximally entangled states
  2. Circuit Construction: Hadamard + CNOT chain architecture
  3. Scalability: From 3 to 7+ qubits with linear scaling
  4. Size Comparison: Systematic comparison across different qubit counts

Key Differences: GHZ vs Bell States¶

Property Bell States GHZ States
Qubits 2 qubits only 3+ qubits
Outcomes 2 outcomes 2 outcomes (always)
Scalability Fixed at 2 qubits Scales to any n ≥ 3
Applications Basic entanglement Multi-party protocols

Key Methods Reference¶

  • GHZStateGenerator(num_qubits) - Create GHZ state generator (min 3 qubits)
  • build_circuit(measure=True) - Build the quantum circuit
  • run(shots, backend, experiment_name) - Execute on quantum backend
  • get_expected_outcomes() - Get theoretical distribution

Thank you for learning with QpiAI!

In [16]:
import qpiai_quantum
print(qpiai_quantum.__version__)
0.1.9