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

2024-05 Docs maintenance #940

Merged
merged 9 commits into from
May 15, 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
9 changes: 9 additions & 0 deletions dev_tools/autogenerate-bloqs-notebooks-v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import qualtran.bloqs.chemistry.pbc.first_quantization.projectile.select_and_prepare
import qualtran.bloqs.chemistry.pbc.first_quantization.select_t
import qualtran.bloqs.chemistry.pbc.first_quantization.select_uv
import qualtran.bloqs.chemistry.quad_fermion.givens_bloq
import qualtran.bloqs.chemistry.sf.single_factorization
import qualtran.bloqs.chemistry.sparse.prepare
import qualtran.bloqs.chemistry.sparse.walk_operator
Expand Down Expand Up @@ -270,6 +271,14 @@
],
directory=f'{SOURCE_DIR}/bloqs/chemistry/trotter/hubbard',
),
NotebookSpecV2(
title='Givens Rotations',
module=qualtran.bloqs.chemistry.quad_fermion.givens_bloq,
bloq_specs=[
qualtran.bloqs.chemistry.quad_fermion.givens_bloq._REAL_GIVENS_DOC,
qualtran.bloqs.chemistry.quad_fermion.givens_bloq._CPLX_GIVENS_DOC,
],
),
]

# --------------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion docs/bloq_infra.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ types (``Register``), and algorithms (``CompositeBloq``).
Protocols.ipynb
simulation/classical_sim.ipynb
simulation/tensor.ipynb
resource_counting/bloq_counts.ipynb
resource_counting/call_graph.ipynb
Adjoint.ipynb
Controlled.ipynb

Expand All @@ -37,5 +37,6 @@ types (``Register``), and algorithms (``CompositeBloq``).
_infra/gate_with_registers.ipynb
drawing/graphviz.ipynb
drawing/musical_score.ipynb
drawing/drawing_call_graph.ipynb
simulation/xcheck_classical_quimb.ipynb
Autodoc.ipynb
1 change: 1 addition & 0 deletions docs/bloqs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Bloqs Library
chemistry/trotter/trotterized_unitary.ipynb
chemistry/trotter/ising/ising.ipynb
chemistry/trotter/hubbard/hubbard.ipynb
chemistry/quad_fermion/givens_bloq.ipynb

.. toctree::
:maxdepth: 2
Expand Down
317 changes: 317 additions & 0 deletions qualtran/bloqs/chemistry/quad_fermion/givens_bloq.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,317 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "d171e669",
"metadata": {
"cq.autogen": "title_cell"
},
"source": [
"# Givens Rotations\n",
"\n",
"The Givens rotation Bloqs help count costs for similarity transforming\n",
"fermionic ladder operators to produce linear combinations of fermionic ladder operators.\n",
"\n",
"Following notation from Reference [1] we note that a single \n",
"ladder operator can be similarity transformed by a basis rotation to produce a linear \n",
"combination of ladder operators\n",
"$$\n",
"U(Q)a_{q}U(Q)^{\\dagger} = \\sum_{p}Q_{pq}^{*}a_{p} = \\overrightarrow{a}_{q}\\\\\n",
"U(Q)a_{q}^{\\dagger}U(Q)^{\\dagger} = \\sum_{p}Q_{pq}a_{p}^{\\dagger} = \n",
"\\overrightarrow{a}_{q}^{\\dagger}\n",
"$$\n",
"Each vector of operators can be implemented by a $N$ (size of basis) Givens rotation unitaries as\n",
"$$\n",
"V_{\\overrightarrow{Q}_{q}} a_{0} V_{\\overrightarrow{Q}_{q}}^{\\dagger} = \n",
"\\overrightarrow{a}_{q} \\\\\n",
"V_{\\overrightarrow{Q}_{q}} a_{0}^{\\dagger} V_{\\overrightarrow{Q}_{q}}^{\\dagger} = \n",
"\\overrightarrow{a}_{q}^{\\dagger}\n",
"$$\n",
"where \n",
"$$\n",
"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",
"V_{n-3,n-4}(\\theta_{n-2}, \\phi_{n-2})...V_{2, 1}(\\theta_{1}, \\phi_{1})\n",
"V_{1, 0}(\\theta_{0}, \\phi_{0})\n",
"$$\n",
"with each $V_{ij}(\\theta, \\phi) = \\mathrm{RZ}_{j}(\\pi)\\mathrm{R}_{ij}(\\theta)$. \n",
"and $1$ Rz rotation for real valued $\\overrightarrow{Q}$.\n",
"\n",
"\n",
"References:\n",
" 1. Vera von Burg, Guang Hao Low, Thomas H ̈aner, Damian S. Steiger, Markus Reiher, \n",
" Martin Roetteler, and Matthias Troyer, “Quantum computing enhanced computational catalysis,” \n",
" Phys. Rev. Res. 3, 033055 (2021)."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "14f323c1",
"metadata": {
"cq.autogen": "top_imports"
},
"outputs": [],
"source": [
"from qualtran import Bloq, CompositeBloq, BloqBuilder, Signature, Register\n",
"from qualtran import QBit, QInt, QUInt, QAny\n",
"from qualtran.drawing import show_bloq, show_call_graph, show_counts_sigma\n",
"from typing import *\n",
"import numpy as np\n",
"import sympy\n",
"import cirq"
]
},
{
"cell_type": "markdown",
"id": "7bae4b04",
"metadata": {
"cq.autogen": "RealGivensRotationByPhaseGradient.bloq_doc.md"
},
"source": [
"## `RealGivensRotationByPhaseGradient`\n",
"Givens rotation corresponding to a 2-fermion mode transformation generated by\n",
"\n",
"$$\n",
" e^{\\theta (a_{i}^{\\dagger}a_{j} - a_{j}^{\\dagger}a_{i})} = e^{i \\theta (YX + XY) / 2}\n",
"$$\n",
"\n",
"corresponding to the circuit\n",
"\n",
" i: ───X───X───S^-1───X───Rz(theta)───X───X───@───────X───S^-1───\n",
" │ │ │ │ │\n",
" j: ───S───@───H──────@───Rz(theta)───@───────X───H───@──────────\n",
"\n",
"The rotation is performed by addition into a phase state and the fractional binary for\n",
"$\\theta$ is stored in an additional register.\n",
"\n",
"The Toffoli cost for this block comes from the cost of two rotations by addition into\n",
"the phase gradient state which which is $2(b_{\\mathrm{grad}}-2)$ where $b_{\\mathrm{grad}}$\n",
"is the size of the phasegradient register.\n",
"\n",
"#### Parameters\n",
" - `phasegrad_bitsize int`: size of phase gradient which is also the size of the register representing the binary fraction of the rotation angle\n",
"\n",
"#### Registers\n",
" - `target_i`: 1st-qubit QBit type register\n",
" - `target_j`: 2nd-qubit Qbit type register\n",
" - `rom_data`: QFxp data representing fractional binary for real part of rotation\n",
" - `phase_gradient`: QFxp data type representing the phase gradient register \n",
"\n",
"#### References\n",
" - [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"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ddd15f5d",
"metadata": {
"cq.autogen": "RealGivensRotationByPhaseGradient.bloq_doc.py"
},
"outputs": [],
"source": [
"from qualtran.bloqs.chemistry.quad_fermion.givens_bloq import RealGivensRotationByPhaseGradient"
]
},
{
"cell_type": "markdown",
"id": "e87cf483",
"metadata": {
"cq.autogen": "RealGivensRotationByPhaseGradient.example_instances.md"
},
"source": [
"### Example Instances"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "92e02725",
"metadata": {
"cq.autogen": "RealGivensRotationByPhaseGradient.real_givens"
},
"outputs": [],
"source": [
"real_givens = RealGivensRotationByPhaseGradient(phasegrad_bitsize=4)"
]
},
{
"cell_type": "markdown",
"id": "13ab3902",
"metadata": {
"cq.autogen": "RealGivensRotationByPhaseGradient.graphical_signature.md"
},
"source": [
"#### Graphical Signature"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1164b4d2",
"metadata": {
"cq.autogen": "RealGivensRotationByPhaseGradient.graphical_signature.py"
},
"outputs": [],
"source": [
"from qualtran.drawing import show_bloqs\n",
"show_bloqs([real_givens],\n",
" ['`real_givens`'])"
]
},
{
"cell_type": "markdown",
"id": "4dae5381",
"metadata": {
"cq.autogen": "RealGivensRotationByPhaseGradient.call_graph.md"
},
"source": [
"### Call Graph"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d57228fb",
"metadata": {
"cq.autogen": "RealGivensRotationByPhaseGradient.call_graph.py"
},
"outputs": [],
"source": [
"from qualtran.resource_counting.generalizers import ignore_split_join\n",
"real_givens_g, real_givens_sigma = real_givens.call_graph(max_depth=1, generalizer=ignore_split_join)\n",
"show_call_graph(real_givens_g)\n",
"show_counts_sigma(real_givens_sigma)"
]
},
{
"cell_type": "markdown",
"id": "2ef53544",
"metadata": {
"cq.autogen": "ComplexGivensRotationByPhaseGradient.bloq_doc.md"
},
"source": [
"## `ComplexGivensRotationByPhaseGradient`\n",
"Complex Givens rotation corresponding to a 2-fermion mode transformation generated by\n",
"\n",
"$$\n",
" 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",
"$$\n",
"\n",
"corresponding to the circuit\n",
"\n",
" i: ───X───X───S^-1───X───Rz(theta)───X───X───@───────X──S^-1─────\n",
" │ │ │ │ │\n",
" j: ───S───@───H──────@───Rz(theta)───@───────X───H───@──Rz(phi)──\n",
"\n",
"The rotation is performed by addition into a phase state and the fractional binary for\n",
"$\\theta$ is stored in an additional register.\n",
"\n",
"#### Parameters\n",
" - `phasegrad_bitsize int`: size of phase gradient which is also the size of the register representing the binary fraction of the rotation angles\n",
"\n",
"#### Registers\n",
" - `target_i`: 1st-qubit QBit type register\n",
" - `target_j`: 2nd-qubit Qbit type register\n",
" - `real_rom_data`: QFxp data representing fractional binary for real part of rotation\n",
" - `cplx_rom_data`: QFxp data representing fractional binary for imag part of rotation\n",
" - `phase_gradient`: QFxp data type representing the phase gradient register\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "654e9882",
"metadata": {
"cq.autogen": "ComplexGivensRotationByPhaseGradient.bloq_doc.py"
},
"outputs": [],
"source": [
"from qualtran.bloqs.chemistry.quad_fermion.givens_bloq import ComplexGivensRotationByPhaseGradient"
]
},
{
"cell_type": "markdown",
"id": "cacdb693",
"metadata": {
"cq.autogen": "ComplexGivensRotationByPhaseGradient.example_instances.md"
},
"source": [
"### Example Instances"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "864bb02d",
"metadata": {
"cq.autogen": "ComplexGivensRotationByPhaseGradient.cplx_givens"
},
"outputs": [],
"source": [
"cplx_givens = ComplexGivensRotationByPhaseGradient(phasegrad_bitsize=4)"
]
},
{
"cell_type": "markdown",
"id": "f83a1498",
"metadata": {
"cq.autogen": "ComplexGivensRotationByPhaseGradient.graphical_signature.md"
},
"source": [
"#### Graphical Signature"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8a33e7f1",
"metadata": {
"cq.autogen": "ComplexGivensRotationByPhaseGradient.graphical_signature.py"
},
"outputs": [],
"source": [
"from qualtran.drawing import show_bloqs\n",
"show_bloqs([cplx_givens],\n",
" ['`cplx_givens`'])"
]
},
{
"cell_type": "markdown",
"id": "998e18d3",
"metadata": {
"cq.autogen": "ComplexGivensRotationByPhaseGradient.call_graph.md"
},
"source": [
"### Call Graph"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1580750d",
"metadata": {
"cq.autogen": "ComplexGivensRotationByPhaseGradient.call_graph.py"
},
"outputs": [],
"source": [
"from qualtran.resource_counting.generalizers import ignore_split_join\n",
"cplx_givens_g, cplx_givens_sigma = cplx_givens.call_graph(max_depth=1, generalizer=ignore_split_join)\n",
"show_call_graph(cplx_givens_g)\n",
"show_counts_sigma(cplx_givens_sigma)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
8 changes: 4 additions & 4 deletions qualtran/bloqs/chemistry/quad_fermion/givens_bloq.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ def build_composite_bloq(

@bloq_example
def _real_givens() -> RealGivensRotationByPhaseGradient:
r_givens = RealGivensRotationByPhaseGradient(phasegrad_bitsize=4)
return r_givens
real_givens = RealGivensRotationByPhaseGradient(phasegrad_bitsize=4)
return real_givens


_REAL_GIVENS_DOC = BloqDocSpec(
Expand Down Expand Up @@ -263,8 +263,8 @@ def build_composite_bloq(

@bloq_example
def _cplx_givens() -> ComplexGivensRotationByPhaseGradient:
c_givens = ComplexGivensRotationByPhaseGradient(phasegrad_bitsize=4)
return c_givens
cplx_givens = ComplexGivensRotationByPhaseGradient(phasegrad_bitsize=4)
return cplx_givens


_CPLX_GIVENS_DOC = BloqDocSpec(
Expand Down
Loading
Loading