Skip to content

Commit

Permalink
Add Product block encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesyuan314 committed Jul 2, 2024
1 parent 9514139 commit 9c7bacc
Show file tree
Hide file tree
Showing 8 changed files with 596 additions and 1 deletion.
1 change: 1 addition & 0 deletions dev_tools/autogenerate-bloqs-notebooks-v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@
qualtran.bloqs.block_encoding.chebyshev_polynomial._CHEBYSHEV_BLOQ_DOC,
qualtran.bloqs.block_encoding.unitary._UNITARY_DOC,
qualtran.bloqs.block_encoding.tensor_product._TENSOR_PRODUCT_DOC,
qualtran.bloqs.block_encoding.product._PRODUCT_DOC,
],
directory=f'{SOURCE_DIR}/bloqs/block_encoding/',
),
Expand Down
1 change: 1 addition & 0 deletions qualtran/bloqs/block_encoding/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
LCUBlockEncoding,
LCUBlockEncodingZeroState,
)
from qualtran.bloqs.block_encoding.product import Product
from qualtran.bloqs.block_encoding.tensor_product import TensorProduct
from qualtran.bloqs.block_encoding.unitary import Unitary
159 changes: 159 additions & 0 deletions qualtran/bloqs/block_encoding/block_encoding.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,165 @@
"show_call_graph(tensor_product_block_encoding_g)\n",
"show_counts_sigma(tensor_product_block_encoding_sigma)"
]
},
{
"cell_type": "markdown",
"id": "1127108b",
"metadata": {
"cq.autogen": "Product.bloq_doc.md"
},
"source": [
"## `Product`\n",
"Product of a sequence of block encodings.\n",
"\n",
"Builds the block encoding $B[U_1 * U_2 * \\cdots * U_n]$ given block encodings $B[U_1], \\ldots, B[U_n]$.\n",
"\n",
"When each $B[U_i]$ is a $(\\alpha_i, a_i, \\epsilon_i)$-block encoding of $U_i$, we have that\n",
"$B[U_1 * \\cdots * U_n]$ is a $(\\prod_i \\alpha_i, n - 1 + \\max_i a_i, \\sum_i \\alpha_i \\epsilon_i)$-block\n",
"encoding of $U_1 * \\cdots * U_n$.\n",
"\n",
"#### Parameters\n",
" - `block_encodings`: A sequence of block encodings. \n",
"\n",
"#### Registers\n",
" - `system`: The system register.\n",
" - `ancilla`: The ancilla register (present only if bitsize > 0).\n",
" - `resource`: The resource register (present only if bitsize > 0). \n",
"\n",
"#### References\n",
" - [Quantum algorithms: A survey of applications and end-to-end complexities](https://arxiv.org/abs/2310.03011). Dalzell et al. (2023). Ch. 10.2.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3643f471",
"metadata": {
"cq.autogen": "Product.bloq_doc.py"
},
"outputs": [],
"source": [
"from qualtran.bloqs.block_encoding import Product"
]
},
{
"cell_type": "markdown",
"id": "d37c3d81",
"metadata": {
"cq.autogen": "Product.example_instances.md"
},
"source": [
"### Example Instances"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "96a8d277",
"metadata": {
"cq.autogen": "Product.product_block_encoding"
},
"outputs": [],
"source": [
"from qualtran.bloqs.basic_gates import Hadamard, TGate\n",
"from qualtran.bloqs.block_encoding.unitary import Unitary\n",
"\n",
"product_block_encoding = Product((Unitary(TGate()), Unitary(Hadamard())))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "83b0468a",
"metadata": {
"cq.autogen": "Product.product_block_encoding_override"
},
"outputs": [],
"source": [
"from qualtran.bloqs.basic_gates import Hadamard, TGate\n",
"from qualtran.bloqs.block_encoding.unitary import Unitary\n",
"\n",
"u1 = evolve(Unitary(TGate()), alpha=0.5, ancilla_bitsize=2, resource_bitsize=1, epsilon=0.01)\n",
"u2 = evolve(Unitary(Hadamard()), alpha=0.5, ancilla_bitsize=1, resource_bitsize=1, epsilon=0.1)\n",
"product_block_encoding_override = Product((u1, u2))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "238b45e4",
"metadata": {
"cq.autogen": "Product.product_block_encoding_symb"
},
"outputs": [],
"source": [
"import sympy\n",
"\n",
"from qualtran.bloqs.basic_gates import Hadamard, TGate\n",
"from qualtran.bloqs.block_encoding.unitary import Unitary\n",
"\n",
"alpha1 = sympy.Symbol('alpha1')\n",
"a1 = sympy.Symbol('a1')\n",
"eps1 = sympy.Symbol('eps1')\n",
"alpha2 = sympy.Symbol('alpha2')\n",
"a2 = sympy.Symbol('a2')\n",
"eps2 = sympy.Symbol('eps2')\n",
"product_block_encoding_symb = Product(\n",
" (\n",
" Unitary(TGate(), alpha=alpha1, ancilla_bitsize=a1, epsilon=eps1),\n",
" Unitary(Hadamard(), alpha=alpha2, ancilla_bitsize=a2, epsilon=eps2),\n",
" )\n",
")"
]
},
{
"cell_type": "markdown",
"id": "598fe397",
"metadata": {
"cq.autogen": "Product.graphical_signature.md"
},
"source": [
"#### Graphical Signature"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5e28152f",
"metadata": {
"cq.autogen": "Product.graphical_signature.py"
},
"outputs": [],
"source": [
"from qualtran.drawing import show_bloqs\n",
"show_bloqs([product_block_encoding, product_block_encoding_override, product_block_encoding_symb],\n",
" ['`product_block_encoding`', '`product_block_encoding_override`', '`product_block_encoding_symb`'])"
]
},
{
"cell_type": "markdown",
"id": "d3175473",
"metadata": {
"cq.autogen": "Product.call_graph.md"
},
"source": [
"### Call Graph"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a5436f3e",
"metadata": {
"cq.autogen": "Product.call_graph.py"
},
"outputs": [],
"source": [
"from qualtran.resource_counting.generalizers import ignore_split_join\n",
"product_block_encoding_g, product_block_encoding_sigma = product_block_encoding.call_graph(max_depth=1, generalizer=ignore_split_join)\n",
"show_call_graph(product_block_encoding_g)\n",
"show_counts_sigma(product_block_encoding_sigma)"
]
}
],
"metadata": {
Expand Down
Loading

0 comments on commit 9c7bacc

Please sign in to comment.