-
Notifications
You must be signed in to change notification settings - Fork 100
Bloqs arithmetic and sorting #216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
d4d6cd1
Addition gate.
fdmalone 9aef9a1
Add basic arithmetic bloqs.
fdmalone c64189a
More basic bloqs.
fdmalone e4e0a19
Rename arthmetic_bloqs -> arithmetic.
fdmalone 9f41298
Tidy + tests.
fdmalone 14254d2
More Bloqs.
fdmalone d1e37ec
Add test.
fdmalone f067dda
Add notebooks + more tests.
fdmalone b48e148
Fix references + notebook.
fdmalone f277b20
Sorting notebook.
fdmalone 0882c05
Fix errors.
fdmalone 13bf6f9
Fix lint error.
fdmalone 072d8ae
Fix import order.
fdmalone 734cf83
Fix formatting.
fdmalone cefc997
Merge branch 'main' into bloqs_primitives
fdmalone 8848dbb
Remove imports from init.
fdmalone d311a57
Update cirq_qubitization/bloq_algos/arithmetic.py
fdmalone 1205396
Update nbits -> bitsize + typos.
fdmalone c263e55
Add short_name method for sorting bloqs.
fdmalone ce90dfe
Add issue comments.
fdmalone d9bc84d
Merge branch 'bloqs_primitives' of github.com:quantumlib/cirq-qubitiz…
fdmalone dc2d759
Working on registers.
fdmalone 7eedf54
Use multidimensional registers.
fdmalone 2472f27
Fix test.
fdmalone aa2641b
Remove pretty_name.
fdmalone eec9dfa
Clear outputs.
fdmalone 1458d2e
Address more review comments.
fdmalone c3583b9
Add rotation gate unit tests.
fdmalone bfdcacb
Add rotation gates to __init__.
fdmalone 3755078
Address review comments.
fdmalone 36ef97b
Upadate notebook.
fdmalone 960a75c
Fix sum of squares unit test.
fdmalone b146ac5
Fix formatting.
fdmalone 9509804
Remove unused imports.
fdmalone d031e46
Fix some docstrings.
fdmalone f227b70
Fix unit test.
fdmalone 02e6e86
Fix notebooks.
fdmalone 4f6dbd2
Add SelectionRegisters and multi-indexed versions of `SelectedMajoran…
tanujkhattar e35d41e
Remove debug code.
fdmalone 44a800a
Merge branch 'main' into bloqs_primitives
fdmalone 6e7b0b8
Merge branch 'main' into bloqs_primitives
fdmalone 3abb21c
Note book tests.
fdmalone 3fda1a6
Merge branch 'main' into bloqs_primitives
mpharrigan 0aa69ac
Merge branch 'main' into bloqs_primitives
mpharrigan 58e3b47
fixes
mpharrigan 87d7222
Fix jupyter imports.
fdmalone File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1 +1 @@ | ||
| from . import and_bloq, basic_gates | ||
| from . import and_bloq, arithmetic, basic_gates, sorting | ||
This file contains hidden or 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,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 | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.