-
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.
- Loading branch information
1 parent
28487f6
commit ec85731
Showing
7 changed files
with
303 additions
and
163 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,163 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "064ac84d", | ||
"metadata": { | ||
"cq.autogen": "title_cell" | ||
}, | ||
"source": [ | ||
"# Controlled Addition" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "a283d3fb", | ||
"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": "d85b6f41", | ||
"metadata": { | ||
"cq.autogen": "CAdd.bloq_doc.md" | ||
}, | ||
"source": [ | ||
"## `CAdd`\n", | ||
"An n-bit controlled-addition gate.\n", | ||
"\n", | ||
"#### Parameters\n", | ||
" - `a_dtype`: Quantum datatype used to represent the integer a.\n", | ||
" - `b_dtype`: Quantum datatype used to represent the integer b. Must be large enough to hold the result in the output register of a + b, or else it simply drops the most significant bits. If not specified, b_dtype is set to a_dtype.\n", | ||
" - `cv`: When controlled=0, this bloq is active when the ctrl register is 0. When controlled=1, this bloq is active when the ctrl register is 1. \n", | ||
"\n", | ||
"#### Registers\n", | ||
" - `ctrl`: the control bit for the addition\n", | ||
" - `a`: A a_dtype.bitsize-sized input register (register a above).\n", | ||
" - `b`: A b_dtype.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": "1e441ac2", | ||
"metadata": { | ||
"cq.autogen": "CAdd.bloq_doc.py" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"from qualtran.bloqs.arithmetic import CAdd" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "801cf1e1", | ||
"metadata": { | ||
"cq.autogen": "CAdd.example_instances.md" | ||
}, | ||
"source": [ | ||
"### Example Instances" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "854ba572", | ||
"metadata": { | ||
"cq.autogen": "CAdd.cadd_small" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"cadd_small = CAdd(QUInt(3))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "0a4d89b2", | ||
"metadata": { | ||
"cq.autogen": "CAdd.cadd_large" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"cadd_large = CAdd(QUInt(1000), QUInt(1000))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "25c1ed97", | ||
"metadata": { | ||
"cq.autogen": "CAdd.graphical_signature.md" | ||
}, | ||
"source": [ | ||
"#### Graphical Signature" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "03b6c6a6", | ||
"metadata": { | ||
"cq.autogen": "CAdd.graphical_signature.py" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"from qualtran.drawing import show_bloqs\n", | ||
"show_bloqs([cadd_small, cadd_large],\n", | ||
" ['`cadd_small`', '`cadd_large`'])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "3bd7842e", | ||
"metadata": { | ||
"cq.autogen": "CAdd.call_graph.md" | ||
}, | ||
"source": [ | ||
"### Call Graph" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "80c50e8b", | ||
"metadata": { | ||
"cq.autogen": "CAdd.call_graph.py" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"from qualtran.resource_counting.generalizers import ignore_split_join\n", | ||
"cadd_small_g, cadd_small_sigma = cadd_small.call_graph(max_depth=1, generalizer=ignore_split_join)\n", | ||
"show_call_graph(cadd_small_g)\n", | ||
"show_counts_sigma(cadd_small_sigma)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"name": "python" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
Oops, something went wrong.