Skip to content
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

Add Product block encoding #1106

Merged
merged 9 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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 @@ -578,6 +578,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
175 changes: 175 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,181 @@
"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\n",
"$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 block encoding of $U_1 * \\cdots * U_n$ with normalization\n",
"constant $\\prod_i \\alpha_i$, ancilla bitsize $n - 1 + \\max_i a_i$, and precision\n",
"$\\sum_i \\alpha_i \\epsilon_i$.\n",
"\n",
"Following Fig. 2 in Dalzell et al. (2023), Ch. 10.2, the product is encoded by concatenating\n",
"each constituent block encoding, using a shared ancilla register and a set of flag qubits to\n",
"verify that the ancilla is left as zero after each use:\n",
"```\n",
" ┌────────┐\n",
" |0> ─┤ ├─ |0> ───────────X──────X────\n",
" │ │ │\n",
" │ U_(AB) │ = ┌─────┐ │ ┌─────┐\n",
" |0> ─┤ ├─ |0> ─┤ ├──(0)──┤ ├─\n",
" │ │ │ U_B │ │ U_A │\n",
"|Psi> ─┤ ├─ |Psi> ─┤ ├───────┤ ├─\n",
" └────────┘ └─────┘ └─────┘\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": "feefd8ac",
"metadata": {
"cq.autogen": "Product.example_instances.md"
},
"source": [
"### Example Instances"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1067eef2",
"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": "a3c9bef3",
"metadata": {
"cq.autogen": "Product.product_block_encoding_properties"
},
"outputs": [],
"source": [
"from qualtran.bloqs.basic_gates import Hadamard, TGate\n",
"from qualtran.bloqs.block_encoding.unitary import Unitary\n",
"\n",
"u1 = Unitary(TGate(), alpha=0.5, ancilla_bitsize=2, resource_bitsize=1, epsilon=0.01)\n",
"u2 = Unitary(Hadamard(), alpha=0.5, ancilla_bitsize=1, resource_bitsize=1, epsilon=0.1)\n",
"product_block_encoding_properties = Product((u1, u2))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a36f7cd9",
"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": "f372c55c",
"metadata": {
"cq.autogen": "Product.graphical_signature.md"
},
"source": [
"#### Graphical Signature"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "189c579f",
"metadata": {
"cq.autogen": "Product.graphical_signature.py"
},
"outputs": [],
"source": [
"from qualtran.drawing import show_bloqs\n",
"show_bloqs([product_block_encoding, product_block_encoding_properties, product_block_encoding_symb],\n",
" ['`product_block_encoding`', '`product_block_encoding_properties`', '`product_block_encoding_symb`'])"
]
},
{
"cell_type": "markdown",
"id": "442b1e19",
"metadata": {
"cq.autogen": "Product.call_graph.md"
},
"source": [
"### Call Graph"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "399ee3dd",
"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
Loading