Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with Fidelity output in Qiskit with noisy gates for entanglement swap #13673

Open
a24l opened this issue Jan 15, 2025 · 0 comments
Open
Labels
bug Something isn't working

Comments

@a24l
Copy link

a24l commented Jan 15, 2025

Environment

  • Qiskit version: 1.3
  • Python version: 3.11.9
  • Operating system:

What is happening?

I'm performing an entanglement swap using 4 qubits in Qiskit. I make my own noisy gates and insert noise in the circuit. I want to create two noisy input Bell pairs of various two different fidelities and, after performing the swap, find the fidelity of the swapped circuit. I'm using a depolarizing error for the CNOT gates and CZ gates. The problem arises when I make the measurement and calculate the fidelity using the Hellinger Fidelity function in Qiskit. For the lower value of two input fidelities, the outcome fidelity is higher than the two input fidelities. How is that possible?

It seems like the there is an inherent problem in the depolarizing channel, for lower values ~0,4 - 0.5. The output fidelities are always higher when f1 and f2 values are selected within the range of ~0.4 - 0.5

How can we reproduce the issue?

def entanglement_swap(f1, f2, dep_errorx, dep_errorz):
    """Simulate entanglement swapping with depolarizing errors and given initial fidelities.
    
    Args:
        f1 (float): Fidelity of the first Bell pair.
        f2 (float): Fidelity of the second Bell pair.
        dep_error (float): Depolarizing error rate for CNOT gates.
    
    Returns:
        float: Estimated fidelity after entanglement swapping.
    """
    # Calculate depolarizing error rates from the given fidelities f1 and f2
    p1 =  (4/3) *(1 - (f1))
    p2 =  (4/3) *(1 - (f2))


    
    #prepare the noisy gates 
    cx_gate = CXGate()  # regular cnot gate
    h_gate = HGate() # regular H gate
    cz_gate = CZGate()

    cx1_gate = CXGate(label="cx1")  # first labelled CX gate 
    cx2_gate = CXGate(label="cx2")  # second labelled CX gate
    cx3_gate = CXGate(label="cx3")  # third labelled CX gate 
    cx4_gate = CXGate(label="cx4")  # fourth labelled CX gate 

    cz1_gate = CZGate(label="cz1")
    
    # create the depolarizing errors for each CX gate
    cx1_error = depolarizing_error(p1, 2)   # For the first Bell pair
    cx2_error = depolarizing_error(p2, 2)   # For the second Bell pair
    cx3_error = depolarizing_error(dep_errorx, 2)
    cx4_error = depolarizing_error(dep_errorx, 2)

    cz_error = depolarizing_error(dep_errorz, 2)

    #readout error only if we perform any sort of measurement
    #ro_err_rate = 0.1
    #ro_err = ReadoutError( [[1 - ro_err_rate, ro_err_rate], [ro_err_rate, 1 - ro_err_rate]] )


    #jot down the noise model
    noise_model_gate = NoiseModel()
    noise_model_gate.add_all_qubit_quantum_error(cx1_error, cx1_gate.label)
    noise_model_gate.add_all_qubit_quantum_error(cx2_error, cx2_gate.label)
    noise_model_gate.add_all_qubit_quantum_error(cx3_error, cx3_gate.label)
    noise_model_gate.add_all_qubit_quantum_error(cx4_error, cx4_gate.label)
    
    noise_model_gate.add_all_qubit_quantum_error(cz_error, cz1_gate.label)
    
   # noise_model_gate.add_readout_error(ro_err, [0])


    noise_model_gate.add_basis_gates(['cx','cz1', 'cx1','cx2','cx3','cx4'])       #adds noise to basis gates
    
    # make the quantum circuit with noise gates
    bell_noise = QuantumCircuit(4, 2)

    #make the first bell pair
    bell_noise.h(0)
    bell_noise.append(cx1_gate, [0,1])  # first noisy cx gate

    #make the second bell pair
    bell_noise.h(2)
    bell_noise.append(cx2_gate, [2,3])  # second noisy cx gate


    bell_noise.append(cx3_gate, [1,2])  # swap noisy cx gate
    #bell_noise.cx(1,2)
    bell_noise.h(1)

    bell_noise.barrier()
    bell_noise.append(cz1_gate, [0,1])
    #bell_noise.cz(0,1)
    #bell_noise.cx(2,3)
    bell_noise.append(cx4_gate, [2,3])
    bell_noise.barrier()
    bell_noise.measure([0,3],[0,1])

    
    # Simulate the circuit with the noise model
    basis_gates = noise_model_gate.basis_gates
    sim_noise = AerSimulator(noise_model=noise_model_gate, basis_gates = basis_gates)   
    rep = 2000
    qc_aer = transpile(bell_noise, backend= sim_noise)
    result = sim_noise.run(qc_aer, shots=rep).result()
    counts = result.get_counts()

    
    
    # Estimate fidelity (assuming ideal Bell state |Φ+⟩ = (|00⟩ + |11⟩)/√2)
    
    #fidelity = correct_outcomes / rep
    
    return counts

f1 = 0.4
f2 = 0.4

dep_errorx = 0
dep_errorz = 0
noise_counts = entanglement_swap(f1, f2, dep_errorx, dep_errorz)  # , dep_errorx, dep_errorz)

#use Hellinger fidelity for ideal and noise count dict
fidelity = hellinger_fidelity(counts_ideal, noise_counts)
print("Fidelity of entanglement swap F_AC=", fidelity)

Fidelity of entanglement swap F_AC= 0.5224602685141051

What should happen?

The fidelity of the total output of the swapped circuit has to be less than the input fidelities of the bell pair.

Any suggestions?

No response

@a24l a24l added the bug Something isn't working label Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant