61 lines
1.7 KiB
Plaintext
61 lines
1.7 KiB
Plaintext
---
|
||
title: hellinger_fidelity
|
||
description: API reference for qiskit.quantum_info.hellinger_fidelity
|
||
in_page_toc_min_heading_level: 1
|
||
python_api_type: function
|
||
python_api_name: qiskit.quantum_info.hellinger_fidelity
|
||
---
|
||
|
||
# qiskit.quantum\_info.hellinger\_fidelity
|
||
|
||
<Function id="qiskit.quantum_info.hellinger_fidelity" isDedicatedPage={true} github="https://github.com/qiskit/qiskit/tree/stable/0.18/qiskit/quantum_info/analysis/distance.py" signature="hellinger_fidelity(dist_p, dist_q)">
|
||
Computes the Hellinger fidelity between two counts distributions.
|
||
|
||
The fidelity is defined as $\left(1-H^{2}\right)^{2}$ where H is the Hellinger distance. This value is bounded in the range \[0, 1].
|
||
|
||
This is equivalent to the standard classical fidelity $F(Q,P)=\left(\sum_{i}\sqrt{p_{i}q_{i}}\right)^{2}$ that in turn is equal to the quantum state fidelity for diagonal density matrices.
|
||
|
||
**Parameters**
|
||
|
||
* **dist\_p** (*dict*) – First dict of counts.
|
||
* **dist\_q** (*dict*) – Second dict of counts.
|
||
|
||
**Returns**
|
||
|
||
Fidelity
|
||
|
||
**Return type**
|
||
|
||
float
|
||
|
||
**Example**
|
||
|
||
```python
|
||
from qiskit import QuantumCircuit, execute, BasicAer
|
||
from qiskit.quantum_info.analysis import hellinger_fidelity
|
||
|
||
qc = QuantumCircuit(5, 5)
|
||
qc.h(2)
|
||
qc.cx(2, 1)
|
||
qc.cx(2, 3)
|
||
qc.cx(3, 4)
|
||
qc.cx(1, 0)
|
||
qc.measure(range(5), range(5))
|
||
|
||
sim = BasicAer.get_backend('qasm_simulator')
|
||
res1 = execute(qc, sim).result()
|
||
res2 = execute(qc, sim).result()
|
||
|
||
hellinger_fidelity(res1.get_counts(), res2.get_counts())
|
||
```
|
||
|
||
```python
|
||
0.9999961828418649
|
||
```
|
||
|
||
**References**
|
||
|
||
[Quantum Fidelity @ wikipedia](https://en.wikipedia.org/wiki/Fidelity_of_quantum_states) [Hellinger Distance @ wikipedia](https://en.wikipedia.org/wiki/Hellinger_distance)
|
||
</Function>
|
||
|