Writing Python code to generate the $\Phi^+$ Bell state is an essential skill in quantum computing. The process involves combining single-qubit superposition with the multi-qubit interaction of the CNOT gate.The goal is to create a circuit that transforms the default state $|00\rangle$ into the entangled state:$$ |\Phi^+\rangle = \frac{|00\rangle + |11\rangle}{\sqrt{2}} $$This specific state represents a scenario where two qubits are perfectly correlated. If you measure the first qubit as 0, the second is guaranteed to be 0. If you measure the first as 1, the second is guaranteed to be 1. You will never observe $|01\rangle$ or $|10\rangle$.Designing the CircuitBefore writing code, we must visualize the sequence of operations. To create entanglement from a clean state, we need two steps. First, we place the control qubit into a superposition. Second, we use that superposition to control the target qubit.Hadamard (H) on Qubit 0: This places Qubit 0 into the state $\frac{|0\rangle + |1\rangle}{\sqrt{2}}$.CNOT (CX) with Control 0 and Target 1: Since Qubit 0 is in superposition, the CNOT gate acts on Qubit 1 only for the portion of the state where Qubit 0 is $|1\rangle$.This sequence links the two qubits inseparable.digraph BellCircuit { rankdir=LR; node [shape=box, style=filled, fontname="Helvetica", fontsize=12]; edge [fontname="Helvetica", fontsize=10]; // Inputs q0 [label="q0 |0⟩", fillcolor="#e9ecef", width=0.8]; q1 [label="q1 |0⟩", fillcolor="#e9ecef", width=0.8]; // Gates H [label="H Gate", fillcolor="#a5d8ff", style="filled,rounded"]; CNOT [label="CNOT", fillcolor="#b2f2bb", style="filled,rounded"]; // Measurements M0 [label="Measure q0", fillcolor="#fcc2d7", shape=oval]; M1 [label="Measure q1", fillcolor="#fcc2d7", shape=oval]; // Connections q0 -> H; H -> CNOT [label="Control"]; q1 -> CNOT [label="Target"]; CNOT -> M0 [label="Output 0"]; CNOT -> M1 [label="Output 1"]; }Flow of operations to generate the standard Bell state.Python ImplementationWe will use a standard quantum software development kit structure. The logic remains consistent across most Python quantum libraries. We define a register for our qubits, apply the gates in sequence, and then simulate the measurement.First, we initialize the quantum circuit. We require two quantum bits (qubits) to hold the state and two classical bits to store the measurement results.# Import necessary components from qiskit import QuantumCircuit, Aer, execute # Initialize a Quantum Circuit with 2 qubits and 2 classical bits qc = QuantumCircuit(2, 2) # Step 1: Apply the Hadamard gate to the first qubit (q0) # This creates the superposition state on q0 qc.h(0) # Step 2: Apply the CNOT gate # q0 is the control, q1 is the target qc.cx(0, 1) # Step 3: Measure both qubits # Map quantum result q0 to classical bit 0 # Map quantum result q1 to classical bit 1 qc.measure([0, 1], [0, 1]) # Display the drawing of the circuit (optional text representation) print(qc.draw())When you execute the drawing command, you should see a visual confirmation that the H gate is applied to line q0, followed by a vertical line connecting q0 and q1 representing the CNOT.Simulating the MeasurementIn a perfect mathematical model, the probability of measuring $|00\rangle$ is exactly 50%, and the probability of measuring $|11\rangle$ is exactly 50%. However, when we run this on a simulator (or a real quantum computer), we perform the experiment multiple times to build a statistical distribution. These repetitions are often called "shots."We will run the circuit 1,000 times and count the outcomes.# Use a local simulator backend = Aer.get_backend('qasm_simulator') # Execute the circuit 1000 times job = execute(qc, backend, shots=1000) # Get the results result = job.result() counts = result.get_counts(qc) print("Measurement Counts:", counts)Understanding the OutputYou will likely see an output resembling this: {'00': 492, '11': 508}Notice two specific details in this result.First, the numbers are roughly equal but not exactly 500 each. This is due to statistical randomness, similar to flipping a fair coin 1,000 times. You rarely get exactly 500 heads and 500 tails.Second, and most importantly, the keys '01' and '10' are missing or have zero counts. This absence confirms entanglement. In a non-entangled system where two qubits are in random superposition, you would expect to see all four combinations ($00, 01, 10, 11$). Here, the state of the second qubit is entirely dependent on the first.Visualizing the CorrelationWe can visualize these results to see the probability distribution clearly. The chart below represents the ideal outcome of our Bell state generator.{ "layout": { "title": "Bell State Measurement Probabilities", "xaxis": { "title": "State |q1 q0>", "type": "category" }, "yaxis": { "title": "Probability", "range": [0, 1] }, "plot_bgcolor": "#f8f9fa", "paper_bgcolor": "#ffffff" }, "data": [ { "type": "bar", "x": ["|00>", "|01>", "|10>", "|11>"], "y": [0.5, 0, 0, 0.5], "marker": { "color": ["#4dabf7", "#e9ecef", "#e9ecef", "#4dabf7"] } } ] }The probability distribution shows outcomes are restricted to only correlated states.Creating Other Bell StatesThe logic we used above generates the $\Phi^+$ state. However, there are four Bell states in total. You can generate the other three by slightly modifying the initial state of the qubits before applying the entanglement sequence (Hadamard + CNOT).The H + CNOT sequence acts as a generic "entangler." The specific correlation you get depends on the input.For $\Phi^-$: Apply an X gate to Qubit 0 after the H gate (or Z gate depending on convention), then CNOT.For $\Psi^+$: Apply an X gate to Qubit 1 before the sequence starts.For $\Psi^-$: Apply an X gate to Qubit 1 before the sequence, and a Z gate to Qubit 0.For example, to create the $\Psi^+$ state ($\frac{|01\rangle + |10\rangle}{\sqrt{2}}$), where the results are always opposite (01 or 10), you simply flip the target qubit to start at 1.# Circuit for Psi+ Bell State qc2 = QuantumCircuit(2, 2) # Initialize q1 to |1> qc2.x(1) # Begin Entanglement Sequence qc2.h(0) qc2.cx(0, 1) qc2.measure([0, 1], [0, 1])If you simulate qc2, you will find that the results cluster around '01' and '10', with '00' and '11' disappearing. This demonstrates that while the output states are different, the fundamental property of entanglement, perfect correlation between qubits, remains the defining feature.