2
$\begingroup$

I have a circuit with different structures, now I'm trying to calculate the fidelity between those with the original one. How do I calculate the fidelity? I want also to initialize the state vector by myself. Can someone show how to compute fidelity for the below example?

For example if I have a circuit like below,

q = QuantumRegister(2)
qc = QuantumCircuit(q)
qc.cu1(3*pi/4, q[0], q[1]);
print(qc)

and different structure

q = QuantumRegister(2)
qc = QuantumCircuit(q)
qc.h(q[0]);
qc.h(q[1]);
qc.cu1(3*pi/4, q[0], q[1]);
qc.h(q[0]);
qc.h(q[1]);
print(qc)
$\endgroup$
1
$\begingroup$

There is more information towards the end of the tutorial here but essentially how you do this is you run both circuits on the state_vector simulator and then you can use the function state_fidelity to work out the fidelity between the two states.

The code to do this should look something like this

from qiskit.quantum_info import state_fidelity

# set up qc1 and qc2

backend = Aer.get_backend('state_vector')

sv1 = execute(qc1, backend).result().get_statevector(qc1)
sv2 = execute(qc2, backend).result().get_statevector(qc2)

print(state_fidelity(sv1, sv2))
| improve this answer | |
$\endgroup$
  • $\begingroup$ I looked at the definition of fidelity in the tutorial: $F(|\psi_1\rangle,\psi_2\rangle) = |\langle\psi_1 \,\text{middle}\, \psi_2\rangle|^2$. What does it mean the $\text{middle}$? I would expect that only inner product is used because in case $|\psi_1\rangle = |\psi_2\rangle$ the $F =|\langle\psi_1| \psi_1\rangle|^2 = ||\, |\psi_1\rangle \,||^2 = 1$ and in case of orthogonal states $F$ is zero. $\endgroup$ – Martin Vesely Mar 18 at 9:47
  • 1
    $\begingroup$ I think that might be a typo, feel free to raise that as an issue against the repo! $\endgroup$ – met927 Mar 18 at 10:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.