Skip to content

Commit

Permalink
Merge branch 'main' into gqsp-hamiltonian-simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
tanujkhattar authored Mar 18, 2024
2 parents fc01bc9 + 0db37a9 commit 5277f51
Show file tree
Hide file tree
Showing 13 changed files with 684 additions and 14 deletions.
19 changes: 14 additions & 5 deletions dev_tools/autogenerate-bloqs-notebooks-v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import qualtran.bloqs.mcmt.and_bloq
import qualtran.bloqs.multiplexers.apply_gate_to_lth_target
import qualtran.bloqs.phase_estimation.lp_resource_state
import qualtran.bloqs.qft.approximate_qft
import qualtran.bloqs.qft.two_bit_ffft
import qualtran.bloqs.reflection
import qualtran.bloqs.rotations.phasing_via_cost_function
Expand Down Expand Up @@ -95,6 +96,11 @@
module=qualtran.bloqs.basic_gates.toffoli,
bloq_specs=[qualtran.bloqs.basic_gates.toffoli._TOFFOLI_DOC],
),
NotebookSpecV2(
title='Hadamard',
module=qualtran.bloqs.basic_gates.hadamard,
bloq_specs=[qualtran.bloqs.basic_gates.hadamard._HADAMARD_DOC],
),
NotebookSpecV2(
title='Swap Network',
module=qualtran.bloqs.swap_network,
Expand Down Expand Up @@ -123,13 +129,11 @@
bloq_specs=[
qualtran.bloqs.state_preparation.prepare_uniform_superposition._PREP_UNIFORM_DOC
],
directory=f'{SOURCE_DIR}/bloqs/',
),
NotebookSpecV2(
title='Apply to Lth Target',
module=qualtran.bloqs.multiplexers.apply_gate_to_lth_target,
bloq_specs=[qualtran.bloqs.multiplexers.apply_gate_to_lth_target._APPLYLTH_DOC],
directory=f'{SOURCE_DIR}/bloqs/',
),
NotebookSpecV2(
title='QROM',
Expand Down Expand Up @@ -199,7 +203,8 @@
qualtran.bloqs.chemistry.trotter.grid_ham.potential._PAIR_POTENTIAL,
qualtran.bloqs.chemistry.trotter.grid_ham.potential._POTENTIAL_ENERGY,
],
directory=f'{SOURCE_DIR}/bloqs/chemistry/trotter',
directory=f'{SOURCE_DIR}/bloqs/chemistry/trotter/grid_ham/',
path_stem=f'{SOURCE_DIR}/bloqs/chemistry/trotter/grid_ham/trotter',
),
NotebookSpecV2(
title='Tensor Hypercontraction',
Expand All @@ -218,7 +223,6 @@
qualtran.bloqs.mcmt.and_bloq._AND_DOC,
qualtran.bloqs.mcmt.and_bloq._MULTI_AND_DOC,
],
directory=f'{SOURCE_DIR}/bloqs/',
),
NotebookSpecV2(
title='Block Encoding',
Expand All @@ -242,7 +246,7 @@
qualtran.bloqs.mcmt.multi_control_multi_target_pauli._C_MULTI_NOT_DOC,
qualtran.bloqs.mcmt.multi_control_multi_target_pauli._CC_PAULI_DOC,
],
directory=f'{SOURCE_DIR}/bloqs/',
directory=f'{SOURCE_DIR}/bloqs/mcmt/',
),
# --------------------------------------------------------------------------
# ----- Arithmetic -----------------------------------------------------
Expand Down Expand Up @@ -326,6 +330,11 @@
module=qualtran.bloqs.qft.two_bit_ffft,
bloq_specs=[qualtran.bloqs.qft.two_bit_ffft._TWO_BIT_FFFT_DOC],
),
NotebookSpecV2(
title='Approximate QFT',
module=qualtran.bloqs.qft.approximate_qft,
bloq_specs=[qualtran.bloqs.qft.approximate_qft._CC_AQFT_DOC],
),
# --------------------------------------------------------------------------
# ----- Phase Estimation -----------------------------------------------------
# --------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion qualtran/_infra/gate_with_registers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}
6 changes: 5 additions & 1 deletion qualtran/bloqs/arithmetic/multiplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
Side,
Signature,
)
from qualtran.bloqs.basic_gates import Toffoli
from qualtran.bloqs.basic_gates import TGate, Toffoli
from qualtran.cirq_interop.t_complexity_protocol import TComplexity
from qualtran.resource_counting.symbolic_counting_utils import smax

if TYPE_CHECKING:
from qualtran import SoquetT
Expand Down Expand Up @@ -103,6 +104,9 @@ def add_my_tensors(
self, self.signature, self.short_name(), tn, tag, incoming=incoming, outgoing=outgoing
)

def build_call_graph(self, ssa: 'SympySymbolAllocator') -> Set['BloqCountT']:
return {(TGate(), 8 * smax(self.a_bitsize, self.b_bitsize) ** 2)}


@bloq_example
def _plus_equal_product() -> PlusEqualProduct:
Expand Down
146 changes: 146 additions & 0 deletions qualtran/bloqs/basic_gates/hadamard.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "269cd713",
"metadata": {
"cq.autogen": "title_cell"
},
"source": [
"# Hadamard"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a181241c",
"metadata": {
"cq.autogen": "top_imports"
},
"outputs": [],
"source": [
"from qualtran import Bloq, CompositeBloq, BloqBuilder, Signature, Register\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": "51e3fa62",
"metadata": {
"cq.autogen": "Hadamard.bloq_doc.md"
},
"source": [
"## `Hadamard`\n",
"The Hadamard gate\n",
"\n",
"This converts between the X and Z basis.\n",
"\n",
"$$\\begin{aligned}\n",
"H |0\\rangle = |+\\rangle \\\\\n",
"H |-\\rangle = |1\\rangle\n",
"\\end{aligned}$$\n",
"\n",
"#### Registers\n",
" - `q`: The qubit\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d05cfd73",
"metadata": {
"cq.autogen": "Hadamard.bloq_doc.py"
},
"outputs": [],
"source": [
"from qualtran.bloqs.basic_gates import Hadamard"
]
},
{
"cell_type": "markdown",
"id": "35b53a72",
"metadata": {
"cq.autogen": "Hadamard.example_instances.md"
},
"source": [
"### Example Instances"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "39ebe976",
"metadata": {
"cq.autogen": "Hadamard.hadamard"
},
"outputs": [],
"source": [
"hadamard = Hadamard()"
]
},
{
"cell_type": "markdown",
"id": "f19223de",
"metadata": {
"cq.autogen": "Hadamard.graphical_signature.md"
},
"source": [
"#### Graphical Signature"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "92b60b87",
"metadata": {
"cq.autogen": "Hadamard.graphical_signature.py"
},
"outputs": [],
"source": [
"from qualtran.drawing import show_bloqs\n",
"show_bloqs([hadamard],\n",
" ['`hadamard`'])"
]
},
{
"cell_type": "markdown",
"id": "6dc303ab",
"metadata": {
"cq.autogen": "Hadamard.call_graph.md"
},
"source": [
"### Call Graph"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "19f5aeb1",
"metadata": {
"cq.autogen": "Hadamard.call_graph.py"
},
"outputs": [],
"source": [
"hadamard_g, hadamard_sigma = hadamard.call_graph()\n",
"show_call_graph(hadamard_g)\n",
"show_counts_sigma(hadamard_sigma)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
4 changes: 2 additions & 2 deletions qualtran/bloqs/basic_gates/hadamard.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ class Hadamard(Bloq):
This converts between the X and Z basis.
$$
$$\begin{aligned}
H |0\rangle = |+\rangle \\
H |-\rangle = |1\rangle
$$
\end{aligned}$$
Registers:
q: The qubit
Expand Down
2 changes: 1 addition & 1 deletion qualtran/bloqs/mcmt/and_bloq.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
},
"outputs": [],
"source": [
"multi_and = MultiAnd(cvs=(1,) * 4)"
"multi_and = MultiAnd(cvs=(1, 0, 1, 0, 1, 0))"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions qualtran/bloqs/mcmt/multi_control_multi_target_pauli.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def _c_multi_not() -> MultiTargetCNOT:

_C_MULTI_NOT_DOC = BloqDocSpec(
bloq_cls=MultiTargetCNOT,
import_line='from qualtran.bloqs.multi_control_multi_target_pauli import MultiTargetCNOT',
import_line='from qualtran.bloqs.mcmt import MultiTargetCNOT',
examples=(_c_multi_not_symb, _c_multi_not),
)

Expand Down Expand Up @@ -204,7 +204,7 @@ def _ccpauli() -> MultiControlPauli:

_CC_PAULI_DOC = BloqDocSpec(
bloq_cls=MultiControlPauli,
import_line='from qualtran.bloqs.multi_control_multi_target_pauli import MultiControlPauli',
import_line='from qualtran.bloqs.mcmt import MultiControlPauli',
examples=(_ccpauli,),
)

Expand Down
2 changes: 1 addition & 1 deletion qualtran/bloqs/multiplexers/apply_gate_to_lth_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,6 @@ def _z_to_odd(n: int):

_APPLYLTH_DOC = BloqDocSpec(
bloq_cls=ApplyGateToLthQubit,
import_line='from qualtran.bloqs.apply_gate_to_lth_target import ApplyGateToLthQubit',
import_line='from qualtran.bloqs.multiplexers.apply_gate_to_lth_target import ApplyGateToLthQubit',
examples=(_apply_z_to_odd,),
)
Loading

0 comments on commit 5277f51

Please sign in to comment.