|
25 | 25 | import cirq
|
26 | 26 | import pandas as pd
|
27 | 27 | import multiprocessing
|
| 28 | + import matplotlib.pyplot as plt |
28 | 29 |
|
29 | 30 |
|
30 | 31 | def z_phase_calibration_workflow(
|
@@ -109,10 +110,12 @@ def z_phase_calibration_workflow(
|
109 | 110 | pool=pool,
|
110 | 111 | )
|
111 | 112 |
|
112 |
| - return result, xeb_fitting.before_and_after_characterization( |
| 113 | + before_after = xeb_fitting.before_and_after_characterization( |
113 | 114 | fids_df_0, characterization_result=result
|
114 | 115 | )
|
115 | 116 |
|
| 117 | + return result, before_after |
| 118 | + |
116 | 119 |
|
117 | 120 | def calibrate_z_phases(
|
118 | 121 | sampler: 'cirq.Sampler',
|
@@ -191,3 +194,39 @@ def calibrate_z_phases(
|
191 | 194 | params['gamma'] = params.get('gamma', options.gamma_default or 0)
|
192 | 195 | gates[pair] = ops.PhasedFSimGate(**params)
|
193 | 196 | return gates
|
| 197 | + |
| 198 | + |
| 199 | +def plot_z_phase_calibration_result( |
| 200 | + before_after_df: 'pd.DataFrame', |
| 201 | + axes: np.ndarray[Sequence[Sequence['plt.Axes']], np.dtype[np.object_]], |
| 202 | + *, |
| 203 | + with_error_bars: bool = False, |
| 204 | +) -> None: |
| 205 | + """A helper method to plot the result of running z-phase calibration. |
| 206 | +
|
| 207 | + Args: |
| 208 | + before_after_df: The second return object of running `z_phase_calibration_workflow`. |
| 209 | + axes: And ndarray of the axes to plot on. |
| 210 | + The number of axes is expected to be >= number of qubit pairs. |
| 211 | + with_error_bars: Whether to add error bars or not. |
| 212 | + The width of the bar is an upper bound on standard variation of the estimated fidelity. |
| 213 | + """ |
| 214 | + for pair, ax in zip(before_after_df.index, axes.flatten()): |
| 215 | + row = before_after_df.loc[[pair]].iloc[0] |
| 216 | + ax.errorbar( |
| 217 | + row.cycle_depths_0, |
| 218 | + row.fidelities_0, |
| 219 | + yerr=row.layer_fid_std_0 * with_error_bars, |
| 220 | + label='original', |
| 221 | + ) |
| 222 | + ax.errorbar( |
| 223 | + row.cycle_depths_0, |
| 224 | + row.fidelities_c, |
| 225 | + yerr=row.layer_fid_std_c * with_error_bars, |
| 226 | + label='calibrated', |
| 227 | + ) |
| 228 | + ax.axhline(1, linestyle='--') |
| 229 | + ax.set_xlabel('cycle depth') |
| 230 | + ax.set_ylabel('fidelity estimate') |
| 231 | + ax.set_title('-'.join(str(q) for q in pair)) |
| 232 | + ax.legend() |
0 commit comments