Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
d4d6cd1
Addition gate.
fdmalone Apr 26, 2023
9aef9a1
Add basic arithmetic bloqs.
fdmalone Apr 28, 2023
c64189a
More basic bloqs.
fdmalone May 1, 2023
e4e0a19
Rename arthmetic_bloqs -> arithmetic.
fdmalone May 5, 2023
9f41298
Tidy + tests.
fdmalone May 5, 2023
14254d2
More Bloqs.
fdmalone May 5, 2023
d1e37ec
Add test.
fdmalone May 5, 2023
f067dda
Add notebooks + more tests.
fdmalone May 5, 2023
b48e148
Fix references + notebook.
fdmalone May 5, 2023
f277b20
Sorting notebook.
fdmalone May 5, 2023
0882c05
Fix errors.
fdmalone May 5, 2023
13bf6f9
Fix lint error.
fdmalone May 5, 2023
072d8ae
Fix import order.
fdmalone May 5, 2023
734cf83
Fix formatting.
fdmalone May 8, 2023
cefc997
Merge branch 'main' into bloqs_primitives
fdmalone May 8, 2023
8848dbb
Remove imports from init.
fdmalone May 8, 2023
d311a57
Update cirq_qubitization/bloq_algos/arithmetic.py
fdmalone May 9, 2023
1205396
Update nbits -> bitsize + typos.
fdmalone May 9, 2023
c263e55
Add short_name method for sorting bloqs.
fdmalone May 9, 2023
ce90dfe
Add issue comments.
fdmalone May 10, 2023
d9bc84d
Merge branch 'bloqs_primitives' of github.com:quantumlib/cirq-qubitiz…
fdmalone May 10, 2023
dc2d759
Working on registers.
fdmalone May 10, 2023
7eedf54
Use multidimensional registers.
fdmalone May 10, 2023
2472f27
Fix test.
fdmalone May 10, 2023
aa2641b
Remove pretty_name.
fdmalone May 10, 2023
eec9dfa
Clear outputs.
fdmalone May 10, 2023
1458d2e
Address more review comments.
fdmalone May 10, 2023
c3583b9
Add rotation gate unit tests.
fdmalone May 10, 2023
bfdcacb
Add rotation gates to __init__.
fdmalone May 10, 2023
3755078
Address review comments.
fdmalone May 10, 2023
36ef97b
Upadate notebook.
fdmalone May 10, 2023
960a75c
Fix sum of squares unit test.
fdmalone May 10, 2023
b146ac5
Fix formatting.
fdmalone May 10, 2023
9509804
Remove unused imports.
fdmalone May 10, 2023
d031e46
Fix some docstrings.
fdmalone May 10, 2023
f227b70
Fix unit test.
fdmalone May 10, 2023
02e6e86
Fix notebooks.
fdmalone May 10, 2023
4f6dbd2
Add SelectionRegisters and multi-indexed versions of `SelectedMajoran…
tanujkhattar May 9, 2023
e35d41e
Remove debug code.
fdmalone May 10, 2023
44a800a
Merge branch 'main' into bloqs_primitives
fdmalone May 10, 2023
6e7b0b8
Merge branch 'main' into bloqs_primitives
fdmalone May 30, 2023
3abb21c
Note book tests.
fdmalone May 30, 2023
3fda1a6
Merge branch 'main' into bloqs_primitives
mpharrigan Jun 2, 2023
0aa69ac
Merge branch 'main' into bloqs_primitives
mpharrigan Jun 20, 2023
58e3b47
fixes
mpharrigan Jun 20, 2023
87d7222
Fix jupyter imports.
fdmalone Jun 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cirq_qubitization/bloq_algos/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from . import and_bloq, basic_gates
from . import and_bloq, arithmetic, basic_gates, sorting
253 changes: 253 additions & 0 deletions cirq_qubitization/bloq_algos/arithmetic.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "40368a5b",
"metadata": {
"cq.autogen": "title_cell"
},
"source": [
"# Arithmetic"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "410926b9",
"metadata": {
"cq.autogen": "top_imports"
},
"outputs": [],
"source": [
"import cirq\n",
"import numpy as np\n",
"import cirq_qubitization\n",
"import cirq_ft\n",
"import cirq_ft.infra.testing as cq_testing\n",
"from cirq_qubitization.jupyter_tools import display_gate_and_compilation, show_bloq\n",
"from typing import *"
]
},
{
"cell_type": "markdown",
"id": "b92171ba",
"metadata": {
"cq.autogen": "_make_add.md"
},
"source": [
"## `Add`\n",
"An n-bit addition gate.\n",
"\n",
"Implements $U|a\\rangle|b\\rangle \\rightarrow |a\\rangle|a+b\\rangle$ using $4n - 4 T$ gates.\n",
"\n",
"#### Parameters\n",
" - `bitsize`: Number of bits used to represent each integer. Must be large enough to hold the result in the output register of a + b. \n",
"\n",
"Registers:\n",
" - a: A bitsize-sized input register (register a above).\n",
" - b: A bitsize-sized input/output register (register b above).\n",
"\n",
"#### References\n",
"[Halving the cost of quantum addition](https://arxiv.org/abs/1709.06648)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f930d4ff",
"metadata": {
"cq.autogen": "_make_add.py"
},
"outputs": [],
"source": [
"from cirq_qubitization.bloq_algos.arithmetic import Add\n",
"\n",
"bloq = Add(bitsize=4)\n",
"show_bloq(bloq)"
]
},
{
"cell_type": "markdown",
"id": "3b20c805",
"metadata": {
"cq.autogen": "_make_product.md"
},
"source": [
"## `Product`\n",
"Compute the product of an `n` and `m` bit integer.\n",
"\n",
"Implements $U|a\\rangle|b\\rangle|0\\rangle -\\rightarrow\n",
"|a\\rangle|b\\rangle|a\\times b\\rangle$ using $2nm-n$ Toffolis.\n",
"\n",
"#### Parameters\n",
" - `a_bitsize`: Number of bits used to represent the first integer.\n",
" - `b_bitsize`: Number of bits used to represent the second integer. \n",
"\n",
"Registers:\n",
" - a: a_bitsize-sized input register.\n",
" - b: b_bitsize-sized input register.\n",
" - result: A 2*max(a_bitsize, b_bitsize) bit-sized output register to store\n",
" the result a*b.\n",
"\n",
"#### References\n",
"[Fault-Tolerant Quantum Simulations of Chemistry in First Quantization](https://arxiv.org/abs/2105.12767) pg 81 gives a Toffoli complexity for multiplying two numbers.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "877b583b",
"metadata": {
"cq.autogen": "_make_product.py"
},
"outputs": [],
"source": [
"from cirq_qubitization.bloq_algos.arithmetic import Product\n",
"\n",
"bloq = Product(a_bitsize=4, b_bitsize=6)\n",
"show_bloq(bloq)"
]
},
{
"cell_type": "markdown",
"id": "f50caf16",
"metadata": {
"cq.autogen": "_make_square.md"
},
"source": [
"## `Square`\n",
"Square an n-bit number.\n",
"\n",
"Implements $U|a\\rangle|0\\rangle \\rightarrow |a\\rangle|a^2\\rangle$ using $4n - 4 T$ gates.\n",
"\n",
"#### Parameters\n",
" - `bitsize`: Number of bits used to represent the integer to be squared. The result is stored in a register of size 2*bitsize. \n",
"\n",
"Registers:\n",
" - a: A bitsize-sized input register (register a above).\n",
" - result: A 2-bitsize-sized input/ouput register.\n",
"\n",
"#### References\n",
"[Fault-Tolerant Quantum Simulations of Chemistry in First Quantization](https://arxiv.org/abs/2105.12767). pg 76 for Toffoli complexity.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "633eb3ba",
"metadata": {
"cq.autogen": "_make_square.py"
},
"outputs": [],
"source": [
"from cirq_qubitization.bloq_algos.arithmetic import Square\n",
"\n",
"bloq = Square(bitsize=8)\n",
"show_bloq(bloq)"
]
},
{
"cell_type": "markdown",
"id": "18e2cca7",
"metadata": {
"cq.autogen": "_make_sum_of_squares.md"
},
"source": [
"## `SumOfSquares`\n",
"Compute the sum of squares of k n-bit numbers.\n",
"\n",
"Implements $U|a\\rangle|b\\rangle\\dots k\\rangle|0\\rangle \\rightarrow\n",
" |a\\rangle|b\\rangle\\dots|k\\rangle|a^2+b^2+\\dots k^2\\rangle$ using\n",
" $4 k n^2 T$ gates.\n",
"\n",
"#### Parameters\n",
" - `bitsize`: Number of bits used to represent each of the k integers.\n",
" - `k`: The number of integers we want to square. \n",
"\n",
"Registers:\n",
" - input: k n-bit registers.\n",
" - result: 2 * bitsize + 1 sized output register.\n",
"\n",
"#### References\n",
"[Fault-Tolerant Quantum Simulations of Chemistry in First Quantization](https://arxiv.org/abs/2105.12767) pg 80 give a Toffoli complexity for squaring.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "95d0069d",
"metadata": {
"cq.autogen": "_make_sum_of_squares.py"
},
"outputs": [],
"source": [
"from cirq_qubitization.bloq_algos.arithmetic import SumOfSquares\n",
"\n",
"bloq = SumOfSquares(bitsize=8, k=4)\n",
"show_bloq(bloq)"
]
},
{
"cell_type": "markdown",
"id": "20639a7a",
"metadata": {
"cq.autogen": "_make_greater_than.md"
},
"source": [
"## `GreaterThan`\n",
"Compare two n-bit integers.\n",
"\n",
"Implements $U|a\\rangle|b\\rangle|0\\rangle \\rightarrow\n",
"|a\\rangle|b\\rangle|a > b\\rangle$ using $8n T$ gates.\n",
"\n",
"\n",
"#### Parameters\n",
" - `bitsize`: Number of bits used to represent the two integers a and b. \n",
"\n",
"Registers:\n",
" - a: n-bit-sized input registers.\n",
" - b: n-bit-sized input registers.\n",
" - result: A single bit output register to store the result of A > B.\n",
"\n",
"#### References\n",
"[Improved techniques for preparing eigenstates of fermionic Hamiltonians](https://www.nature.com/articles/s41534-018-0071-5#additional-information), Comparison Oracle from SI: Appendix 2B (pg 3)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "af66690c",
"metadata": {
"cq.autogen": "_make_greater_than.py"
},
"outputs": [],
"source": [
"from cirq_qubitization.bloq_algos.arithmetic import GreaterThan\n",
"\n",
"bloq = GreaterThan(bitsize=4)\n",
"show_bloq(bloq)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.10.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading