Skip to content

Commit

Permalink
Analysis
Browse files Browse the repository at this point in the history
Change-Id: Ib0ad42e19989ea513d31fcd406ce075d56c9a6b7
  • Loading branch information
mpharrigan committed Aug 25, 2022
1 parent e7d1b3e commit c34bfb7
Show file tree
Hide file tree
Showing 5 changed files with 396 additions and 105 deletions.
20 changes: 13 additions & 7 deletions docs/ftbbl.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,7 @@
" <th>n_repetitions</th>\n",
" <th>success_probability</th>\n",
" <th>processor_str</th>\n",
" <th>job_finished_time</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
Expand All @@ -922,6 +923,7 @@
" <td>1000</td>\n",
" <td>0.954</td>\n",
" <td>rainbow-depol(5.000e-03)</td>\n",
" <td>1969-12-31 16:00:00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
Expand All @@ -935,6 +937,7 @@
" <td>1000</td>\n",
" <td>0.940</td>\n",
" <td>rainbow-depol(5.000e-03)</td>\n",
" <td>1969-12-31 16:00:00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
Expand All @@ -948,6 +951,7 @@
" <td>1000</td>\n",
" <td>0.946</td>\n",
" <td>rainbow-depol(5.000e-03)</td>\n",
" <td>1969-12-31 16:00:00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
Expand All @@ -961,6 +965,7 @@
" <td>1000</td>\n",
" <td>0.708</td>\n",
" <td>rainbow-depol(5.000e-03)</td>\n",
" <td>1969-12-31 16:00:00</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
Expand All @@ -974,6 +979,7 @@
" <td>1000</td>\n",
" <td>0.682</td>\n",
" <td>rainbow-depol(5.000e-03)</td>\n",
" <td>1969-12-31 16:00:00</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
Expand All @@ -994,12 +1000,12 @@
"3 1 40 0 1000 0.708 \n",
"4 1 40 1 1000 0.682 \n",
"\n",
" processor_str \n",
"0 rainbow-depol(5.000e-03) \n",
"1 rainbow-depol(5.000e-03) \n",
"2 rainbow-depol(5.000e-03) \n",
"3 rainbow-depol(5.000e-03) \n",
"4 rainbow-depol(5.000e-03) "
" processor_str job_finished_time \n",
"0 rainbow-depol(5.000e-03) 1969-12-31 16:00:00 \n",
"1 rainbow-depol(5.000e-03) 1969-12-31 16:00:00 \n",
"2 rainbow-depol(5.000e-03) 1969-12-31 16:00:00 \n",
"3 rainbow-depol(5.000e-03) 1969-12-31 16:00:00 \n",
"4 rainbow-depol(5.000e-03) 1969-12-31 16:00:00 "
]
},
"execution_count": 15,
Expand Down Expand Up @@ -1043,7 +1049,7 @@
"\n",
"colors = plt.get_cmap('tab10')\n",
"\n",
"for i, row in total_df.iterrows():\n",
"for i, row in total_df.reset_index().iterrows():\n",
" plt.errorbar(\n",
" x=row['macrocycle_depth'],\n",
" y=row['success_probability_mean'],\n",
Expand Down
111 changes: 70 additions & 41 deletions recirq/otoc/loschmidt/tilted_square_lattice/analysis-walkthrough.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,22 @@
"metadata": {},
"outputs": [],
"source": [
"means_df, means_gb_cols = analysis.groupby_all_except(\n",
" df.drop(['n_qubits', 'q_area'], axis=1), \n",
" y_cols=('instance_i', 'success_probability'), \n",
" agg_func={'success_probability': ['mean', 'std']}\n",
")\n",
"from analysis import WHD_GB_COLS\n",
"WHD_GB_COLS"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"means_y_cols = {\n",
" 'success_probability_mean': ('success_probability', 'mean'),\n",
" 'success_probability_std': ('success_probability', 'std'),\n",
" 'job_finished_time': ('job_finished_time', 'last'),\n",
"}\n",
"means_df = df.groupby(WHD_GB_COLS).agg(**means_y_cols)\n",
"means_df"
]
},
Expand All @@ -137,11 +148,24 @@
"metadata": {},
"outputs": [],
"source": [
"vs_depth_df, vs_depth_gb_cols = analysis.groupby_all_except(\n",
" means_df, \n",
" y_cols=('macrocycle_depth', 'success_probability_mean', 'success_probability_std'),\n",
" agg_func=list\n",
")\n",
"from analysis import WH_GB_COLS\n",
"WH_GB_COLS"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"vs_depth_y_cols = {\n",
" 'macrocycle_depth': list,\n",
" 'success_probability_mean': list,\n",
" 'success_probability_std': list,\n",
" 'job_finished_time': 'last',\n",
"}\n",
"\n",
"vs_depth_df = means_df.reset_index(level='macrocycle_depth').groupby(WH_GB_COLS).agg(vs_depth_y_cols)\n",
"vs_depth_df"
]
},
Expand All @@ -151,18 +175,18 @@
"metadata": {},
"outputs": [],
"source": [
"for i, row in vs_depth_df.iterrows():\n",
"for i, row in vs_depth_df.reset_index().iterrows():\n",
" plt.errorbar(\n",
" x=row['macrocycle_depth'],\n",
" y=row['success_probability_mean'],\n",
" yerr=row['success_probability_std'],\n",
" label=', '.join(f'{row[col]}' for col in vs_depth_gb_cols),\n",
" label=', '.join(f'{row[col]}' for col in WH_GB_COLS),\n",
" capsize=5, ls='', marker='o',\n",
" )\n",
" \n",
"plt.xlabel('Macrocycle Depth')\n",
"plt.ylabel('Success Probability')\n",
"plt.legend(title=','.join(vs_depth_gb_cols), loc='best')\n",
"plt.legend(title=','.join(WH_GB_COLS), loc='best')\n",
"plt.tight_layout()"
]
},
Expand Down Expand Up @@ -197,12 +221,14 @@
"metadata": {},
"outputs": [],
"source": [
"agg_df3, gb_cols3 = analysis.groupby_all_except(\n",
" df.drop('n_qubits', axis=1),\n",
" y_cols=('instance_i', 'macrocycle_depth', 'q_area', 'success_probability'),\n",
" agg_func=list,\n",
")\n",
"agg_df3"
"vs_size_y_cols = {\n",
" 'macrocycle_depth': list,\n",
" 'success_probability': list,\n",
" 'job_finished_time': 'last',\n",
" 'n_qubits': analysis.assert_one_unique_val,\n",
"}\n",
"vs_size_df = df.groupby(WH_GB_COLS).agg(vs_size_y_cols)\n",
"vs_size_df"
]
},
{
Expand Down Expand Up @@ -230,17 +256,8 @@
"metadata": {},
"outputs": [],
"source": [
"print(vs_depth_gb_cols)\n",
"print(gb_cols3)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"total_df = pd.merge(vs_depth_df, fit_df, on=vs_depth_gb_cols)\n",
"duplicate_cols = ['job_finished_time']\n",
"total_df = fit_df.join(vs_depth_df.drop(duplicate_cols, axis=1))\n",
"total_df"
]
},
Expand All @@ -252,7 +269,7 @@
"source": [
"colors = plt.get_cmap('tab10')\n",
"\n",
"for i, row in total_df.iterrows():\n",
"for i, row in total_df.reset_index().iterrows():\n",
" plt.errorbar(\n",
" x=row['macrocycle_depth'],\n",
" y=row['success_probability_mean'],\n",
Expand Down Expand Up @@ -281,7 +298,7 @@
"\n",
"In a local depolarizing model, we expect success to decay exponentially in circuit depth and the number of qubits. We define a quantity called quantum area (`q_area`) which is the circuit width (i.e. number of qubits) multiplied by its depth. This is the number of operations in the circuit (also including any idle operations).\n",
"\n",
"By defining this new quantity, we can fit a curve of fidelity vs. quantum area.. The following cell shows the groupby operation used in `analysis.fit_vs_q_area`."
"By defining this new quantity, we can fit a curve of fidelity vs. quantum area. The following cell shows the groupby operation used in `analysis.fit_vs_q_area`."
]
},
{
Expand All @@ -290,12 +307,22 @@
"metadata": {},
"outputs": [],
"source": [
"agg_df4, gb_cols4 = analysis.groupby_all_except(\n",
" df.drop(['width', 'height'], axis=1),\n",
" y_cols=('q_area', 'n_qubits', 'instance_i', 'macrocycle_depth', 'success_probability'),\n",
" agg_func=list,\n",
")\n",
"agg_df4"
"from analysis import BASE_GB_COLS\n",
"BASE_GB_COLS"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"vs_q_area_y_cols = {\n",
" 'q_area': list,\n",
" 'success_probability': list,\n",
" 'job_finished_time': 'last',\n",
"}\n",
"df.groupby(BASE_GB_COLS).agg(vs_q_area_y_cols)"
]
},
{
Expand Down Expand Up @@ -324,7 +351,9 @@
"outputs": [],
"source": [
"vs_q_area_df, vs_q_area_gb_cols = analysis.agg_vs_q_area(df)\n",
"total_df2 = pd.merge(vs_q_area_df, fit_df2, on=vs_q_area_gb_cols)\n",
"\n",
"duplicate_cols = ['job_finished_time']\n",
"total_df2 = fit_df2.join(vs_q_area_df.drop(duplicate_cols, axis=1))\n",
"total_df2"
]
},
Expand All @@ -336,7 +365,7 @@
"source": [
"colors = plt.get_cmap('tab10')\n",
"\n",
"for i, row in total_df2.iterrows():\n",
"for i, row in total_df2.reset_index().iterrows():\n",
" plt.errorbar(x=row['q_area'], \n",
" y=row['success_probability_mean'], \n",
" yerr=row['success_probability_std'],\n",
Expand All @@ -349,7 +378,7 @@
"\n",
"plt.legend(loc='best')\n",
"plt.xlabel('Quantum Area')\n",
"plt.ylabel('Macrocycle Fidelity')\n",
"plt.ylabel('Success Probability')\n",
"plt.yscale('log')\n",
"plt.tight_layout()"
]
Expand Down
Loading

0 comments on commit c34bfb7

Please sign in to comment.