Skip to content

Tutorial 1: Creating a Bell State

In this tutorial, you'll learn how to create and measure a Bell state - one of the most fundamental entangled states in quantum computing. :)

What is a Bell State?

A Bell state is a maximally entangled two-qubit state. The most common Bell state is:

|Φ⁺⟩ = (|00⟩ + |11⟩) / √2

This means when you measure both qubits, you'll always get the same result: either both 0 or both 1, each with 50% probability.

Prerequisites


Step-by-Step Guide

Step 1: Import Required Modules

from psiqit.circuits import QuantumCircuit
from psiqit.visualization import draw_circuit
import numpy as np

Step 2: Create a Quantum Circuit

Initialize a circuit with 2 qubits:

circ = QuantumCircuit(2)
print(f"Circuit with {circ.n_qubits} qubits created")

Step 3: Apply Hadamard Gate

The Hadamard gate puts qubit 0 into a superposition state:

circ.h(0)  # Apply H to qubit 0

After this step, qubit 0 is in the state |+⟩ = (|0⟩ + |1⟩) / √2.

Step 4: Apply CNOT Gate

The CNOT (Controlled-NOT) gate entangles the two qubits:

circ.cx(0, 1)  # Control: qubit 0, Target: qubit 1

This creates the Bell state |Φ⁺⟩.

Understanding CNOT

The CNOT gate flips the target qubit (qubit 1) if and only if the control qubit (qubit 0) is in state |1⟩. Combined with the superposition from the Hadamard gate, this creates entanglement.

Step 5: Visualize the Circuit

print(draw_circuit(circ))

Output:

q0: ── H ── ● ──
q1: ──────── X ──

Step 6: Get the State Vector

Run the circuit to obtain the final quantum state:

state = circ.run()
print("State vector:", state.data)

Output:

State vector: [0.70710678+0.j 0.+0.j 0.+0.j 0.70710678+0.j]

This represents (1/√2)|00⟩ + (1/√2)|11⟩.

Step 7: Calculate Probabilities

probabilities = np.abs(state.data)**2
for i, prob in enumerate(probabilities):
    if prob > 0.01:
        binary = format(i, '02b')
        print(f"|{binary}⟩: {prob:.4f}")

Output:

|00⟩: 0.5000
|11⟩: 0.5000

Step 8: Measure the Circuit

Simulate measurements to see the statistical distribution:

result = circ.measure(shots=1024)
print("Counts:", result['counts'])

Typical Output:

Counts: {'00': 512, '11': 512}

Statistical Variation

The exact numbers will vary each time you run the measurement due to the probabilistic nature of quantum mechanics. However, you should always see approximately 50% 00 and 50% 11, with almost no 01 or 10.


Complete Code

Here's the complete script:

from psiqit.circuits import QuantumCircuit
from psiqit.visualization import draw_circuit
import numpy as np

# Create circuit
circ = QuantumCircuit(2)

# Build Bell state
circ.h(0)
circ.cx(0, 1)

# Visualize
print("Circuit:")
print(draw_circuit(circ))

# Get state vector
state = circ.run()
print("\nState vector:", state.data)

# Calculate probabilities
probabilities = np.abs(state.data)**2
print("\nProbabilities:")
for i, prob in enumerate(probabilities):
    if prob > 0.01:
        binary = format(i, '02b')
        print(f"  |{binary}⟩: {prob:.4f}")

# Measure
result = circ.measure(shots=1024)
print("\nMeasurement counts:", result['counts'])

Test It Yourself

You can find the complete test script in the repository:

python examples/tutorials/test_01_bell_state.py

This will run the tutorial and verify that the Bell state is created correctly.


Understanding the Results

Why is this important?

  1. Entanglement: The Bell state demonstrates quantum entanglement - the qubits are correlated in a way that's impossible classically.

  2. Perfect Correlation: When you measure both qubits, they always give the same result. If qubit 0 is 0, qubit 1 is guaranteed to be 0. If qubit 0 is 1, qubit 1 is guaranteed to be 1.

  3. Foundation for Quantum Computing: Bell states are the building blocks for:

  4. Quantum teleportation
  5. Superdense coding
  6. Quantum error correction
  7. Quantum cryptography

Common Mistakes

Wrong Qubit Order

Remember that PSIQIT uses LSB-first ordering. The state |01⟩ means qubit 0 is 1 and qubit 1 is 0.

Forgetting to Run

Don't forget to call circ.run() before measuring. The circuit needs to be executed to produce the final state.


Next Steps

Now that you've created a Bell state, you can:


References

  • Nielsen, M.A. & Chuang, I.L. "Quantum Computation and Quantum Information" - Chapter 2
  • PSIQIT API Reference - Complete documentation for QuantumCircuit