|
17 | 17 |
|
18 | 18 | from typing import Any, cast, Iterator, List, Optional, Sequence, Tuple, TYPE_CHECKING
|
19 | 19 | import numpy as np
|
| 20 | +from scipy.optimize import curve_fit |
20 | 21 |
|
21 | 22 | from matplotlib import pyplot as plt
|
22 | 23 |
|
@@ -92,13 +93,44 @@ def plot(self, ax: Optional[plt.Axes] = None, **plot_kwargs: Any) -> plt.Axes:
|
92 | 93 | fig, ax = plt.subplots(1, 1, figsize=(8, 8)) # pragma: no cover
|
93 | 94 | ax = cast(plt.Axes, ax) # pragma: no cover
|
94 | 95 | ax.set_ylim((0.0, 1.0)) # pragma: no cover
|
95 |
| - ax.plot(self._num_cfds_seq, self._gnd_state_probs, 'ro-', **plot_kwargs) |
| 96 | + ax.plot(self._num_cfds_seq, self._gnd_state_probs, 'ro', label='data', **plot_kwargs) |
| 97 | + x = np.linspace(self._num_cfds_seq[0], self._num_cfds_seq[-1], 100) |
| 98 | + opt_params, _ = self._fit_exponential() |
| 99 | + ax.plot(x, opt_params[0] * opt_params[2] ** x + opt_params[1], '--k', label='fit') |
| 100 | + ax.legend(loc='upper right') |
96 | 101 | ax.set_xlabel(r"Number of Cliffords")
|
97 | 102 | ax.set_ylabel('Ground State Probability')
|
98 | 103 | if show_plot:
|
99 | 104 | fig.show()
|
100 | 105 | return ax
|
101 | 106 |
|
| 107 | + def pauli_error(self) -> float: |
| 108 | + r"""Returns the Pauli error inferred from randomized benchmarking. |
| 109 | +
|
| 110 | + If sequence fidelity $F$ decays with number of gates $m$ as |
| 111 | +
|
| 112 | + $$F = A p^m + B,$$ |
| 113 | +
|
| 114 | + where $0 < p < 1$, then the Pauli error $r_p$ is given by |
| 115 | +
|
| 116 | + $$r_p = (1 - 1/d^2) * (1 - p),$$ |
| 117 | +
|
| 118 | + where $d = 2^N_Q$ is the Hilbert space dimension and $N_Q$ is the number of qubits. |
| 119 | + """ |
| 120 | + opt_params, _ = self._fit_exponential() |
| 121 | + p = opt_params[2] |
| 122 | + return (1.0 - 1.0 / 4.0) * (1.0 - p) |
| 123 | + |
| 124 | + def _fit_exponential(self) -> Tuple[np.ndarray, np.ndarray]: |
| 125 | + exp_fit = lambda x, A, B, p: A * p**x + B |
| 126 | + return curve_fit( |
| 127 | + f=exp_fit, |
| 128 | + xdata=self._num_cfds_seq, |
| 129 | + ydata=self._gnd_state_probs, |
| 130 | + p0=[0.5, 0.5, 1.0 - 1e-3], |
| 131 | + bounds=([0, 0.25, 0], [0.5, 0.75, 1]), |
| 132 | + ) |
| 133 | + |
102 | 134 |
|
103 | 135 | class TomographyResult:
|
104 | 136 | """Results from a state tomography experiment."""
|
|
0 commit comments