Skip to content

Commit

Permalink
Revamp ChebyshevPolynomial (#1213)
Browse files Browse the repository at this point in the history
* Revamp `ChebyshevPolynomial`

* Fix mypy
  • Loading branch information
charlesyuan314 authored Jul 30, 2024
1 parent d9a1eb1 commit 22e5538
Show file tree
Hide file tree
Showing 4 changed files with 201 additions and 148 deletions.
81 changes: 30 additions & 51 deletions qualtran/bloqs/block_encoding/chebyshev_polynomial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,26 @@
},
"source": [
"## `ChebyshevPolynomial`\n",
"Block encoding of $T_j[H]$ where $T_j$ is the $j$-th Chebyshev polynomial.\n",
"Block encoding of $T_j[A]$ where $T_j$ is the $j$-th Chebyshev polynomial.\n",
"\n",
"Here H is a Hamiltonian with spectral norm $|H| \\le 1$, we assume we have\n",
"Here $A$ is a Hermitian matrix with spectral norm $|A| \\le 1$, we assume we have\n",
"an $n_L$ qubit ancilla register, and assume that $j > 0$ to avoid block\n",
"encoding the identity operator.\n",
"\n",
"Recall:\n",
"\n",
"\\begin{align*}\n",
" T_0[H] &= \\mathbb{1} \\\\\n",
" T_1[H] &= H \\\\\n",
" T_2[H] &= 2 H^2 - \\mathbb{1} \\\\\n",
" T_3[H] &= 4 H^3 - 3 H \\\\\n",
" T_0[A] &= I \\\\\n",
" T_1[A] &= A \\\\\n",
" T_2[A] &= 2 A^2 - I \\\\\n",
" T_3[A] &= 4 A^3 - 3 A \\\\\n",
" &\\dots\n",
"\\end{align*}\n",
"\n",
"See https://github.com/quantumlib/Qualtran/issues/984 for an alternative.\n",
"\n",
"#### Parameters\n",
" - `block_encoding`: Block encoding of a Hamiltonian $H$, $\\mathcal{B}[H]$. Assumes the $|G\\rangle$ state of the block encoding is the identity operator.\n",
" - `block_encoding`: Block encoding of a Hermitian matrix $A$, $\\mathcal{B}[A]$. Assumes the $|G\\rangle$ state of the block encoding is the identity operator.\n",
" - `order`: order of Chebychev polynomial. \n",
"\n",
"#### References\n",
Expand Down Expand Up @@ -87,60 +87,38 @@
{
"cell_type": "code",
"execution_count": null,
"id": "948022f5",
"id": "76559ac1",
"metadata": {
"cq.autogen": "ChebyshevPolynomial.chebyshev_poly"
"cq.autogen": "ChebyshevPolynomial.chebyshev_poly_even"
},
"outputs": [],
"source": [
"from qualtran.bloqs.block_encoding import LCUBlockEncodingZeroState\n",
"from qualtran.bloqs.chemistry.hubbard_model.qubitization import PrepareHubbard, SelectHubbard\n",
"from qualtran.bloqs.basic_gates import Hadamard, XGate\n",
"from qualtran.bloqs.block_encoding import LinearCombination, Unitary\n",
"\n",
"dim = 3\n",
"select = SelectHubbard(x_dim=dim, y_dim=dim)\n",
"U = 4\n",
"t = 1\n",
"prepare = PrepareHubbard(x_dim=dim, y_dim=dim, t=t, u=U)\n",
"N = dim * dim * 2\n",
"qlambda = 2 * N * t + (N * U) // 2\n",
"block_bloq = LCUBlockEncodingZeroState(\n",
" select=select, prepare=prepare, alpha=qlambda, epsilon=0.0\n",
")\n",
"chebyshev_poly = ChebyshevPolynomial(block_bloq, order=3)"
"bloq = LinearCombination((Unitary(XGate()), Unitary(Hadamard())), (1.0, 1.0), lambd_bits=1)\n",
"chebyshev_poly_even = ChebyshevPolynomial(bloq, order=4)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5c2de09f",
"id": "1d85b9c1",
"metadata": {
"cq.autogen": "ChebyshevPolynomial.black_box_chebyshev_poly"
"cq.autogen": "ChebyshevPolynomial.chebyshev_poly_odd"
},
"outputs": [],
"source": [
"from qualtran.bloqs.block_encoding import (\n",
" BlackBoxPrepare,\n",
" BlackBoxSelect,\n",
" LCUBlockEncodingZeroState,\n",
")\n",
"from qualtran.bloqs.chemistry.hubbard_model.qubitization import PrepareHubbard, SelectHubbard\n",
"from qualtran.bloqs.basic_gates import Hadamard\n",
"from qualtran.bloqs.block_encoding import Unitary\n",
"\n",
"dim = 3\n",
"select = SelectHubbard(x_dim=dim, y_dim=dim)\n",
"U = 4\n",
"t = 1\n",
"prepare = PrepareHubbard(x_dim=dim, y_dim=dim, t=t, u=U)\n",
"N = dim * dim * 2\n",
"qlambda = 2 * N * t + (N * U) // 2\n",
"black_box_block_bloq = LCUBlockEncodingZeroState(\n",
" select=BlackBoxSelect(select), prepare=BlackBoxPrepare(prepare), alpha=qlambda, epsilon=0.0\n",
")\n",
"black_box_chebyshev_poly = ChebyshevPolynomial(black_box_block_bloq, order=3)"
"bloq = Unitary(Hadamard())\n",
"chebyshev_poly_odd = ChebyshevPolynomial(bloq, order=5)"
]
},
{
"cell_type": "markdown",
"id": "feb63ede",
"id": "9dcdb85f",
"metadata": {
"cq.autogen": "ChebyshevPolynomial.graphical_signature.md"
},
Expand All @@ -151,20 +129,20 @@
{
"cell_type": "code",
"execution_count": null,
"id": "5c240f74",
"id": "70740244",
"metadata": {
"cq.autogen": "ChebyshevPolynomial.graphical_signature.py"
},
"outputs": [],
"source": [
"from qualtran.drawing import show_bloqs\n",
"show_bloqs([chebyshev_poly, black_box_chebyshev_poly],\n",
" ['`chebyshev_poly`', '`black_box_chebyshev_poly`'])"
"show_bloqs([chebyshev_poly_even, chebyshev_poly_odd],\n",
" ['`chebyshev_poly_even`', '`chebyshev_poly_odd`'])"
]
},
{
"cell_type": "markdown",
"id": "9ae67df3",
"id": "5ceaeb9b",
"metadata": {
"cq.autogen": "ChebyshevPolynomial.call_graph.md"
},
Expand All @@ -175,16 +153,16 @@
{
"cell_type": "code",
"execution_count": null,
"id": "8c7b9d94",
"id": "d258bae7",
"metadata": {
"cq.autogen": "ChebyshevPolynomial.call_graph.py"
},
"outputs": [],
"source": [
"from qualtran.resource_counting.generalizers import ignore_split_join\n",
"chebyshev_poly_g, chebyshev_poly_sigma = chebyshev_poly.call_graph(max_depth=1, generalizer=ignore_split_join)\n",
"show_call_graph(chebyshev_poly_g)\n",
"show_counts_sigma(chebyshev_poly_sigma)"
"chebyshev_poly_even_g, chebyshev_poly_even_sigma = chebyshev_poly_even.call_graph(max_depth=1, generalizer=ignore_split_join)\n",
"show_call_graph(chebyshev_poly_even_g)\n",
"show_counts_sigma(chebyshev_poly_even_sigma)"
]
}
],
Expand All @@ -195,7 +173,8 @@
"name": "python3"
},
"language_info": {
"name": "python"
"name": "python",
"version": "3.11.2"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 22e5538

Please sign in to comment.