Search code examples
quantum-computingq#qubit

3 Way Quantum Entanglement with a Hadamard Transformed (superposition) Qubit


When running the following operations on 3 qubits:

H(qubits[0]);
CNOT(qubits[0], qubits[1]);
CNOT(qubits[0], qubits[2]);
CNOT(qubits[1], qubits[2]);

I get these results: qubit 0 is in a superposition qubit 1 is the same as qubit 0 qubit 2 is the same as qubit 0 half the time. e.g. superposition-like values.

Why does running CNOT on qubit 2 with both other qubits after running CNOT on qubit 1 with qubit 0 cause qubit 2 to enter a state of superposition between qubit 0 and not qubit 0?


Solution

  • If you do some quantum computing maths, you will find out that you end up in the following state:

    |ψ 〉 = (|000〉 + |011〉) / √2
    

    This is essentially a superposition between qubit 0 and entangled qubits 1 and 2.

    |ψ 〉 = |0〉 ⊗ (|00〉 + |11〉) / √2
    

    You can do this maths with IBM QISKit in Python:

    from qiskit import QuantumProgram
    from math import sqrt
    import numpy as np
    
    qp = QuantumProgram()
    cname = '3-qubit'
    num_qubits = 3
    qr = qp.create_quantum_register('qr', num_qubits)
    cr = qp.create_classical_register('cr', num_qubits)
    qc = qp.create_circuit(cname, [qr], [cr])
    
    qc.h(qr[0])
    qc.cx(qr[0], qr[1])
    qc.cx(qr[0], qr[2])
    qc.cx(qr[1], qr[2])
    
    qc.measure(qr, cr)
    
    results = qp.execute(cname)
    print(results.get_counts(cname))
    

    This would give you a result similar to the following:

    {'000': 530, '011': 494}
    

    You can also explicitly obtain this state |ψ〉 by taking the unitary matrix of your circuit and applying it to your initial state |000〉, that is a vector [1,0,0,0,0,0,0,0]:

    results = qp.execute(cname, backend='local_unitary_simulator', shots=1)
    data = results.get_data(cname)
    u = np.real(data['unitary'] * sqrt(2.0)).astype(int)
    psi = np.zeros(2**num_qubits, dtype=np.int_)
    psi[0] = 1
    u @ psi
    

    The result is

    array([1, 0, 0, 1, 0, 0, 0, 0])
    

    The 0-th entry is |000〉, the 3-rd entry is |011〉.