From 9d8fd5a26c6594f6393b093c9bc184a3365b528a Mon Sep 17 00:00:00 2001 From: "Kevin J. Sung" Date: Tue, 28 May 2024 11:32:48 -0400 Subject: [PATCH] use hellinger_fidelity function from qiskit (#1426) --- docs/verify/simulate-with-qiskit-aer.ipynb | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/docs/verify/simulate-with-qiskit-aer.ipynb b/docs/verify/simulate-with-qiskit-aer.ipynb index 04cdee32757..a4bd5825053 100644 --- a/docs/verify/simulate-with-qiskit-aer.ipynb +++ b/docs/verify/simulate-with-qiskit-aer.ipynb @@ -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", @@ -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)" ] }, {