Skip to content

Commit

Permalink
[XEB] Theory notebook: fix pauli vs. depol error number (#4097)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mpharrigan committed May 13, 2021
1 parent 115e50e commit 5fdb80d
Showing 1 changed file with 45 additions and 8 deletions.
53 changes: 45 additions & 8 deletions docs/qcvv/xeb_theory.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@
"outputs": [],
"source": [
"# We will truncate to these lengths\n",
"cycle_depths = np.arange(3, MAX_DEPTH, 9)\n",
"cycle_depths = np.arange(1, MAX_DEPTH + 1, 9)\n",
"cycle_depths"
]
},
Expand All @@ -275,8 +275,10 @@
"source": [
"pure_sim = cirq.Simulator()\n",
"\n",
"P_DEPOL = 5e-3\n",
"noisy_sim = cirq.DensityMatrixSimulator(noise=cirq.depolarize(P_DEPOL))\n",
"# Pauli Error. If there is an error, it is either X, Y, or Z\n",
"# with probability E_PAULI / 3\n",
"E_PAULI = 5e-3\n",
"noisy_sim = cirq.DensityMatrixSimulator(noise=cirq.depolarize(E_PAULI))\n",
"\n",
"# These two qubit circuits have 2^2 = 4 probabilities\n",
"DIM = 4\n",
Expand Down Expand Up @@ -386,10 +388,10 @@
"$$\n",
"\n",
"We estimate f by performing least squares\n",
"minimization of the quantity\n",
"minimization of the sum of squared residuals\n",
"\n",
"$$\n",
" f (e_U - u_U) - (m_U - u_U)\n",
" \\sum_U \\left(f (e_U - u_U) - (m_U - u_U)\\right)^2\n",
"$$\n",
"\n",
"over different random circuits. The solution to the\n",
Expand Down Expand Up @@ -456,7 +458,7 @@
" \n",
" global _lines\n",
" _lines += [l] # for legend\n",
" return pd.Series({'fid_lsq': fid_lsq})\n",
" return pd.Series({'fidelity': fid_lsq})\n",
"\n",
"fids = df.groupby('cycle_depth').apply(per_cycle_depth).reset_index()\n",
"plt.xlabel(r'$e_U - u_U$', fontsize=18)\n",
Expand All @@ -483,16 +485,51 @@
},
"outputs": [],
"source": [
"plt.plot(fids['cycle_depth'], fids['fid_lsq'], label='LSq')\n",
"plt.plot(\n",
" fids['cycle_depth'], \n",
" fids['fidelity'],\n",
" marker='o',\n",
" label='Least Squares')\n",
"\n",
"xx = np.linspace(0, fids['cycle_depth'].max())\n",
"plt.plot(xx, (1-P_DEPOL)**(4*xx), label=r'$(1-\\mathrm{depol})^{4d}$')\n",
"\n",
"# In XEB, we extract the depolarizing fidelity, which is\n",
"# related to (but not equal to) the Pauli error.\n",
"# For the latter, an error involves doing X, Y, or Z with E_PAULI/3\n",
"# but for the former, an error involves doing I, X, Y, or Z with e_depol/4\n",
"e_depol = E_PAULI / (1 - 1/DIM**2)\n",
"\n",
"# The additional factor of four in the exponent is because each layer\n",
"# involves two moments of two qubits (so each layer has four applications\n",
"# of a single-qubit single-moment depolarizing channel).\n",
"plt.plot(xx, (1-e_depol)**(4*xx), label=r'$(1-\\mathrm{e\\_depol})^{4d}$')\n",
"\n",
"plt.ylabel('Circuit fidelity', fontsize=18)\n",
"plt.xlabel('Cycle Depth $d$', fontsize=18)\n",
"plt.legend(loc='best')\n",
"plt.yscale('log')\n",
"plt.tight_layout()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "e931726da2af"
},
"outputs": [],
"source": [
"from cirq.experiments.xeb_fitting import fit_exponential_decays\n",
"\n",
"# Ordinarily, we'd use this function to fit curves for multiple pairs.\n",
"# We add our qubit pair as a column.\n",
"fids['pair'] = [(q0, q1)] * len(fids)\n",
"\n",
"fit_df = fit_exponential_decays(fids)\n",
"fit_row = fit_df.iloc[0]\n",
"print(f\"Noise model fidelity: {(1-e_depol)**4:.3e}\")\n",
"print(f\"XEB layer fidelity: {fit_row['layer_fid']:.3e} +- {fit_row['layer_fid_std']:.2e}\")"
]
}
],
"metadata": {
Expand Down

0 comments on commit 5fdb80d

Please sign in to comment.