Skip to content

Commit

Permalink
use hellinger_fidelity function from qiskit (Qiskit#1426)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinsung authored May 28, 2024
1 parent 0e80bc4 commit a294ea2
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions docs/verify/simulate-with-qiskit-aer.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,9 @@
}
],
"source": [
"import math\n",
"from qiskit.result import ProbDistribution\n",
"from qiskit.quantum_info import hellinger_fidelity\n",
"from qiskit_aer.primitives import Sampler\n",
"\n",
"\n",
"measured_circuit = circuit.copy()\n",
"measured_circuit.measure_all()\n",
"\n",
Expand All @@ -212,18 +210,8 @@
"noisy_quasis = job.result().quasi_dists[0]\n",
"noisy_probs = noisy_quasis.nearest_probability_distribution()\n",
"\n",
"\n",
"# Compute fidelity\n",
"def fidelity(dist1: ProbDistribution, dist2: ProbDistribution) -> float:\n",
" result = 0\n",
" for bitstring in dist1 | dist2:\n",
" prob1 = dist1.get(bitstring, 0)\n",
" prob2 = dist2.get(bitstring, 0)\n",
" result += math.sqrt(prob1 * prob2)\n",
" return result**2\n",
"\n",
"\n",
"fidelity(exact_probs, noisy_probs)"
"hellinger_fidelity(exact_probs, noisy_probs)"
]
},
{
Expand Down

0 comments on commit a294ea2

Please sign in to comment.