{ "cells": [ { "cell_type": "markdown", "id": "361fb535-859f-4055-a4fc-7b1df2064656", "metadata": {}, "source": [ "(howto-analysis)=\n", "# Analysis helpers" ] }, { "cell_type": "markdown", "id": "80c14750-eac2-4ab8-95fb-5e95558b384b", "metadata": {}, "source": [ "(howto-analysis-has-calibration-points)=\n", "## Calibration points autodetection\n", "\n", "In this ideal scenario, if the datapoints indicated by the indices correspond to the\n", "calibration points, then these points will be located on the extremities of a\n", "\"segment\" on the IQ plane." ] }, { "cell_type": "code", "execution_count": null, "id": "5ab42847-2e66-46b2-9677-6dbf5c0443dc", "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "import numpy as np\n", "\n", "from quantify_core.analysis.calibration import has_calibration_points\n", "from quantify_core.utilities.examples_support import mk_iq_shots\n", "\n", "\n", "def _with_cal(data_):\n", " return np.concatenate((data_, (center_0, center_1)))\n", "\n", "\n", "def _print(ax_, data_):\n", " ax_.set_title(\n", " f\"W/out cal.: {has_calibration_points(data_)}\\n\"\n", " f\"With cal.: {has_calibration_points(_with_cal(data_))}\"\n", " )\n", "\n", "\n", "fig, ((ax0, ax1), (ax2, ax3)) = plt.subplots(\n", " 2, 2, figsize=(10, 10 / 1.6), sharex=True, sharey=True\n", ")\n", "\n", "center_0, center_1, center_2 = 0.6 + 1.2j, -0.2 + 0.5j, 0 + 1.5j\n", "NUM_SHOTS = 50\n", "\n", "data = mk_iq_shots(\n", " NUM_SHOTS,\n", " sigmas=[0.1] * 2,\n", " centers=(center_0, center_1),\n", " probabilities=[0.3, 1 - 0.3],\n", ")\n", "\n", "ax0.plot(data.real, data.imag, \"o\", label=\"Shots\")\n", "_print(ax0, data)\n", "\n", "data = mk_iq_shots(\n", " NUM_SHOTS,\n", " sigmas=[0.1] * 3,\n", " centers=(center_0, center_1, center_2),\n", " probabilities=[0.35, 0.35, 1 - 0.35 - 0.35],\n", ")\n", "ax1.plot(data.real, data.imag, \"o\", label=\"Shots\")\n", "_print(ax1, data)\n", "\n", "data = mk_iq_shots(\n", " NUM_SHOTS,\n", " sigmas=[0.1],\n", " centers=(center_0,),\n", " probabilities=[1],\n", ")\n", "ax2.plot(data.real, data.imag, \"o\", label=\"Shots\")\n", "_print(ax2, data)\n", "\n", "data = np.fromiter(\n", " (\n", " mk_iq_shots(\n", " NUM_SHOTS * 2,\n", " sigmas=[0.5] * 2,\n", " centers=(center_0, center_1),\n", " probabilities=[prob, 1 - prob],\n", " ).mean()\n", " for prob in np.linspace(0, 1, 35)\n", " ),\n", " dtype=complex,\n", ")\n", "ax3.plot(data.real, data.imag, \"o\", label=\"Shots\")\n", "_print(ax3, data)\n", "\n", "for i, ax in enumerate(fig.axes):\n", " ax.plot(center_0.real, center_0.imag, \"^\", label=\"|0>\", markersize=10)\n", " ax.plot(center_1.real, center_1.imag, \"d\", label=\"|1>\", markersize=10)\n", " if i == 1:\n", " ax.plot(\n", " center_2.real, center_2.imag, \"*\", label=\"|2>\", markersize=10\n", " )\n", " ax.legend()\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.16" } }, "nbformat": 4, "nbformat_minor": 5 }