Skip to content

Commit 8fcba74

Browse files
authored
2024-05 Docs maintenance (#940)
* re-generate stale notebook * re-generate stale notebook * add givens_bloq notebook * fix, test notebook * missed rename * toc for drawing_call_graph
1 parent 03d09a0 commit 8fcba74

8 files changed

Lines changed: 343 additions & 9 deletions

File tree

dev_tools/autogenerate-bloqs-notebooks-v2.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import qualtran.bloqs.chemistry.pbc.first_quantization.projectile.select_and_prepare
6363
import qualtran.bloqs.chemistry.pbc.first_quantization.select_t
6464
import qualtran.bloqs.chemistry.pbc.first_quantization.select_uv
65+
import qualtran.bloqs.chemistry.quad_fermion.givens_bloq
6566
import qualtran.bloqs.chemistry.sf.single_factorization
6667
import qualtran.bloqs.chemistry.sparse.prepare
6768
import qualtran.bloqs.chemistry.sparse.walk_operator
@@ -270,6 +271,14 @@
270271
],
271272
directory=f'{SOURCE_DIR}/bloqs/chemistry/trotter/hubbard',
272273
),
274+
NotebookSpecV2(
275+
title='Givens Rotations',
276+
module=qualtran.bloqs.chemistry.quad_fermion.givens_bloq,
277+
bloq_specs=[
278+
qualtran.bloqs.chemistry.quad_fermion.givens_bloq._REAL_GIVENS_DOC,
279+
qualtran.bloqs.chemistry.quad_fermion.givens_bloq._CPLX_GIVENS_DOC,
280+
],
281+
),
273282
]
274283

275284
# --------------------------------------------------------------------------

docs/bloq_infra.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ types (``Register``), and algorithms (``CompositeBloq``).
1515
Protocols.ipynb
1616
simulation/classical_sim.ipynb
1717
simulation/tensor.ipynb
18-
resource_counting/bloq_counts.ipynb
18+
resource_counting/call_graph.ipynb
1919
Adjoint.ipynb
2020
Controlled.ipynb
2121

@@ -37,5 +37,6 @@ types (``Register``), and algorithms (``CompositeBloq``).
3737
_infra/gate_with_registers.ipynb
3838
drawing/graphviz.ipynb
3939
drawing/musical_score.ipynb
40+
drawing/drawing_call_graph.ipynb
4041
simulation/xcheck_classical_quimb.ipynb
4142
Autodoc.ipynb

docs/bloqs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Bloqs Library
4949
chemistry/trotter/trotterized_unitary.ipynb
5050
chemistry/trotter/ising/ising.ipynb
5151
chemistry/trotter/hubbard/hubbard.ipynb
52+
chemistry/quad_fermion/givens_bloq.ipynb
5253

5354
.. toctree::
5455
:maxdepth: 2
Lines changed: 317 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,317 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "d171e669",
6+
"metadata": {
7+
"cq.autogen": "title_cell"
8+
},
9+
"source": [
10+
"# Givens Rotations\n",
11+
"\n",
12+
"The Givens rotation Bloqs help count costs for similarity transforming\n",
13+
"fermionic ladder operators to produce linear combinations of fermionic ladder operators.\n",
14+
"\n",
15+
"Following notation from Reference [1] we note that a single \n",
16+
"ladder operator can be similarity transformed by a basis rotation to produce a linear \n",
17+
"combination of ladder operators\n",
18+
"$$\n",
19+
"U(Q)a_{q}U(Q)^{\\dagger} = \\sum_{p}Q_{pq}^{*}a_{p} = \\overrightarrow{a}_{q}\\\\\n",
20+
"U(Q)a_{q}^{\\dagger}U(Q)^{\\dagger} = \\sum_{p}Q_{pq}a_{p}^{\\dagger} = \n",
21+
"\\overrightarrow{a}_{q}^{\\dagger}\n",
22+
"$$\n",
23+
"Each vector of operators can be implemented by a $N$ (size of basis) Givens rotation unitaries as\n",
24+
"$$\n",
25+
"V_{\\overrightarrow{Q}_{q}} a_{0} V_{\\overrightarrow{Q}_{q}}^{\\dagger} = \n",
26+
"\\overrightarrow{a}_{q} \\\\\n",
27+
"V_{\\overrightarrow{Q}_{q}} a_{0}^{\\dagger} V_{\\overrightarrow{Q}_{q}}^{\\dagger} = \n",
28+
"\\overrightarrow{a}_{q}^{\\dagger}\n",
29+
"$$\n",
30+
"where \n",
31+
"$$\n",
32+
"V_{\\overrightarrow{Q}_{q}} = V_{n-1,n-2}(0, \\phi_{n-1}) V_{n-2, n-3}(\\theta_{n-2}, \\phi_{n-2})\n",
33+
"V_{n-3,n-4}(\\theta_{n-2}, \\phi_{n-2})...V_{2, 1}(\\theta_{1}, \\phi_{1})\n",
34+
"V_{1, 0}(\\theta_{0}, \\phi_{0})\n",
35+
"$$\n",
36+
"with each $V_{ij}(\\theta, \\phi) = \\mathrm{RZ}_{j}(\\pi)\\mathrm{R}_{ij}(\\theta)$. \n",
37+
"and $1$ Rz rotation for real valued $\\overrightarrow{Q}$.\n",
38+
"\n",
39+
"\n",
40+
"References:\n",
41+
" 1. Vera von Burg, Guang Hao Low, Thomas H ̈aner, Damian S. Steiger, Markus Reiher, \n",
42+
" Martin Roetteler, and Matthias Troyer, “Quantum computing enhanced computational catalysis,” \n",
43+
" Phys. Rev. Res. 3, 033055 (2021)."
44+
]
45+
},
46+
{
47+
"cell_type": "code",
48+
"execution_count": null,
49+
"id": "14f323c1",
50+
"metadata": {
51+
"cq.autogen": "top_imports"
52+
},
53+
"outputs": [],
54+
"source": [
55+
"from qualtran import Bloq, CompositeBloq, BloqBuilder, Signature, Register\n",
56+
"from qualtran import QBit, QInt, QUInt, QAny\n",
57+
"from qualtran.drawing import show_bloq, show_call_graph, show_counts_sigma\n",
58+
"from typing import *\n",
59+
"import numpy as np\n",
60+
"import sympy\n",
61+
"import cirq"
62+
]
63+
},
64+
{
65+
"cell_type": "markdown",
66+
"id": "7bae4b04",
67+
"metadata": {
68+
"cq.autogen": "RealGivensRotationByPhaseGradient.bloq_doc.md"
69+
},
70+
"source": [
71+
"## `RealGivensRotationByPhaseGradient`\n",
72+
"Givens rotation corresponding to a 2-fermion mode transformation generated by\n",
73+
"\n",
74+
"$$\n",
75+
" e^{\\theta (a_{i}^{\\dagger}a_{j} - a_{j}^{\\dagger}a_{i})} = e^{i \\theta (YX + XY) / 2}\n",
76+
"$$\n",
77+
"\n",
78+
"corresponding to the circuit\n",
79+
"\n",
80+
" i: ───X───X───S^-1───X───Rz(theta)───X───X───@───────X───S^-1───\n",
81+
" │ │ │ │ │\n",
82+
" j: ───S───@───H──────@───Rz(theta)───@───────X───H───@──────────\n",
83+
"\n",
84+
"The rotation is performed by addition into a phase state and the fractional binary for\n",
85+
"$\\theta$ is stored in an additional register.\n",
86+
"\n",
87+
"The Toffoli cost for this block comes from the cost of two rotations by addition into\n",
88+
"the phase gradient state which which is $2(b_{\\mathrm{grad}}-2)$ where $b_{\\mathrm{grad}}$\n",
89+
"is the size of the phasegradient register.\n",
90+
"\n",
91+
"#### Parameters\n",
92+
" - `phasegrad_bitsize int`: size of phase gradient which is also the size of the register representing the binary fraction of the rotation angle\n",
93+
"\n",
94+
"#### Registers\n",
95+
" - `target_i`: 1st-qubit QBit type register\n",
96+
" - `target_j`: 2nd-qubit Qbit type register\n",
97+
" - `rom_data`: QFxp data representing fractional binary for real part of rotation\n",
98+
" - `phase_gradient`: QFxp data type representing the phase gradient register \n",
99+
"\n",
100+
"#### References\n",
101+
" - [Compilation of Fault-Tolerant Quantum Heuristics for Combinatorial Optimization]( https://arxiv.org/abs/2007.07391). Section II-C: Oracles for phasing by cost function. Appendix A: Addition for controlled rotations\n"
102+
]
103+
},
104+
{
105+
"cell_type": "code",
106+
"execution_count": null,
107+
"id": "ddd15f5d",
108+
"metadata": {
109+
"cq.autogen": "RealGivensRotationByPhaseGradient.bloq_doc.py"
110+
},
111+
"outputs": [],
112+
"source": [
113+
"from qualtran.bloqs.chemistry.quad_fermion.givens_bloq import RealGivensRotationByPhaseGradient"
114+
]
115+
},
116+
{
117+
"cell_type": "markdown",
118+
"id": "e87cf483",
119+
"metadata": {
120+
"cq.autogen": "RealGivensRotationByPhaseGradient.example_instances.md"
121+
},
122+
"source": [
123+
"### Example Instances"
124+
]
125+
},
126+
{
127+
"cell_type": "code",
128+
"execution_count": null,
129+
"id": "92e02725",
130+
"metadata": {
131+
"cq.autogen": "RealGivensRotationByPhaseGradient.real_givens"
132+
},
133+
"outputs": [],
134+
"source": [
135+
"real_givens = RealGivensRotationByPhaseGradient(phasegrad_bitsize=4)"
136+
]
137+
},
138+
{
139+
"cell_type": "markdown",
140+
"id": "13ab3902",
141+
"metadata": {
142+
"cq.autogen": "RealGivensRotationByPhaseGradient.graphical_signature.md"
143+
},
144+
"source": [
145+
"#### Graphical Signature"
146+
]
147+
},
148+
{
149+
"cell_type": "code",
150+
"execution_count": null,
151+
"id": "1164b4d2",
152+
"metadata": {
153+
"cq.autogen": "RealGivensRotationByPhaseGradient.graphical_signature.py"
154+
},
155+
"outputs": [],
156+
"source": [
157+
"from qualtran.drawing import show_bloqs\n",
158+
"show_bloqs([real_givens],\n",
159+
" ['`real_givens`'])"
160+
]
161+
},
162+
{
163+
"cell_type": "markdown",
164+
"id": "4dae5381",
165+
"metadata": {
166+
"cq.autogen": "RealGivensRotationByPhaseGradient.call_graph.md"
167+
},
168+
"source": [
169+
"### Call Graph"
170+
]
171+
},
172+
{
173+
"cell_type": "code",
174+
"execution_count": null,
175+
"id": "d57228fb",
176+
"metadata": {
177+
"cq.autogen": "RealGivensRotationByPhaseGradient.call_graph.py"
178+
},
179+
"outputs": [],
180+
"source": [
181+
"from qualtran.resource_counting.generalizers import ignore_split_join\n",
182+
"real_givens_g, real_givens_sigma = real_givens.call_graph(max_depth=1, generalizer=ignore_split_join)\n",
183+
"show_call_graph(real_givens_g)\n",
184+
"show_counts_sigma(real_givens_sigma)"
185+
]
186+
},
187+
{
188+
"cell_type": "markdown",
189+
"id": "2ef53544",
190+
"metadata": {
191+
"cq.autogen": "ComplexGivensRotationByPhaseGradient.bloq_doc.md"
192+
},
193+
"source": [
194+
"## `ComplexGivensRotationByPhaseGradient`\n",
195+
"Complex Givens rotation corresponding to a 2-fermion mode transformation generated by\n",
196+
"\n",
197+
"$$\n",
198+
" e^{i \\phi n_{j}}e^{\\theta (a_{i}^{\\dagger}a_{j} - a_{j}^{\\dagger}a_{i})} = e^{i \\phi Z_{j}/2}e^{i \\theta (YX + XY) / 2}\n",
199+
"$$\n",
200+
"\n",
201+
"corresponding to the circuit\n",
202+
"\n",
203+
" i: ───X───X───S^-1───X───Rz(theta)───X───X───@───────X──S^-1─────\n",
204+
" │ │ │ │ │\n",
205+
" j: ───S───@───H──────@───Rz(theta)───@───────X───H───@──Rz(phi)──\n",
206+
"\n",
207+
"The rotation is performed by addition into a phase state and the fractional binary for\n",
208+
"$\\theta$ is stored in an additional register.\n",
209+
"\n",
210+
"#### Parameters\n",
211+
" - `phasegrad_bitsize int`: size of phase gradient which is also the size of the register representing the binary fraction of the rotation angles\n",
212+
"\n",
213+
"#### Registers\n",
214+
" - `target_i`: 1st-qubit QBit type register\n",
215+
" - `target_j`: 2nd-qubit Qbit type register\n",
216+
" - `real_rom_data`: QFxp data representing fractional binary for real part of rotation\n",
217+
" - `cplx_rom_data`: QFxp data representing fractional binary for imag part of rotation\n",
218+
" - `phase_gradient`: QFxp data type representing the phase gradient register\n"
219+
]
220+
},
221+
{
222+
"cell_type": "code",
223+
"execution_count": null,
224+
"id": "654e9882",
225+
"metadata": {
226+
"cq.autogen": "ComplexGivensRotationByPhaseGradient.bloq_doc.py"
227+
},
228+
"outputs": [],
229+
"source": [
230+
"from qualtran.bloqs.chemistry.quad_fermion.givens_bloq import ComplexGivensRotationByPhaseGradient"
231+
]
232+
},
233+
{
234+
"cell_type": "markdown",
235+
"id": "cacdb693",
236+
"metadata": {
237+
"cq.autogen": "ComplexGivensRotationByPhaseGradient.example_instances.md"
238+
},
239+
"source": [
240+
"### Example Instances"
241+
]
242+
},
243+
{
244+
"cell_type": "code",
245+
"execution_count": null,
246+
"id": "864bb02d",
247+
"metadata": {
248+
"cq.autogen": "ComplexGivensRotationByPhaseGradient.cplx_givens"
249+
},
250+
"outputs": [],
251+
"source": [
252+
"cplx_givens = ComplexGivensRotationByPhaseGradient(phasegrad_bitsize=4)"
253+
]
254+
},
255+
{
256+
"cell_type": "markdown",
257+
"id": "f83a1498",
258+
"metadata": {
259+
"cq.autogen": "ComplexGivensRotationByPhaseGradient.graphical_signature.md"
260+
},
261+
"source": [
262+
"#### Graphical Signature"
263+
]
264+
},
265+
{
266+
"cell_type": "code",
267+
"execution_count": null,
268+
"id": "8a33e7f1",
269+
"metadata": {
270+
"cq.autogen": "ComplexGivensRotationByPhaseGradient.graphical_signature.py"
271+
},
272+
"outputs": [],
273+
"source": [
274+
"from qualtran.drawing import show_bloqs\n",
275+
"show_bloqs([cplx_givens],\n",
276+
" ['`cplx_givens`'])"
277+
]
278+
},
279+
{
280+
"cell_type": "markdown",
281+
"id": "998e18d3",
282+
"metadata": {
283+
"cq.autogen": "ComplexGivensRotationByPhaseGradient.call_graph.md"
284+
},
285+
"source": [
286+
"### Call Graph"
287+
]
288+
},
289+
{
290+
"cell_type": "code",
291+
"execution_count": null,
292+
"id": "1580750d",
293+
"metadata": {
294+
"cq.autogen": "ComplexGivensRotationByPhaseGradient.call_graph.py"
295+
},
296+
"outputs": [],
297+
"source": [
298+
"from qualtran.resource_counting.generalizers import ignore_split_join\n",
299+
"cplx_givens_g, cplx_givens_sigma = cplx_givens.call_graph(max_depth=1, generalizer=ignore_split_join)\n",
300+
"show_call_graph(cplx_givens_g)\n",
301+
"show_counts_sigma(cplx_givens_sigma)"
302+
]
303+
}
304+
],
305+
"metadata": {
306+
"kernelspec": {
307+
"display_name": "Python 3",
308+
"language": "python",
309+
"name": "python3"
310+
},
311+
"language_info": {
312+
"name": "python"
313+
}
314+
},
315+
"nbformat": 4,
316+
"nbformat_minor": 5
317+
}

qualtran/bloqs/chemistry/quad_fermion/givens_bloq.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ def build_composite_bloq(
168168

169169
@bloq_example
170170
def _real_givens() -> RealGivensRotationByPhaseGradient:
171-
r_givens = RealGivensRotationByPhaseGradient(phasegrad_bitsize=4)
172-
return r_givens
171+
real_givens = RealGivensRotationByPhaseGradient(phasegrad_bitsize=4)
172+
return real_givens
173173

174174

175175
_REAL_GIVENS_DOC = BloqDocSpec(
@@ -263,8 +263,8 @@ def build_composite_bloq(
263263

264264
@bloq_example
265265
def _cplx_givens() -> ComplexGivensRotationByPhaseGradient:
266-
c_givens = ComplexGivensRotationByPhaseGradient(phasegrad_bitsize=4)
267-
return c_givens
266+
cplx_givens = ComplexGivensRotationByPhaseGradient(phasegrad_bitsize=4)
267+
return cplx_givens
268268

269269

270270
_CPLX_GIVENS_DOC = BloqDocSpec(

0 commit comments

Comments
 (0)