|
| 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 | +} |
0 commit comments