diff options
| author | J08nY | 2024-04-06 00:32:23 +0200 |
|---|---|---|
| committer | J08nY | 2024-04-06 00:33:18 +0200 |
| commit | 57cadf3ea4ae80e999a2f18ab605b633cd78cbee (patch) | |
| tree | a86b6d5c85a9973205d07bd8db78d92240ffad03 | |
| parent | 5840af243a0b1d3d50494094c1fd026c27ce5c3a (diff) | |
| download | pyecsca-notebook-57cadf3ea4ae80e999a2f18ab605b633cd78cbee.tar.gz pyecsca-notebook-57cadf3ea4ae80e999a2f18ab605b633cd78cbee.tar.zst pyecsca-notebook-57cadf3ea4ae80e999a2f18ab605b633cd78cbee.zip | |
Add RPA eval plots.
| -rw-r--r-- | re/rpa.ipynb | 411 |
1 files changed, 380 insertions, 31 deletions
diff --git a/re/rpa.ipynb b/re/rpa.ipynb index f328b2d..d435b15 100644 --- a/re/rpa.ipynb +++ b/re/rpa.ipynb @@ -55,7 +55,7 @@ "metadata": {}, "outputs": [], "source": [ - "%matplotlib inline\n", + "%matplotlib ipympl\n", "hv.extension(\"bokeh\")" ] }, @@ -115,26 +115,36 @@ " RTLMultiplier(add, dbl, None, True, AccumulationOrder.PeqPR, False),\n", " SimpleLadderMultiplier(add, dbl, None, True, True),\n", " BinaryNAFMultiplier(add, dbl, neg, None, ProcessingDirection.LTR, AccumulationOrder.PeqPR, True),\n", + " BinaryNAFMultiplier(add, dbl, neg, None, ProcessingDirection.RTL, AccumulationOrder.PeqPR, True),\n", " WindowNAFMultiplier(add, dbl, neg, 3, None, AccumulationOrder.PeqPR, True, True),\n", " WindowNAFMultiplier(add, dbl, neg, 4, None, AccumulationOrder.PeqPR, True, True),\n", " WindowNAFMultiplier(add, dbl, neg, 5, None, AccumulationOrder.PeqPR, True, True),\n", - " #WindowNAFMultiplier(add, dbl, neg, 4, None, AccumulationOrder.PeqPR, False, True), # Same set of multiples as Window NAF with precompute_negation\n", + " WindowBoothMultiplier(add, dbl, neg, 3, None, AccumulationOrder.PeqPR, True, True),\n", + " WindowBoothMultiplier(add, dbl, neg, 4, None, AccumulationOrder.PeqPR, True, True),\n", + " WindowBoothMultiplier(add, dbl, neg, 5, None, AccumulationOrder.PeqPR, True, True),\n", " SlidingWindowMultiplier(add, dbl, 3, None, ProcessingDirection.LTR, AccumulationOrder.PeqPR, True),\n", " SlidingWindowMultiplier(add, dbl, 4, None, ProcessingDirection.LTR, AccumulationOrder.PeqPR, True),\n", " SlidingWindowMultiplier(add, dbl, 5, None, ProcessingDirection.LTR, AccumulationOrder.PeqPR, True),\n", + " SlidingWindowMultiplier(add, dbl, 3, None, ProcessingDirection.RTL, AccumulationOrder.PeqPR, True),\n", + " SlidingWindowMultiplier(add, dbl, 4, None, ProcessingDirection.RTL, AccumulationOrder.PeqPR, True),\n", + " SlidingWindowMultiplier(add, dbl, 5, None, ProcessingDirection.RTL, AccumulationOrder.PeqPR, True),\n", + " FixedWindowLTRMultiplier(add, dbl, 3, None, AccumulationOrder.PeqPR, True),\n", " FixedWindowLTRMultiplier(add, dbl, 4, None, AccumulationOrder.PeqPR, True),\n", " FixedWindowLTRMultiplier(add, dbl, 5, None, AccumulationOrder.PeqPR, True),\n", " FixedWindowLTRMultiplier(add, dbl, 8, None, AccumulationOrder.PeqPR, True),\n", + " FixedWindowLTRMultiplier(add, dbl, 16, None, AccumulationOrder.PeqPR, True),\n", " FullPrecompMultiplier(add, dbl, None, True, ProcessingDirection.LTR, AccumulationOrder.PeqPR, True, True),\n", " FullPrecompMultiplier(add, dbl, None, False, ProcessingDirection.LTR, AccumulationOrder.PeqPR, True, True),\n", - " #FullPrecompMultiplier(add, dbl, None, False, ProcessingDirection.RTL, AccumulationOrder.PeqPR, True, True), # Same set of multiples as RTL multiplier\n", " BGMWMultiplier(add, dbl, 2, None, ProcessingDirection.LTR, AccumulationOrder.PeqPR, True),\n", " BGMWMultiplier(add, dbl, 3, None, ProcessingDirection.LTR, AccumulationOrder.PeqPR, True),\n", + " BGMWMultiplier(add, dbl, 4, None, ProcessingDirection.LTR, AccumulationOrder.PeqPR, True),\n", " BGMWMultiplier(add, dbl, 5, None, ProcessingDirection.LTR, AccumulationOrder.PeqPR, True),\n", " CombMultiplier(add, dbl, 2, None, AccumulationOrder.PeqPR, True),\n", " CombMultiplier(add, dbl, 3, None, AccumulationOrder.PeqPR, True),\n", + " CombMultiplier(add, dbl, 4, None, AccumulationOrder.PeqPR, True),\n", " CombMultiplier(add, dbl, 5, None, AccumulationOrder.PeqPR, True)\n", - "]" + "]\n", + "print(len(multipliers))" ] }, { @@ -333,7 +343,9 @@ "cell_type": "code", "execution_count": null, "id": "b6c70d89-1c7d-4d7c-bc65-0cf766b86c0a", - "metadata": {}, + "metadata": { + "scrolled": true + }, "outputs": [], "source": [ "p256 = get_params(\"secg\", \"secp256r1\", \"projective\")\n", @@ -342,27 +354,54 @@ }, { "cell_type": "markdown", + "id": "6361c477-5ddf-46ff-8918-864a453b676b", + "metadata": {}, + "source": [ + "Let's see if the result is correct." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1556e604-d0ab-403c-bd44-d53be8e18283", + "metadata": {}, + "outputs": [], + "source": [ + "print(multipliers[0] in res)" + ] + }, + { + "cell_type": "markdown", "id": "068e1ba5-9884-4d2b-97f6-d54313daddad", "metadata": {}, "source": [ + "#### What about (symmetric) noise?\n", "Now we can examine how the method performs in the presence of noise and with various majority vote parameters. Note that the code below spawns several processes (`num_cores`) and saturates their CPU fully, so set this to something appropriate." ] }, { "cell_type": "code", "execution_count": null, - "id": "4e9ca09b-9fe4-4c91-ac37-530892b1df48", + "id": "76b0f82c-64ac-4646-91b9-99f7962200d3", "metadata": {}, "outputs": [], "source": [ "errs = (0, 0.1, 0.2, 0.3, 0.4, 0.5)\n", "majs = (1, 3, 5, 7, 9, 11)\n", + "num_tries = 100" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4e9ca09b-9fe4-4c91-ac37-530892b1df48", + "metadata": {}, + "outputs": [], + "source": [ "correct_tries = np.zeros((len(errs), len(majs)))\n", "precise_tries = np.zeros((len(errs), len(majs)))\n", "query_tries = np.zeros((len(errs), len(majs)))\n", - "total_tries = 0\n", - "\n", - "num_tries = 50" + "total_tries = 0" ] }, { @@ -388,8 +427,8 @@ " res = rpa_distinguish(params, multipliers, oracle, majority=majority)\n", " if mult in res:\n", " correct += 1\n", - " if len(res) == 1:\n", - " precise += 1\n", + " if len(res) == 1:\n", + " precise += 1\n", " return correct, precise, calls\n", "\n", "with TemporaryConfig() as cfg:\n", @@ -404,7 +443,7 @@ " futures.append(pool.submit(measure_mult, *a))\n", " args.append(a)\n", " results = [None for _ in futures]\n", - " for future in tqdm(as_completed(futures), total=len(futures)):\n", + " for future in tqdm(as_completed(futures), total=len(futures), smoothing=0):\n", " j = futures.index(future)\n", " a = args[j]\n", " results[j] = future.result()" @@ -440,12 +479,33 @@ }, { "cell_type": "markdown", + "id": "8c747434-84bb-4acd-a994-45a4b4859a6e", + "metadata": {}, + "source": [ + "And save the results for later." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "857f39ad-f6ba-4006-8da9-92f4318819e2", + "metadata": {}, + "outputs": [], + "source": [ + "np.save(\"rpa_re_correct_rate\", correct_rate)\n", + "np.save(\"rpa_re_precise_rate\", precise_rate)\n", + "np.save(\"rpa_re_query_rate\", query_rate)" + ] + }, + { + "cell_type": "markdown", "id": "9bda1baa-359a-4f9b-889d-f64e055deff6", "metadata": {}, "source": [ - "We can plot two heatmaps:\n", + "We can plot several heatmaps:\n", " - One for the average number of queries to the oracle.\n", - " - One for the success rate of the distinguisher." + " - One for the success rate of the reverse-engineering.\n", + " - One for the precision of the reverse-engineering." ] }, { @@ -457,19 +517,19 @@ "source": [ "fig, ax = plt.subplots()\n", "im = ax.imshow(query_rate.T, cmap=\"plasma\")\n", - "cbar_ax = fig.add_axes((0.90, 0.15, 0.04, 0.69))\n", + "cbar_ax = fig.add_axes((0.85, 0.15, 0.04, 0.69))\n", "cbar = fig.colorbar(im, cax=cbar_ax)\n", - "cbar.ax.set_ylabel(\"Average oracle query rate\", rotation=-90, va=\"bottom\")\n", + "cbar.ax.set_ylabel(\"Oracle query rate\", rotation=-90, va=\"bottom\")\n", "\n", "ax.set_xticks(np.arange(len(errs)), labels=errs)\n", "ax.set_yticks(np.arange(len(majs)), labels=reversed(majs))\n", - "ax.set_xlabel(\"err\")\n", - "ax.set_ylabel(\"majority\")\n", + "ax.set_xlabel(\"error probability\")\n", + "ax.set_ylabel(\"majority vote\")\n", "for i in range(len(errs)):\n", " for j in range(len(majs)):\n", - " text = ax.text(i, j, f\"{query_rate[i, j]:.2f}\",\n", - " ha=\"center\", va=\"center\", color=\"w\")\n", - "fig.savefig(\"rpa_re_query_rate.png\", bbox_inches=\"tight\")\n", + " text = ax.text(i, j, f\"{query_rate[i, j]:.1f}\",\n", + " ha=\"center\", va=\"center\", color=\"w\" if i - j <= 2 else \"black\")\n", + "fig.savefig(\"rpa_re_query_rate.pdf\", bbox_inches=\"tight\")\n", "plt.show()" ] }, @@ -482,20 +542,309 @@ "source": [ "fig, ax = plt.subplots()\n", "im = ax.imshow(correct_rate.T, vmin=0, cmap=\"viridis\")\n", - "cbar_ax = fig.add_axes((0.90, 0.15, 0.04, 0.69))\n", + "cbar_ax = fig.add_axes((0.85, 0.15, 0.04, 0.69))\n", "cbar = fig.colorbar(im, cax=cbar_ax)\n", "cbar.ax.set_ylabel(\"Success rate\", rotation=-90, va=\"bottom\")\n", "cbar.ax.axhline(100 / len(multipliers), color=\"red\", linestyle=\"--\")\n", "\n", "ax.set_xticks(np.arange(len(errs)), labels=errs)\n", "ax.set_yticks(np.arange(len(majs)), labels=reversed(majs))\n", - "ax.set_xlabel(\"err\")\n", - "ax.set_ylabel(\"majority\")\n", + "ax.set_xlabel(\"error probability\")\n", + "ax.set_ylabel(\"majority vote\")\n", "for i in range(len(errs)):\n", " for j in range(len(majs)):\n", - " text = ax.text(i, j, f\"{correct_rate[i, j]:.2f}%\",\n", - " ha=\"center\", va=\"center\", color=\"w\")\n", - "fig.savefig(\"rpa_re_success_rate.png\", bbox_inches=\"tight\")\n", + " c_rate = correct_rate[i, j]\n", + " text = ax.text(i, j, f\"{c_rate:.1f}%\",\n", + " ha=\"center\", va=\"center\", color=\"w\" if c_rate < 80 else \"black\")\n", + "fig.savefig(\"rpa_re_success_rate.pdf\", bbox_inches=\"tight\")\n", + "plt.show()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "56114e99-e949-488f-85bb-f6bd2e221d39", + "metadata": {}, + "outputs": [], + "source": [ + "fig, ax = plt.subplots()\n", + "im = ax.imshow(precise_rate.T, vmin=0, cmap=\"viridis\")\n", + "cbar_ax = fig.add_axes((0.85, 0.15, 0.04, 0.69))\n", + "cbar = fig.colorbar(im, cax=cbar_ax)\n", + "cbar.ax.set_ylabel(\"Precision\", rotation=-90, va=\"bottom\")\n", + "\n", + "ax.set_xticks(np.arange(len(errs)), labels=errs)\n", + "ax.set_yticks(np.arange(len(majs)), labels=reversed(majs))\n", + "ax.set_xlabel(\"error probability\")\n", + "ax.set_ylabel(\"majority vote\")\n", + "for i in range(len(errs)):\n", + " for j in range(len(majs)):\n", + " p_rate = precise_rate[i, j]\n", + " text = ax.text(i, j, f\"{p_rate:.1f}%\",\n", + " ha=\"center\", va=\"center\", color=\"w\" if p_rate < 80 else \"black\")\n", + "fig.savefig(\"rpa_re_precision.pdf\", bbox_inches=\"tight\")\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "id": "b8eeb49e-7734-4fda-bf28-ac39f6c8a626", + "metadata": {}, + "source": [ + "Another way to look at these metrics is a scatter plot." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1e1b1769-6aa9-4b95-a7b7-dd5cfd501d27", + "metadata": {}, + "outputs": [], + "source": [ + "fig, ax = plt.subplots()\n", + "ax.grid()\n", + "for i, err in enumerate(errs):\n", + " qrs = query_rate[i, :]\n", + " crs = correct_rate[i, :]\n", + " ax.scatter(qrs, crs, label=f\"error = {err}\")\n", + "ax.set_xlabel(\"oracle queries\")\n", + "ax.set_ylabel(\"success rate\")\n", + "ax.legend()\n", + "fig.savefig(\"rpa_re_scatter.pdf\", bbox_inches=\"tight\")\n", + "plt.show()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "921b1c7b-fd40-415e-b737-1a85e07a9ba5", + "metadata": {}, + "outputs": [], + "source": [ + "fig, ax = plt.subplots()\n", + "for i, err in enumerate(errs):\n", + " crs = correct_rate[i, :]\n", + " ax.plot(list(reversed(majs)), crs, label=f\"error = {err}\")\n", + "ax.set_xlabel(\"majority vote\")\n", + "ax.set_ylabel(\"success rate\")\n", + "ax.set_xticks(majs)\n", + "ax.legend()\n", + "fig.savefig(\"rpa_re_plot.pdf\", bbox_inches=\"tight\")\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "id": "e3981f44-ed3b-43f5-b4bd-e2d4b2ff95e8", + "metadata": {}, + "source": [ + "#### What about (asymmetric) noise?" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "40652fa3-39f9-47ad-9424-ee2fdaac78d3", + "metadata": {}, + "outputs": [], + "source": [ + "correct_tries_b = np.zeros((len(errs), len(errs), len(majs)))\n", + "precise_tries_b = np.zeros((len(errs), len(errs), len(majs)))\n", + "query_tries_b = np.zeros((len(errs), len(errs), len(majs)))\n", + "total_tries_b = 0\n", + "\n", + "num_tries_b = 100" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d6dce31a-1369-4556-8e01-4e19ad14d21e", + "metadata": {}, + "outputs": [], + "source": [ + "num_cores = 30\n", + "\n", + "def measure_mult(params, multipliers, simulated_oracle, i, mult, err_0, err_1, majority):\n", + " correct = 0\n", + " precise = 0\n", + " calls = 0\n", + " p = lru_cache(maxsize=2)(partial(simulated_oracle, simulate_mult_id=i))\n", + " biased = biased_oracle(p, flip_0=err_0, flip_1=err_1)\n", + " def oracle(scalar, affine_point):\n", + " nonlocal calls\n", + " calls += 1\n", + " return biased(scalar, affine_point)\n", + " for j in range(num_tries_b):\n", + " res = rpa_distinguish(params, multipliers, oracle, majority=majority)\n", + " if mult in res:\n", + " correct += 1\n", + " if len(res) == 1:\n", + " precise += 1\n", + " return correct, precise, calls\n", + "\n", + "with TemporaryConfig() as cfg:\n", + " cfg.log.enabled = False\n", + " with ProcessPoolExecutor(max_workers=num_cores) as pool:\n", + " futures = []\n", + " args = []\n", + " for i, mult in enumerate(multipliers):\n", + " for err_0 in errs:\n", + " for err_1 in errs:\n", + " for majority in majs:\n", + " a = (params, multipliers, simulated_oracle, i, mult, err_0, err_1, majority)\n", + " futures.append(pool.submit(measure_mult, *a))\n", + " args.append(a)\n", + " results = [None for _ in futures]\n", + " for future in tqdm(as_completed(futures), total=len(futures), smoothing=0):\n", + " j = futures.index(future)\n", + " a = args[j]\n", + " results[j] = future.result()" + ] + }, + { + "cell_type": "markdown", + "id": "f4ddde62-18bb-46b2-a2e2-565cc21d654f", + "metadata": {}, + "source": [ + "Now we accumulate the results across the error rate and majority vote parameters." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "20b9ac29-401f-4068-8b2a-4b2f14e14b28", + "metadata": {}, + "outputs": [], + "source": [ + "for a, result in zip(args, results):\n", + " i = errs.index(a[5])\n", + " j = errs.index(a[6])\n", + " k = majs.index(a[7])\n", + " correct_tries_b[i, j, k] += result[0]\n", + " precise_tries_b[i, j, k] += result[1]\n", + " query_tries_b[i, j, k] += result[2]\n", + "total_tries_b += num_tries_b\n", + "\n", + "correct_rate_b = (correct_tries_b * 100) / (total_tries_b * len(multipliers))\n", + "precise_rate_b = (precise_tries_b * 100) / (total_tries_b * len(multipliers))\n", + "query_rate_b = query_tries_b / (total_tries_b * len(multipliers))" + ] + }, + { + "cell_type": "markdown", + "id": "67a6bba8-84e8-48f1-9b3b-b0b8715c71a6", + "metadata": {}, + "source": [ + "And save the results for later." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "85933a5e-f526-4002-9203-0e4ae4f731d0", + "metadata": {}, + "outputs": [], + "source": [ + "np.save(\"rpa_re_correct_rate_b\", correct_rate_b)\n", + "np.save(\"rpa_re_precise_rate_b\", precise_rate_b)\n", + "np.save(\"rpa_re_query_rate_b\", query_rate_b)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5fd78523-0463-4932-ae64-42a444104d2c", + "metadata": {}, + "outputs": [], + "source": [ + "fig, axs = plt.subplots(nrows=2, ncols=3, sharex=\"col\", sharey=\"row\")\n", + "vmin = np.min(query_rate_b)\n", + "vmax = np.max(query_rate_b)\n", + "\n", + "for row in range(2):\n", + " for col in range(3):\n", + " ax = axs[row, col]\n", + " level = row * 3 + col\n", + " im = ax.imshow(query_rate_b[::-1,:,level], cmap=\"plasma\", vmin=vmin, vmax=vmax)\n", + " ax.set_xticks(np.arange(len(errs)), labels=errs)\n", + " ax.set_yticks(np.arange(len(errs)), labels=list(reversed(errs)))\n", + " for i in range(len(errs)):\n", + " for j in range(len(errs)):\n", + " q_rate = f\"{query_rate_b[i, len(errs) - j - 1, level]:.0f}\"\n", + " loc = f\"{errs[i]} {errs[j]}\"\n", + " text = ax.text(i, j, q_rate, ha=\"center\", va=\"center\")\n", + " ax.set_xlabel(\"$e_1$\")\n", + " ax.set_ylabel(\"$e_O$\")\n", + " ax.set_title(majs[level])\n", + "fig.set_size_inches((10,6))\n", + "fig.tight_layout(h_pad=1.5, rect=(0, 0, 0.9, 1))\n", + "cbar_ax = fig.add_axes((0.9, 0.10, 0.02, 0.84))\n", + "cbar = fig.colorbar(im, cax=cbar_ax)\n", + "cbar.ax.set_ylabel(\"Oracle query rate\", rotation=-90, va=\"bottom\")\n", + "fig.savefig(\"rpa_re_asymmetric_query_rate.pdf\")\n", + "plt.show()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6b976938-f10d-439b-83b2-94d20d00ecbc", + "metadata": {}, + "outputs": [], + "source": [ + "fig, axs = plt.subplots(nrows=2, ncols=3, sharex=\"col\", sharey=\"row\")\n", + "for row in range(2):\n", + " for col in range(3):\n", + " ax = axs[row, col]\n", + " level = row * 3 + col\n", + " im = ax.imshow(correct_rate_b[::-1,:,level], cmap=\"viridis\", vmin=0, vmax=100)\n", + " ax.set_xticks(np.arange(len(errs)), labels=errs)\n", + " ax.set_yticks(np.arange(len(errs)), labels=list(reversed(errs)))\n", + " for i in range(len(errs)):\n", + " for j in range(len(errs)):\n", + " c = correct_rate_b[i, len(errs) - j - 1, level]\n", + " c_rate = f\"{c:.0f}%\"\n", + " loc = f\"{errs[i]} {errs[j]}\"\n", + " text = ax.text(i, j, c_rate, ha=\"center\", va=\"center\", color=\"w\" if c < 50 else \"black\")\n", + " ax.set_xlabel(\"$e_1$\")\n", + " ax.set_ylabel(\"$e_O$\")\n", + " ax.set_title(majs[level])\n", + "fig.set_size_inches((10,6))\n", + "fig.tight_layout(h_pad=1.5, rect=(0, 0, 0.9, 1))\n", + "cbar_ax = fig.add_axes((0.9, 0.10, 0.02, 0.84))\n", + "cbar = fig.colorbar(im, cax=cbar_ax)\n", + "cbar.ax.set_ylabel(\"Success rate\", rotation=-90, va=\"bottom\")\n", + "cbar.ax.axhline(100 / len(multipliers), color=\"red\", linestyle=\"--\")\n", + "fig.savefig(\"rpa_re_asymmetric_success_rate.pdf\")\n", + "plt.show()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "868c4a7a-5c0f-4ee6-9a1a-2c251dfae34c", + "metadata": {}, + "outputs": [], + "source": [ + "fig, ax = plt.subplots()\n", + "ax.grid()\n", + "crs_accumulated = {}\n", + "for i, err_0 in enumerate(errs):\n", + " for j, err_1 in enumerate(errs):\n", + " crs = correct_rate_b[i, j, :]\n", + " total_err = round(err_0 + err_1, 1)\n", + " l = crs_accumulated.setdefault(total_err, [])\n", + " l.append(crs)\n", + " #ax.scatter(majs, crs, label=str(err_0 + err_1))\n", + "for total_err in crs_accumulated.keys():\n", + " crs = np.mean(crs_accumulated[total_err], axis=0)\n", + " ax.plot(majs, crs, label=f\"total_error = {total_err}\")\n", + "ax.set_xticks(majs)\n", + "ax.set_xlabel(\"majority\")\n", + "ax.set_ylabel(\"success rate\")\n", + "ax.legend(bbox_to_anchor=(1, 1.02))\n", + "fig.tight_layout()\n", "plt.show()" ] }, @@ -569,7 +918,7 @@ "table = [[\"True multiplier\", \"Reversed\", \"Correct\", \"Remaining\"]]\n", "with TemporaryConfig() as cfg:\n", " cfg.log.enabled = False\n", - " for i, mult in tqdm(enumerate(multipliers)):\n", + " for i, mult in tqdm(enumerate(multipliers), total=len(multipliers)):\n", " res = rpa_distinguish(params, multipliers, partial(simulated_rpa_oracle, simulate_mult_id = i))\n", " table.append([mult, res, mult in res, len(res)])\n", "display(HTML(tabulate.tabulate(table, tablefmt=\"html\", headers=\"firstrow\")))" @@ -591,14 +940,14 @@ "outputs": [], "source": [ "diff_real = normalize(simulated_rpa_trace(multipliers[0], scalar, P0_target.to_affine(), NormalNoice(0, 1)))\n", - "diff_nothing = normalize(simulated_rpa_trace(multipliers[5], scalar, P0_target.to_affine(), NormalNoice(0, 1)))\n", + "diff_nothing = normalize(simulated_rpa_trace(multipliers[7], scalar, P0_target.to_affine(), NormalNoice(0, 1)))\n", "plot_traces(diff_real, diff_nothing).opts(responsive=True, height=600)" ] }, { "cell_type": "code", "execution_count": null, - "id": "efea0ab4-1745-4a13-87fa-501f35cbe903", + "id": "9dc922b4-3123-489f-98e2-4c20f1d65816", "metadata": {}, "outputs": [], "source": [] @@ -620,7 +969,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.5" + "version": "3.11.4" } }, "nbformat": 4, |
