Skip to content

Commit

Permalink
Merge branch 'main' into 2024/07/12-ctrl-spec-bloq
Browse files Browse the repository at this point in the history
  • Loading branch information
anurudhp authored Jul 17, 2024
2 parents 55d87c4 + cebe529 commit 2c190e1
Show file tree
Hide file tree
Showing 8 changed files with 677 additions and 1 deletion.
2 changes: 2 additions & 0 deletions dev_tools/autogenerate-bloqs-notebooks-v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import qualtran.bloqs.block_encoding.chebyshev_polynomial
import qualtran.bloqs.block_encoding.lcu_block_encoding
import qualtran.bloqs.block_encoding.lcu_select_and_prepare
import qualtran.bloqs.block_encoding.linear_combination
import qualtran.bloqs.block_encoding.phase
import qualtran.bloqs.bookkeeping
import qualtran.bloqs.chemistry.df.double_factorization
Expand Down Expand Up @@ -598,6 +599,7 @@
qualtran.bloqs.block_encoding.unitary._UNITARY_DOC,
qualtran.bloqs.block_encoding.tensor_product._TENSOR_PRODUCT_DOC,
qualtran.bloqs.block_encoding.product._PRODUCT_DOC,
qualtran.bloqs.block_encoding.linear_combination._LINEAR_COMBINATION_DOC,
qualtran.bloqs.block_encoding.phase._PHASE_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,6 +21,7 @@
LCUBlockEncoding,
LCUBlockEncodingZeroState,
)
from qualtran.bloqs.block_encoding.linear_combination import LinearCombination
from qualtran.bloqs.block_encoding.phase import Phase
from qualtran.bloqs.block_encoding.product import Product
from qualtran.bloqs.block_encoding.tensor_product import TensorProduct
Expand Down
129 changes: 129 additions & 0 deletions qualtran/bloqs/block_encoding/block_encoding.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,135 @@
"show_call_graph(phase_block_encoding_g)\n",
"show_counts_sigma(phase_block_encoding_sigma)"
]
},
{
"cell_type": "markdown",
"id": "5f9d88fa",
"metadata": {
"cq.autogen": "LinearCombination.bloq_doc.md"
},
"source": [
"## `LinearCombination`\n",
"Linear combination of a sequence of block encodings.\n",
"\n",
"Builds the block encoding $B[\\lambda_1 U_1 + \\lambda_2 U_2 + \\cdots + \\lambda_n U_n]$ given\n",
"block encodings $B[U_1], \\ldots, B[U_n]$ and coefficients $\\lambda_i \\in \\mathbb{R}$.\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[\\lambda_1 U_1 + \\cdots + \\lambda_n U_n]$ is a $(\\alpha, a, \\epsilon)$-block encoding\n",
"of $\\lambda_1 U_1 + \\cdots + \\lambda_n U_n$ where the normalization constant\n",
"$\\alpha = \\sum_i \\lvert\\lambda_i\\rvert\\alpha_i$, number of ancillas\n",
"$a = \\lceil \\log_2 n \\rceil + \\max_i a_i$, and precision\n",
"$\\epsilon = (\\sum_i \\lvert\\lambda_i\\rvert)\\max_i \\epsilon_i$.\n",
"\n",
"Under the hood, this bloq uses LCU Prepare and Select oracles to build the block encoding.\n",
"These oracles will be automatically instantiated if not specified by the user.\n",
"\n",
"#### Parameters\n",
" - `block_encodings`: A sequence of block encodings.\n",
" - `lambd`: Corresponding coefficients.\n",
" - `lambd_bits`: Number of bits needed to represent coefficients precisely.\n",
" - `prepare`: If specified, oracle preparing $\\sum_i \\sqrt{|\\lambda_i|} |i\\rangle$ (state should be normalized and can have junk).\n",
" - `select`: If specified, oracle taking $|i\\rangle|\\psi\\rangle \\mapsto \\text{sgn}(\\lambda_i) |i\\rangle U_i|\\psi\\rangle$. \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": "6e60f66d",
"metadata": {
"cq.autogen": "LinearCombination.bloq_doc.py"
},
"outputs": [],
"source": [
"from qualtran.bloqs.block_encoding import LinearCombination"
]
},
{
"cell_type": "markdown",
"id": "7c3b1b39",
"metadata": {
"cq.autogen": "LinearCombination.example_instances.md"
},
"source": [
"### Example Instances"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7048adb0",
"metadata": {
"cq.autogen": "LinearCombination.linear_combination_block_encoding"
},
"outputs": [],
"source": [
"from qualtran.bloqs.basic_gates import Hadamard, TGate, XGate, ZGate\n",
"from qualtran.bloqs.block_encoding.unitary import Unitary\n",
"\n",
"linear_combination_block_encoding = LinearCombination(\n",
" (Unitary(TGate()), Unitary(Hadamard()), Unitary(XGate()), Unitary(ZGate())),\n",
" lambd=(0.25, -0.25, 0.25, -0.25),\n",
" lambd_bits=1,\n",
")"
]
},
{
"cell_type": "markdown",
"id": "a3c0e843",
"metadata": {
"cq.autogen": "LinearCombination.graphical_signature.md"
},
"source": [
"#### Graphical Signature"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "403264e7",
"metadata": {
"cq.autogen": "LinearCombination.graphical_signature.py"
},
"outputs": [],
"source": [
"from qualtran.drawing import show_bloqs\n",
"show_bloqs([linear_combination_block_encoding],\n",
" ['`linear_combination_block_encoding`'])"
]
},
{
"cell_type": "markdown",
"id": "a506b326",
"metadata": {
"cq.autogen": "LinearCombination.call_graph.md"
},
"source": [
"### Call Graph"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9df2892b",
"metadata": {
"cq.autogen": "LinearCombination.call_graph.py"
},
"outputs": [],
"source": [
"from qualtran.resource_counting.generalizers import ignore_split_join\n",
"linear_combination_block_encoding_g, linear_combination_block_encoding_sigma = linear_combination_block_encoding.call_graph(max_depth=1, generalizer=ignore_split_join)\n",
"show_call_graph(linear_combination_block_encoding_g)\n",
"show_counts_sigma(linear_combination_block_encoding_sigma)"
]
}
],
"metadata": {
Expand Down
Loading

0 comments on commit 2c190e1

Please sign in to comment.