Skip to content

Commit

Permalink
fix definition of fidelity
Browse files Browse the repository at this point in the history
  • Loading branch information
wistaria committed Nov 14, 2023
1 parent a0d2ccc commit 6b1f7ba
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/qailo/state_vector/fidelity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions test/state_vector/test_apply_seq.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion test/state_vector/test_fidelity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 6b1f7ba

Please sign in to comment.