Skip to main content

Bell State

Create quantum entanglement between two qubits - the foundation of quantum computing.

Overview​

The Bell state is the simplest example of quantum entanglement. When two qubits are entangled, measuring one instantly determines the state of the other, regardless of distance.

This example demonstrates:

  • Creating a maximally entangled state
  • Understanding quantum correlations
  • Verifying entanglement quality

The Circuit​

     β”Œβ”€β”€β”€β”     β”Œβ”€β”
q_0: ─ H β”œβ”€β”€β– β”€β”€β”€Mβ”œβ”€β”€β”€
β””β”€β”€β”€β”˜β”Œβ”€β”΄β”€β”β””β•₯β”˜β”Œβ”€β”
q_1: ────── X β”œβ”€β•«β”€β”€Mβ”œ
β””β”€β”€β”€β”˜ β•‘ β””β•₯β”˜
c: 2/═══════════╩══╩═
0 1

The circuit creates the Bell state:

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

Code​

"""
Bell State - Quantum Entanglement
=================================

Creates the maximally entangled Bell state |Φ+⟩.
Expected result: 50% |00⟩ and 50% |11⟩, never |01⟩ or |10⟩
"""

from softqcos_sdk import QCOSClient

def create_bell_state():
"""Create and execute a Bell state circuit."""

client = QCOSClient()

# Bell state circuit
circuit = """
OPENQASM 2.0;
include "qelib1.inc";

qreg q[2];
creg c[2];

// Create Bell state |Φ+⟩
h q[0]; // Put qubit 0 in superposition
cx q[0], q[1]; // Entangle with qubit 1

measure q -> c;
"""

print("πŸ”— Bell State - Quantum Entanglement")
print("=" * 50)

# Execute
result = client.execute(qasm=circuit, shots=2048)

# Analyze results
print(f"\nπŸ“Š Results (2048 shots):")
print("-" * 30)

expected_states = {"00", "11"}
unexpected_states = {"01", "10"}

total_expected = 0
total_unexpected = 0

for state in ["00", "01", "10", "11"]:
count = result.counts.get(state, 0)
percentage = (count / 2048) * 100
bar = "β–ˆ" * int(percentage / 2)

if state in expected_states:
total_expected += count
marker = "βœ“"
else:
total_unexpected += count
marker = "βœ—" if count > 0 else " "

print(f" |{state}⟩: {count:4d} ({percentage:5.1f}%) {bar} {marker}")

# Quality metrics
print(f"\nπŸ“ˆ Entanglement Quality:")

# Correlation
if total_unexpected == 0:
correlation = 1.0
print(f" Perfect correlation: 100%")
else:
correlation = total_expected / 2048
print(f" Correlation: {correlation:.1%}")

# Balance between |00⟩ and |11⟩
count_00 = result.counts.get("00", 0)
count_11 = result.counts.get("11", 0)

if count_00 > 0 and count_11 > 0:
balance = min(count_00, count_11) / max(count_00, count_11)
print(f" State balance: {balance:.1%}")

# Fidelity estimate
fidelity = (total_expected / 2048) * (balance if count_00 > 0 and count_11 > 0 else 1.0)
print(f" Estimated fidelity: {fidelity:.1%}")

if fidelity > 0.95:
print("\nπŸŽ‰ Excellent entanglement quality!")
elif fidelity > 0.85:
print("\nβœ… Good entanglement quality")
else:
print("\n⚠️ Entanglement quality could be improved")

return result

def main():
return create_bell_state()

if __name__ == "__main__":
main()

Expected Output​

πŸ”— Bell State - Quantum Entanglement
==================================================

πŸ“Š Results (2048 shots):
------------------------------
|00⟩: 1031 ( 50.3%) β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ βœ“
|01⟩: 0 ( 0.0%)
|10⟩: 0 ( 0.0%)
|11⟩: 1017 ( 49.7%) β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ βœ“

πŸ“ˆ Entanglement Quality:
Perfect correlation: 100%
State balance: 98.6%
Estimated fidelity: 98.6%

πŸŽ‰ Excellent entanglement quality!

All Four Bell States​

There are four maximally entangled Bell states:

"""All Four Bell States"""

from softqcos_sdk import QCOSClient

def create_all_bell_states():
client = QCOSClient()

bell_states = {
"Ξ¦+": {
"circuit": """
OPENQASM 2.0; include "qelib1.inc";
qreg q[2]; creg c[2];
h q[0]; cx q[0], q[1];
measure q -> c;
""",
"expected": "|00⟩ + |11⟩"
},
"Ξ¦-": {
"circuit": """
OPENQASM 2.0; include "qelib1.inc";
qreg q[2]; creg c[2];
x q[0]; h q[0]; cx q[0], q[1];
measure q -> c;
""",
"expected": "|00⟩ - |11⟩"
},
"Ξ¨+": {
"circuit": """
OPENQASM 2.0; include "qelib1.inc";
qreg q[2]; creg c[2];
h q[0]; cx q[0], q[1]; x q[1];
measure q -> c;
""",
"expected": "|01⟩ + |10⟩"
},
"Ξ¨-": {
"circuit": """
OPENQASM 2.0; include "qelib1.inc";
qreg q[2]; creg c[2];
x q[0]; h q[0]; cx q[0], q[1]; x q[1];
measure q -> c;
""",
"expected": "|01⟩ - |10⟩"
}
}

print("πŸ”— All Four Bell States")
print("=" * 60)

for name, state in bell_states.items():
result = client.execute(qasm=state["circuit"], shots=1024)

print(f"\n|{name}⟩ = (1/√2)({state['expected']})")
print(f" Counts: {dict(sorted(result.counts.items()))}")

if __name__ == "__main__":
create_all_bell_states()

Understanding Entanglement​

Why Only |00⟩ and |11⟩?​

The CNOT gate flips the target qubit (q[1]) only when the control qubit (q[0]) is |1⟩:

  1. After H gate: q[0] is in superposition (|0⟩ + |1⟩)/√2
  2. CNOT correlates q[1] with q[0]:
    • When q[0] = |0⟩: q[1] stays |0⟩ β†’ |00⟩
    • When q[0] = |1⟩: q[1] flips to |1⟩ β†’ |11⟩

The qubits are now entangled - they share a quantum correlation that cannot be described by classical physics.

Spooky Action at a Distance​

If you measure qubit 0 and get |0⟩, you instantly know qubit 1 is also |0⟩, even if the qubits are light-years apart. This is what Einstein called "spooky action at a distance."

Note: This doesn't allow faster-than-light communication because the measurement outcome is random.

Production Usage​

With Optimization​

from softqcos_sdk import QCOSClient

client = QCOSClient()

# Optimize circuit for target hardware
optimized = client.optimize(
circuit=bell_circuit,
target="ionq",
objective="max_fidelity"
)

print(f"Gate reduction: {optimized.improvements['gate_reduction']}")
print(f"Optimized circuit:\n{optimized.optimized_qasm}")

# Execute optimized circuit
result = client.execute(qasm=optimized.optimized_qasm, shots=1024)

With Cost Estimation​

# Estimate cost before execution
estimate = client.estimate_cost(
circuit=bell_circuit,
backend="azure_quantum_ionq",
shots=1024
)

print(f"Estimated cost: €{estimate.cost_eur:.4f}")
print(f"Estimated time: {estimate.time_seconds}s")

# Execute only if within budget
if estimate.cost_eur < 1.0:
result = client.execute(
qasm=bell_circuit,
backend="azure_quantum_ionq",
shots=1024
)

Next Steps​