Skip to content

Commit

Permalink
Improvements to autogenerate-bloqs-notebooks-v2.py (#796)
Browse files Browse the repository at this point in the history
* Improvements to autogenerate-bloqs-notebooks-v2.py

* Revert swap_network.ipynb

* Revert changes to jupyter_autogen_v2.py
  • Loading branch information
tanujkhattar authored Mar 15, 2024
1 parent 370ccc4 commit 0db37a9
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 12 deletions.
13 changes: 8 additions & 5 deletions dev_tools/autogenerate-bloqs-notebooks-v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,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 @@ -124,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 @@ -200,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 @@ -219,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 @@ -243,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
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,),
)
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,6 @@ def _c_prep_uniform() -> PrepareUniformSuperposition:

_PREP_UNIFORM_DOC = BloqDocSpec(
bloq_cls=PrepareUniformSuperposition,
import_line='from qualtran.bloqs.prepare_uniform_superposition import PrepareUniformSuperposition',
import_line='from qualtran.bloqs.state_preparation import PrepareUniformSuperposition',
examples=(_prep_uniform, _c_prep_uniform),
)

0 comments on commit 0db37a9

Please sign in to comment.