Skip to content

Commit 5fdb80d

Browse files
authored
[XEB] Theory notebook: fix pauli vs. depol error number (#4097)
In the XEB theory notebook, the `p**(depth)` line wasn't exactly matching up with the XEB decay curve. This adds notes about the distinction between pauli error and depolarizing error rates and performs the necessary fixup for comparison. There's also a little math notation tidying.
1 parent 115e50e commit 5fdb80d

File tree

1 file changed

+45
-8
lines changed

1 file changed

+45
-8
lines changed

docs/qcvv/xeb_theory.ipynb

+45-8
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@
251251
"outputs": [],
252252
"source": [
253253
"# We will truncate to these lengths\n",
254-
"cycle_depths = np.arange(3, MAX_DEPTH, 9)\n",
254+
"cycle_depths = np.arange(1, MAX_DEPTH + 1, 9)\n",
255255
"cycle_depths"
256256
]
257257
},
@@ -275,8 +275,10 @@
275275
"source": [
276276
"pure_sim = cirq.Simulator()\n",
277277
"\n",
278-
"P_DEPOL = 5e-3\n",
279-
"noisy_sim = cirq.DensityMatrixSimulator(noise=cirq.depolarize(P_DEPOL))\n",
278+
"# Pauli Error. If there is an error, it is either X, Y, or Z\n",
279+
"# with probability E_PAULI / 3\n",
280+
"E_PAULI = 5e-3\n",
281+
"noisy_sim = cirq.DensityMatrixSimulator(noise=cirq.depolarize(E_PAULI))\n",
280282
"\n",
281283
"# These two qubit circuits have 2^2 = 4 probabilities\n",
282284
"DIM = 4\n",
@@ -386,10 +388,10 @@
386388
"$$\n",
387389
"\n",
388390
"We estimate f by performing least squares\n",
389-
"minimization of the quantity\n",
391+
"minimization of the sum of squared residuals\n",
390392
"\n",
391393
"$$\n",
392-
" f (e_U - u_U) - (m_U - u_U)\n",
394+
" \\sum_U \\left(f (e_U - u_U) - (m_U - u_U)\\right)^2\n",
393395
"$$\n",
394396
"\n",
395397
"over different random circuits. The solution to the\n",
@@ -456,7 +458,7 @@
456458
" \n",
457459
" global _lines\n",
458460
" _lines += [l] # for legend\n",
459-
" return pd.Series({'fid_lsq': fid_lsq})\n",
461+
" return pd.Series({'fidelity': fid_lsq})\n",
460462
"\n",
461463
"fids = df.groupby('cycle_depth').apply(per_cycle_depth).reset_index()\n",
462464
"plt.xlabel(r'$e_U - u_U$', fontsize=18)\n",
@@ -483,16 +485,51 @@
483485
},
484486
"outputs": [],
485487
"source": [
486-
"plt.plot(fids['cycle_depth'], fids['fid_lsq'], label='LSq')\n",
488+
"plt.plot(\n",
489+
" fids['cycle_depth'], \n",
490+
" fids['fidelity'],\n",
491+
" marker='o',\n",
492+
" label='Least Squares')\n",
487493
"\n",
488494
"xx = np.linspace(0, fids['cycle_depth'].max())\n",
489-
"plt.plot(xx, (1-P_DEPOL)**(4*xx), label=r'$(1-\\mathrm{depol})^{4d}$')\n",
495+
"\n",
496+
"# In XEB, we extract the depolarizing fidelity, which is\n",
497+
"# related to (but not equal to) the Pauli error.\n",
498+
"# For the latter, an error involves doing X, Y, or Z with E_PAULI/3\n",
499+
"# but for the former, an error involves doing I, X, Y, or Z with e_depol/4\n",
500+
"e_depol = E_PAULI / (1 - 1/DIM**2)\n",
501+
"\n",
502+
"# The additional factor of four in the exponent is because each layer\n",
503+
"# involves two moments of two qubits (so each layer has four applications\n",
504+
"# of a single-qubit single-moment depolarizing channel).\n",
505+
"plt.plot(xx, (1-e_depol)**(4*xx), label=r'$(1-\\mathrm{e\\_depol})^{4d}$')\n",
490506
"\n",
491507
"plt.ylabel('Circuit fidelity', fontsize=18)\n",
492508
"plt.xlabel('Cycle Depth $d$', fontsize=18)\n",
493509
"plt.legend(loc='best')\n",
510+
"plt.yscale('log')\n",
494511
"plt.tight_layout()"
495512
]
513+
},
514+
{
515+
"cell_type": "code",
516+
"execution_count": null,
517+
"metadata": {
518+
"id": "e931726da2af"
519+
},
520+
"outputs": [],
521+
"source": [
522+
"from cirq.experiments.xeb_fitting import fit_exponential_decays\n",
523+
"\n",
524+
"# Ordinarily, we'd use this function to fit curves for multiple pairs.\n",
525+
"# We add our qubit pair as a column.\n",
526+
"fids['pair'] = [(q0, q1)] * len(fids)\n",
527+
"\n",
528+
"fit_df = fit_exponential_decays(fids)\n",
529+
"fit_row = fit_df.iloc[0]\n",
530+
"print(f\"Noise model fidelity: {(1-e_depol)**4:.3e}\")\n",
531+
"print(f\"XEB layer fidelity: {fit_row['layer_fid']:.3e} +- {fit_row['layer_fid_std']:.2e}\")"
532+
]
496533
}
497534
],
498535
"metadata": {

0 commit comments

Comments
 (0)