diff --git a/src/qailo/state_vector/fidelity.py b/src/qailo/state_vector/fidelity.py index 517c14c..953298d 100644 --- a/src/qailo/state_vector/fidelity.py +++ b/src/qailo/state_vector/fidelity.py @@ -4,4 +4,4 @@ def fidelity(v0, v1): v0 = v0 / np.linalg.norm(v0) v1 = v1 / np.linalg.norm(v1) - return np.abs(np.vdot(v0, v1)) + return np.abs(np.vdot(v0, v1))**2 diff --git a/test/state_vector/test_apply_seq.py b/test/state_vector/test_apply_seq.py index 2476abd..62f9788 100644 --- a/test/state_vector/test_apply_seq.py +++ b/test/state_vector/test_apply_seq.py @@ -16,5 +16,5 @@ def test_apply_seq(): assert q.sv.fidelity(v1, v1) == approx(1) assert q.sv.fidelity(v2, v2) == approx(1) assert q.sv.fidelity(v1, v2) == approx(1) - assert q.sv.fidelity(v0, v1) == approx(1 / np.sqrt(2**n)) - assert q.sv.fidelity(v0, v2) == approx(1 / np.sqrt(2**n)) + assert q.sv.fidelity(v0, v1) == approx(1 / 2**n) + assert q.sv.fidelity(v0, v2) == approx(1 / 2**n) diff --git a/test/state_vector/test_fidelity.py b/test/state_vector/test_fidelity.py index 946c1fb..cbcab77 100644 --- a/test/state_vector/test_fidelity.py +++ b/test/state_vector/test_fidelity.py @@ -11,4 +11,4 @@ def test_fidelity(): sv1 = q.sv.apply(sv1, q.op.h(), [i]) assert q.sv.fidelity(sv0, sv0) == approx(1) assert q.sv.fidelity(sv1, sv1) == approx(1) - assert q.sv.fidelity(sv0, sv1) == approx(1 / np.sqrt(2**n)) + assert q.sv.fidelity(sv0, sv1) == approx(1 / 2**n)