microsoft/qdk

Public

mirrored fromhttps://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1365fba5cb78ce29bb89f92fea9c0419a3a85a14

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

samples/estimation/estimation-factoring.ipynb

101lines · modecode

1{
2 "cells": [
3 {
4 "cell_type": "markdown",
5 "metadata": {},
6 "source": [
7 "# Resource Estimation for Integer Factoring\n",
8 "\n",
9 "In this notebook we calculate resource estimates for a 2048-bit integer factoring application based on the implementation described in [[Quantum 5, 433 (2021)](https://quantum-journal.org/papers/q-2021-04-15-433/)]. Our implementation incorporates all techniques described in the paper, except for carry runways and semi-classical Fourier transform. As tolerated error budget, we choose $\\epsilon = 1/3$.\n",
10 "\n",
11 "We start by loading the Q# implementation of the algorithm."
12 ]
13 },
14 {
15 "cell_type": "code",
16 "execution_count": null,
17 "metadata": {},
18 "outputs": [],
19 "source": [
20 "import qsharp\n",
21 "from qsharp_widgets import EstimatesOverview\n",
22 "\n",
23 "with open(\"EkeraHastadFactoring.qs\", \"r\") as f:\n",
24 " qsharp.eval(f.read())"
25 ]
26 },
27 {
28 "cell_type": "markdown",
29 "metadata": {},
30 "source": [
31 "Here are some RSA integers to choose from, taken from this [extensive list](https://en.wikipedia.org/wiki/RSA_numbers#RSA-2048). Add and remove comments to pick the number you'd like to estimate, and feel free to add other numbers."
32 ]
33 },
34 {
35 "cell_type": "code",
36 "execution_count": null,
37 "metadata": {},
38 "outputs": [],
39 "source": [
40 "# RSA-100 (330 bits)\n",
41 "rsa_number = 1522605027922533360535618378132637429718068114961380688657908494580122963258952897654000350692006139\n",
42 "\n",
43 "# RSA-1024 (1024 bits)\n",
44 "# rsa_number = 135066410865995223349603216278805969938881475605667027524485143851526510604859533833940287150571909441798207282164471551373680419703964191743046496589274256239341020864383202110372958725762358509643110564073501508187510676594629205563685529475213500852879416377328533906109750544334999811150056977236890927563\n",
45 "\n",
46 "# RSA-2048 (2048 bits)\n",
47 "# rsa_number = 25195908475657893494027183240048398571429282126204032027777137836043662020707595556264018525880784406918290641249515082189298559149176184502808489120072844992687392807287776735971418347270261896375014971824691165077613379859095700097330459748808428401797429100642458691817195118746121515172654632282216869987549182422433637259085141865462043576798423387184774447920739934236584823824281198163815010674810451660377306056201619676256133844143603833904414952634432190114657544454178424020924616515723350778707749817125772467962926386356373289912154831438167899885040445364023527381951378636564391212010397122822120720357"
48 ]
49 },
50 {
51 "cell_type": "markdown",
52 "metadata": {},
53 "source": [
54 "Next, we estimate the resource estimates for all default qubit parameter configurations."
55 ]
56 },
57 {
58 "cell_type": "code",
59 "execution_count": null,
60 "metadata": {},
61 "outputs": [],
62 "source": [
63 "estimates = qsharp.estimate(f\"EkeraHastad({rsa_number.bit_length()}, {rsa_number}L, 7L)\", [\n",
64 " {\"errorBudget\": 0.333, \"qubitParams\": {\"name\": \"qubit_gate_ns_e3\"}},\n",
65 " {\"errorBudget\": 0.333, \"qubitParams\": {\"name\": \"qubit_gate_ns_e4\"}},\n",
66 " {\"errorBudget\": 0.333, \"qubitParams\": {\"name\": \"qubit_gate_us_e3\"}},\n",
67 " {\"errorBudget\": 0.333, \"qubitParams\": {\"name\": \"qubit_gate_us_e4\"}},\n",
68 " {\"errorBudget\": 0.333, \"qubitParams\": {\"name\": \"qubit_maj_ns_e4\"}, \"qecScheme\": {\"name\": \"floquet_code\"}},\n",
69 " {\"errorBudget\": 0.333, \"qubitParams\": {\"name\": \"qubit_maj_ns_e6\"}, \"qecScheme\": {\"name\": \"floquet_code\"}}\n",
70 "])"
71 ]
72 },
73 {
74 "cell_type": "markdown",
75 "metadata": {},
76 "source": [
77 "And finally, we present all resource estimates in an overview table and space-time plot."
78 ]
79 },
80 {
81 "cell_type": "code",
82 "execution_count": null,
83 "metadata": {},
84 "outputs": [],
85 "source": [
86 "EstimatesOverview(\n",
87 " estimates,\n",
88 " colors=[\"#1f77b4\", \"#ff7f0e\", \"blue\", \"red\", \"green\", \"yellow\"],\n",
89 " runNames=[\"Gate ns e3, surface\", \"Gate ns e4, surface\", \"Gate us e3, surface\", \"Gate us e4, surface\", \"Majorana ns e4, floquet\", \"Majorana ns e6, floquet\"]\n",
90 ")"
91 ]
92 }
93 ],
94 "metadata": {
95 "language_info": {
96 "name": "python"
97 }
98 },
99 "nbformat": 4,
100 "nbformat_minor": 4
101}
102