-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create KaliskiModInverse * format * change signature * free * use half comp * Add documentation * nit * address comments * type * update classical action * nit --------- Co-authored-by: Matthew Harrigan <[email protected]>
- Loading branch information
1 parent
7c6715b
commit b3e0748
Showing
8 changed files
with
934 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "1c5f2b28", | ||
"metadata": { | ||
"cq.autogen": "title_cell" | ||
}, | ||
"source": [ | ||
"# Modular Divison" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "8751aa36", | ||
"metadata": { | ||
"cq.autogen": "top_imports" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"from qualtran import Bloq, CompositeBloq, BloqBuilder, Signature, Register\n", | ||
"from qualtran import QBit, QInt, QUInt, QAny\n", | ||
"from qualtran.drawing import show_bloq, show_call_graph, show_counts_sigma\n", | ||
"from typing import *\n", | ||
"import numpy as np\n", | ||
"import sympy\n", | ||
"import cirq" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "d680443c", | ||
"metadata": { | ||
"cq.autogen": "KaliskiModInverse.bloq_doc.md" | ||
}, | ||
"source": [ | ||
"## `KaliskiModInverse`\n", | ||
"Compute modular multiplicative inverse -inplace- of numbers in montgomery form.\n", | ||
"\n", | ||
"Applies the transformation\n", | ||
"$$\n", | ||
" \\ket{x} \\ket{0} \\rightarrow \\ket{x^{-1} 2^{2n} \\mod p} \\ket{\\mathrm{garbage}}\n", | ||
"$$\n", | ||
"\n", | ||
"#### Parameters\n", | ||
" - `bitsize`: size of the number.\n", | ||
" - `mod`: The integer modulus.\n", | ||
" - `uncompute`: whether to compute or uncompute. \n", | ||
"\n", | ||
"#### Registers\n", | ||
" - `x`: The register for which we compute the multiplicative inverse.\n", | ||
" - `m`: A 2*bitsize register of intermediate values needed for uncomputation. \n", | ||
"\n", | ||
"#### References\n", | ||
" - [Performance Analysis of a Repetition Cat Code Architecture: Computing 256-bit Elliptic Curve Logarithm in 9 Hours with 126 133 Cat Qubits](https://arxiv.org/abs/2302.06639). Appendix C5.\n", | ||
" - [Improved quantum circuits for elliptic curve discrete logarithms](https://arxiv.org/abs/2001.09580). Fig 7(b)\n", | ||
" - [How to compute a 256-bit elliptic curve private key with only 50 million Toffoli gates](https://arxiv.org/abs/2306.08585). page 8.\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "f5917d72", | ||
"metadata": { | ||
"cq.autogen": "KaliskiModInverse.bloq_doc.py" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"from qualtran.bloqs.mod_arithmetic import KaliskiModInverse" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "d44329eb", | ||
"metadata": { | ||
"cq.autogen": "KaliskiModInverse.example_instances.md" | ||
}, | ||
"source": [ | ||
"### Example Instances" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "31a37cf6", | ||
"metadata": { | ||
"cq.autogen": "KaliskiModInverse.kaliskimodinverse_example" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"kaliskimodinverse_example = KaliskiModInverse(32, 10**9 + 7)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "58c697e6", | ||
"metadata": { | ||
"cq.autogen": "KaliskiModInverse.kaliskimodinverse_symbolic" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"n, p = sympy.symbols('n p')\n", | ||
"kaliskimodinverse_symbolic = KaliskiModInverse(n, p)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "9bf1e17c", | ||
"metadata": { | ||
"cq.autogen": "KaliskiModInverse.graphical_signature.md" | ||
}, | ||
"source": [ | ||
"#### Graphical Signature" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "eca3a706", | ||
"metadata": { | ||
"cq.autogen": "KaliskiModInverse.graphical_signature.py" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"from qualtran.drawing import show_bloqs\n", | ||
"show_bloqs([kaliskimodinverse_example, kaliskimodinverse_symbolic],\n", | ||
" ['`kaliskimodinverse_example`', '`kaliskimodinverse_symbolic`'])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "69fd8906", | ||
"metadata": { | ||
"cq.autogen": "KaliskiModInverse.call_graph.md" | ||
}, | ||
"source": [ | ||
"### Call Graph" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "15c6fabe", | ||
"metadata": { | ||
"cq.autogen": "KaliskiModInverse.call_graph.py" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"from qualtran.resource_counting.generalizers import ignore_split_join\n", | ||
"kaliskimodinverse_example_g, kaliskimodinverse_example_sigma = kaliskimodinverse_example.call_graph(max_depth=1, generalizer=ignore_split_join)\n", | ||
"show_call_graph(kaliskimodinverse_example_g)\n", | ||
"show_counts_sigma(kaliskimodinverse_example_sigma)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"name": "python" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
Oops, something went wrong.