-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
GF2Multiplication
bloq for multiplication over GF($2^m$) (#1436)
* Add GF2Multiplication for multiplication over GF(2^m) * Fix formatting * Address nits
- Loading branch information
1 parent
6036ad7
commit 14e6fe7
Showing
9 changed files
with
495 additions
and
2 deletions.
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,15 @@ | ||
# Copyright 2024 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from qualtran.bloqs.gf_arithmetic.gf2_multiplication import GF2Multiplication |
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,182 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "87c95c4a", | ||
"metadata": { | ||
"cq.autogen": "title_cell" | ||
}, | ||
"source": [ | ||
"# GF($2^m$) Multiplication" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "31c1f087", | ||
"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": "307679ec", | ||
"metadata": { | ||
"cq.autogen": "GF2Multiplication.bloq_doc.md" | ||
}, | ||
"source": [ | ||
"## `GF2Multiplication`\n", | ||
"Out of place multiplication over GF($2^m$).\n", | ||
"\n", | ||
"The bloq implements out of place multiplication of two quantum registers storing elements\n", | ||
"from GF($2^m$) using construction described in Ref[1], which extends the classical construction\n", | ||
"of Ref[2].\n", | ||
"\n", | ||
"To multiply two m-bit inputs $a = [a_0, a_1, ..., a_{m-1}]$ and $b = [b_0, b_1, ..., b_{m-1}]$,\n", | ||
"the construction computes the output vector $c$ via the following three steps:\n", | ||
" 1. Compute $e = U.b$ where $U$ is an upper triangular matrix constructed using $a$.\n", | ||
" 2. Compute $Q.e$ where $Q$ is an $m \\times (m - 1)$ reduction matrix that depends upon the\n", | ||
" irreducible polynomial $P(x)$ of the galois field $GF(2^m)$. The i'th column of the\n", | ||
" matrix corresponds to coefficients of the polynomial $x^{m + i} % P(x)$. This matrix $Q$\n", | ||
" is a linear reversible circuit that can be implemented only using CNOT gates.\n", | ||
" 3. Compute $d = L.b$ where $L$ is a lower triangular matrix constructed using $a$.\n", | ||
" 4. Compute $c = d + Q.e$ to obtain the final product.\n", | ||
"\n", | ||
"Steps 1 and 3 are performed using $n^2$ Toffoli gates and step 2 is performed only using CNOT\n", | ||
"gates.\n", | ||
"\n", | ||
"#### Parameters\n", | ||
" - `bitsize`: The degree $m$ of the galois field $GF(2^m)$. Also corresponds to the number of qubits in each of the two input registers $a$ and $b$ that should be multiplied. \n", | ||
"\n", | ||
"#### Registers\n", | ||
" - `x`: Input THRU register of size $m$ that stores elements from $GF(2^m)$.\n", | ||
" - `y`: Input THRU register of size $m$ that stores elements from $GF(2^m)$.\n", | ||
" - `result`: Output RIGHT register of size $m$ that stores the product $x * y$ in $GF(2^m)$. \n", | ||
"\n", | ||
"#### References\n", | ||
" - [On the Design and Optimization of a Quantum Polynomial-Time Attack on Elliptic Curve Cryptography](https://arxiv.org/abs/0710.1093). \n", | ||
" - [Low complexity bit parallel architectures for polynomial basis multiplication over GF(2m)](https://ieeexplore.ieee.org/abstract/document/1306989). \n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "872a44d1", | ||
"metadata": { | ||
"cq.autogen": "GF2Multiplication.bloq_doc.py" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"from qualtran.bloqs.gf_arithmetic import GF2Multiplication" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "d0f0db7d", | ||
"metadata": { | ||
"cq.autogen": "GF2Multiplication.example_instances.md" | ||
}, | ||
"source": [ | ||
"### Example Instances" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "131bc962", | ||
"metadata": { | ||
"cq.autogen": "GF2Multiplication.gf16_multiplication" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"gf16_multiplication = GF2Multiplication(4)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "69f564d8", | ||
"metadata": { | ||
"cq.autogen": "GF2Multiplication.gf2_multiplication_symbolic" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import sympy\n", | ||
"\n", | ||
"m = sympy.Symbol('m')\n", | ||
"gf2_multiplication_symbolic = GF2Multiplication(m)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "2a62c2b8", | ||
"metadata": { | ||
"cq.autogen": "GF2Multiplication.graphical_signature.md" | ||
}, | ||
"source": [ | ||
"#### Graphical Signature" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "cf003e98", | ||
"metadata": { | ||
"cq.autogen": "GF2Multiplication.graphical_signature.py" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"from qualtran.drawing import show_bloqs\n", | ||
"show_bloqs([gf16_multiplication, gf2_multiplication_symbolic],\n", | ||
" ['`gf16_multiplication`', '`gf2_multiplication_symbolic`'])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "f14ef0c5", | ||
"metadata": { | ||
"cq.autogen": "GF2Multiplication.call_graph.md" | ||
}, | ||
"source": [ | ||
"### Call Graph" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "f4b7bf2c", | ||
"metadata": { | ||
"cq.autogen": "GF2Multiplication.call_graph.py" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"from qualtran.resource_counting.generalizers import ignore_split_join\n", | ||
"gf16_multiplication_g, gf16_multiplication_sigma = gf16_multiplication.call_graph(max_depth=1, generalizer=ignore_split_join)\n", | ||
"show_call_graph(gf16_multiplication_g)\n", | ||
"show_counts_sigma(gf16_multiplication_sigma)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"name": "python" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
Oops, something went wrong.