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

[GQSP] Negative powers and Hamiltonian simulation #669

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
8ff6b5f
wip: negative powers
anurudhp Feb 10, 2024
c56d708
notebook: Hamiltonian simulation example.
anurudhp Feb 15, 2024
845f03a
notebook
anurudhp Feb 15, 2024
d7e35c7
lint + TODO comment
anurudhp Feb 15, 2024
814cd51
nb: explain negative power terms
anurudhp Feb 15, 2024
9604613
call graph for GQSP
anurudhp Feb 16, 2024
47e0dfb
test negative power poly
anurudhp Feb 18, 2024
38bfd2f
call prepare oracle correctly
anurudhp Feb 18, 2024
bc63521
add adjoint for random gate
anurudhp Feb 18, 2024
8ccb722
fix negative power test
anurudhp Feb 18, 2024
962b700
gqsp - fewer uses of U
anurudhp Feb 18, 2024
fa9e476
hash random gate to support call graph
anurudhp Feb 18, 2024
95dd66d
format
anurudhp Feb 18, 2024
a0ae7b0
rename
anurudhp Feb 20, 2024
595577b
wip call graph for ham. sim. by gqsp
anurudhp Feb 23, 2024
07a784e
add tests
anurudhp Feb 25, 2024
57416ce
fix bug in using adjoint - use pow(-1) for GWR
anurudhp Feb 26, 2024
b3e9cef
cleanup notebook
anurudhp Feb 26, 2024
94dac17
fix expression for alpha
anurudhp Feb 26, 2024
671fe13
cleanup bloq construction
anurudhp Feb 26, 2024
f576a5d
implement `**-1` for RandomGate
anurudhp Feb 26, 2024
53bd323
cleanup unused fix
anurudhp Feb 27, 2024
52a980b
add test for `cos` approximation
anurudhp Feb 27, 2024
b2e5a6e
docstring
anurudhp Feb 27, 2024
a1afb1f
use adjoint
anurudhp Feb 27, 2024
f9e425d
reorganize code
anurudhp Feb 27, 2024
f4b1ddf
fix warning
anurudhp Feb 27, 2024
830a2fd
compute exp-cos approx accurately
anurudhp Mar 4, 2024
916b674
fix sympy: all vars need to have same limit
anurudhp Mar 4, 2024
dc0f286
mark slow test
anurudhp Mar 4, 2024
6f8d34b
update ham-sim poly test
anurudhp Mar 5, 2024
8b33214
use exact poly as in paper
anurudhp Mar 5, 2024
026df56
cleanup code
anurudhp Mar 6, 2024
fc01bc9
remove custom hash
anurudhp Mar 15, 2024
5277f51
Merge branch 'main' into gqsp-hamiltonian-simulation
tanujkhattar Mar 18, 2024
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
123 changes: 108 additions & 15 deletions qualtran/bloqs/generalized_qsp.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,34 @@
"metadata": {},
"outputs": [],
"source": [
"from qualtran.bloqs.qubitization_walk_operator_test import get_walk_operator_for_1d_Ising_model\n",
"import numpy as np\n",
"import scipy\n",
"from qualtran.drawing import show_bloq\n",
"\n",
"from qualtran.bloqs.generalized_qsp import GeneralizedQSP"
"import qualtran\n",
"from qualtran.bloqs.qubitization_walk_operator_test import get_walk_operator_for_1d_Ising_model\n",
"from qualtran.bloqs.qubitization_walk_operator import QubitizationWalkOperator\n",
"from qualtran.cirq_interop import CirqGateAsBloq\n",
"\n",
"from qualtran.bloqs.generalized_qsp import GeneralizedQSP, HamiltonianSimulationByGQSP\n",
"from qualtran.bloqs.generalized_qsp_test import RandomGate"
]
},
{
"cell_type": "markdown",
"id": "6963c30f339d42de",
"metadata": {},
"source": [
"`GeneralizedQSP` implements the Quantum Eigenvalue Transform on a unitary $U$ using QSP. Given a complex GQSP polynomial $P$ (and its complement $Q$), it implements the unitary:\n",
"$$U' = \\begin{bmatrix} P(U) & \\cdot \\\\ Q(U) & \\cdot \\end{bmatrix}$$\n",
"\n",
"Here, the polynomials $P, Q$ must satisfy the following constraint:\n",
"\n",
"$$\\left| P(e^{i\\theta}) \\right|^2 + \\left| Q(e^{i\\theta}) \\right|^2 = 1 ~~\\text{for every}~ \\theta \\in [0, 2\\pi]$$\n",
"\n",
"A polynomial $P$ is said to be a GQSP polynomial iff it satisfies $\\left| P(e^{i\\theta}) \\right|^2 \\le 1$ for every $\\theta \\in [0, 2\\pi]$. \n",
"\n",
"Reference: https://doi.org/10.48550/arXiv.2308.01501"
]
},
{
Expand All @@ -32,42 +56,111 @@
"show_bloq(U.decompose_bloq())"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "dc7100fd94d58c6b",
"metadata": {},
"outputs": [],
"source": [
"pU = GeneralizedQSP(U, (0.5, 0.5), (-0.5, 0.5))\n",
"show_bloq(pU.decompose_bloq())"
]
},
{
"cell_type": "markdown",
"id": "6963c30f339d42de",
"id": "935a03f7-5843-4b11-abe6-5eb9048c0ab5",
"metadata": {},
"source": [
"`GeneralizedQSP` implements the Quantum Eigenvalue Transform on a unitary $U$ using QSP. Given a complex QSP polynomial $P$ (and its complement $Q$), it implements the unitary:\n",
"$$U' = \\begin{bmatrix} P(U) & \\cdot \\\\ Q(U) & \\cdot \\end{bmatrix}$$\n",
"There is also a method that directly computes $Q$ from $P$:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "78cd3857297f092b",
"metadata": {},
"outputs": [],
"source": [
"pU = GeneralizedQSP.from_qsp_polynomial(U, (0.5, 0, 0.5))\n",
"show_bloq(pU.decompose_bloq())"
]
},
{
"cell_type": "markdown",
"id": "a58f06ba-9287-435d-92a3-256f747024c2",
"metadata": {},
"source": [
"### Negative degree terms\n",
"\n",
"Here, the polynomials $P, Q$ must satisfy the following constraint:\n",
"To apply GQSP for a polynomial $P'(z) = z^{-k} P(z)$, we can just pass the polynomial $P$ along with negative power $k$.\n",
"The QSP angle sequence is the same for both, and $P'$ can be achieved by running $(U^\\dagger)^k$ at any point in the circuit."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ee60e95f-979f-420d-91b1-b6955b9c5a3b",
"metadata": {},
"outputs": [],
"source": [
"pU = GeneralizedQSP.from_qsp_polynomial(U, (0.5, 0, 0.5), negative_power=1)\n",
"show_bloq(pU)"
]
},
{
"cell_type": "markdown",
"id": "c84e5443-483c-4294-8a79-1d2bed70e1f5",
"metadata": {},
"source": [
"## Hamiltonian Simulation by GQSP\n",
"\n",
"Given the Szegedy Quantum Walk Operator for a Hamiltonian $H$, one can construct the walk operator for $e^{-iHt}$ using GQSP (Corollary 8).\n",
"\n",
"### Recap:\n",
"\n",
"For a Hamiltonian $H = \\sum_i \\alpha_i U_i$, given the SELECT and PREPARE oracles\n",
"$$ \\text{SELECT} = \\sum_j \\ketbra{j}{j} \\otimes U_j $$\n",
"$$ \\text{PREPARE} \\ket{0} = \\sum_j \\frac{\\sqrt{\\alpha_j}}{\\|\\alpha\\|_1} \\ket{j} $$\n",
"we can implement the [QubitizationWalkOperator](qubitization_walk_operator.ipynb) that encodes the spectrum of $H$ in the eigenphases of the walk operator $W$.\n",
"\n",
"$$\\left\\mid P(e^{i\\theta}) \\right\\mid^2 + \\left\\mid Q(e^{i\\theta}) \\right\\mid^2 = 1 ~~\\text{for every}~ \\theta \\in [0, 2\\pi]$$\n",
"### Approximating $\\cos$\n",
"We can use the Jacobi-Anger expansion to obtain low-degree polynomial approximations for the $\\cos$ function:\n",
"\n",
"$$e^{it\\cos\\theta} = \\sum_{n = -\\infty}^{\\infty} i^n J_n(t) (e^{i\\theta})^n$$\n",
"\n",
"Reference: https://arxiv.org/abs/2308.01501"
"where $J_n$ is the $n$-th [Bessel function of the first kind](https://en.wikipedia.org/wiki/Bessel_function#Bessel_functions_of_the_first_kind), which is provided by `scipy.special.jv`.\n",
"\n",
"We can cutoff at $d = O(t + \\log(1/\\epsilon) / \\log\\log(1/\\epsilon))$ to get an $\\epsilon$-approximation (Theorem 7):\n",
"\n",
"$$P[t](z) = \\sum_{n = -d}^d i^n J_n(t) z^n$$\n",
"\n",
"### Obtaining $e^{iHt}$\n",
"\n",
"As the eigenphases of the walk operator are $e^{-i\\arccos(E_k / \\|\\alpha\\|_1)}$, we can use the GQSP polynomial with $P = P[\\|\\alpha\\|_1 t]$ (and complementary $Q = 0$) to obtain $P(U) = e^{-iHt}$.\n",
"The obtained GQSP operator $W'$ can then be used with the PREPARE oracle to simulate the hamiltonian:\n",
"$$(\\langle0| \\otimes \\text{PREPARE}^\\dagger \\otimes I) W' (|0\\rangle \\otimes \\text{PREPARE} \\otimes I) |0\\rangle|\\psi\\rangle = |0\\rangle e^{-iHt}|\\psi\\rangle$$"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "dc7100fd94d58c6b",
"id": "c4ccd9c8-92ce-4b53-92bc-722f263a32ad",
"metadata": {},
"outputs": [],
"source": [
"pU = GeneralizedQSP(U, (0.5, 0.5))\n",
"show_bloq(pU.decompose_bloq())"
"W_e_iHt = HamiltonianSimulationByGQSP(U, t=5, alpha=1, precision=1e-3)\n",
"show_bloq(W_e_iHt.decompose_bloq())"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "78cd3857297f092b",
"id": "c6627cb6-446d-4f76-b727-8ed2f67bc382",
"metadata": {},
"outputs": [],
"source": [
"pU = GeneralizedQSP(U, (0.5, 0, 0.5))\n",
"show_bloq(pU.decompose_bloq())"
"W_e_iHt.call_graph()"
]
}
],
Expand All @@ -87,7 +180,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
"version": "3.11.7"
}
},
"nbformat": 4,
Expand Down
Loading
Loading