Skip to content

Commit ddb62bd

Browse files
committed
Merge branch 'main' into unary_iteration
2 parents 37afa30 + 0f4deee commit ddb62bd

File tree

300 files changed

+8616
-5195
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

300 files changed

+8616
-5195
lines changed

dev_tools/autogenerate-bloqs-notebooks-v2.py

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,19 @@
217217
],
218218
),
219219
NotebookSpecV2(
220-
title='Swap Network',
221-
module=qualtran.bloqs.swap_network,
220+
title='Basic Swaps',
221+
module=qualtran.bloqs.basic_gates.swap,
222222
bloq_specs=[
223+
qualtran.bloqs.basic_gates.swap._TWO_BIT_SWAP_DOC,
224+
qualtran.bloqs.basic_gates.swap._TWO_BIT_CSWAP_DOC,
225+
qualtran.bloqs.basic_gates.swap._SWAP_DOC,
223226
qualtran.bloqs.basic_gates.swap._CSWAP_DOC,
227+
],
228+
),
229+
NotebookSpecV2(
230+
title='Swap Networks',
231+
module=qualtran.bloqs.swap_network,
232+
bloq_specs=[
224233
qualtran.bloqs.swap_network.cswap_approx._APPROX_CSWAP_DOC,
225234
qualtran.bloqs.swap_network.swap_with_zero._SWZ_DOC,
226235
qualtran.bloqs.swap_network.multiplexed_cswap._MULTIPLEXED_CSWAP_DOC,
@@ -499,11 +508,23 @@
499508
qualtran.bloqs.mod_arithmetic.mod_addition._C_MOD_ADD_DOC,
500509
],
501510
),
511+
NotebookSpecV2(
512+
title='Modular Subtraction',
513+
module=qualtran.bloqs.mod_arithmetic.mod_subtraction,
514+
bloq_specs=[
515+
qualtran.bloqs.mod_arithmetic.mod_subtraction._MOD_NEG_DOC,
516+
qualtran.bloqs.mod_arithmetic.mod_subtraction._CMOD_NEG_DOC,
517+
qualtran.bloqs.mod_arithmetic.mod_subtraction._MOD_SUB_DOC,
518+
qualtran.bloqs.mod_arithmetic.mod_subtraction._CMOD_SUB_DOC,
519+
],
520+
),
502521
NotebookSpecV2(
503522
title='Modular Multiplication',
504-
module=qualtran.bloqs.factoring.mod_mul,
505-
bloq_specs=[qualtran.bloqs.factoring.mod_mul._MODMUL_DOC],
506-
directory=f'{SOURCE_DIR}/bloqs/factoring',
523+
module=qualtran.bloqs.mod_arithmetic.mod_multiplication,
524+
bloq_specs=[
525+
qualtran.bloqs.mod_arithmetic.mod_multiplication._MOD_DBL_DOC,
526+
qualtran.bloqs.mod_arithmetic.mod_multiplication._C_MOD_MUL_K_DOC,
527+
],
507528
),
508529
NotebookSpecV2(
509530
title='Modular Exponentiation',
@@ -625,7 +646,15 @@
625646
title='Textbook Quantum Phase Estimation',
626647
module=qualtran.bloqs.phase_estimation.text_book_qpe,
627648
bloq_specs=[
628-
qualtran.bloqs.phase_estimation.text_book_qpe._CC_TEXTBOOK_PHASE_ESTIMATION_DOC
649+
qualtran.bloqs.phase_estimation.qpe_window_state._CC_RECTANGULAR_WINDOW_STATE_DOC,
650+
qualtran.bloqs.phase_estimation.text_book_qpe._CC_TEXTBOOK_PHASE_ESTIMATION_DOC,
651+
],
652+
),
653+
NotebookSpecV2(
654+
title='Kaiser Window State for Quantum Phase Estimation',
655+
module=qualtran.bloqs.phase_estimation.kaiser_window_state,
656+
bloq_specs=[
657+
qualtran.bloqs.phase_estimation.kaiser_window_state._CC_KAISER_WINDOW_STATE_DOC
629658
],
630659
),
631660
NotebookSpecV2(

dev_tools/how-to-cut-a-release.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Releasing Qualtran
2+
3+
The steps are
4+
5+
1. Bump the version number to the desired release version
6+
2. Tag the release
7+
3. Follow the Python packaging guide to generate a distribution and upload it
8+
4. Bump the version number to the next "dev" version
9+
10+
The packaging guide instructions can be found at:
11+
https://packaging.python.org/en/latest/tutorials/packaging-projects/#generating-distribution-archives
12+
13+
## Set the version number
14+
15+
Open a PR to edit `qualtran/_version.py` to change the version string to "x.y.z" (without any dev specifier), which
16+
is the desired version number.
17+
It should have previously been set to "x.y.z.dev0".
18+
The PR should be merged to the `main` branch and care should be taken not to merge any other PRs until
19+
the entire process is completed.
20+
Draft the release notes and circulate them for review.
21+
22+
## Tag the repository
23+
24+
Use GitHub "Releases" to tag the release with release notes. Tags for "x.y.0" minor releases should go on `main`.
25+
Patch releases (z > 0) should be tagged against a `vx.y` branch unless the patch immediately follows a minor release.
26+
27+
Follow the convention for tag names. Include the "v" in the tag name.
28+
29+
## Package the release
30+
31+
Make sure you're on `main` and have pulled the version-bump commit.
32+
It's recommended to carefully run `git clean -ndx` (change n to f to actually do it) to prepare
33+
a pristine repository state.
34+
Then, follow the guidance at
35+
https://packaging.python.org/en/latest/tutorials/packaging-projects/#generating-distribution-archives.
36+
37+
Modify the command to upload to the main pypi repository (rather than the test repository used for the tutorial).
38+
39+
## Bump the version number to dev
40+
41+
Edit `_version.py` again, and change the version number from "x.y.z" to "x.(y+1).0.dev0".
42+
43+
## Communicate
44+
45+
Send an email to [qualtran-announce@googlegroups.com](https://groups.google.com/g/qualtran-announce) announcing
46+
the release. Congrats!
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Generate the library-wide call graph from all bloq examples."""
16+
import logging
17+
import warnings
18+
from typing import Iterable
19+
20+
import networkx as nx
21+
22+
from qualtran import Bloq, BloqExample, DecomposeNotImplementedError, DecomposeTypeError
23+
from qualtran.bloqs.basic_gates import Rx, Ry, Rz, TGate, Toffoli, XPowGate, YPowGate, ZPowGate
24+
from qualtran.resource_counting import SympySymbolAllocator
25+
from qualtran.resource_counting._call_graph import _build_call_graph
26+
from qualtran.resource_counting._generalization import _make_composite_generalizer
27+
from qualtran.resource_counting.generalizers import (
28+
generalize_cvs,
29+
generalize_rotation_angle,
30+
ignore_alloc_free,
31+
ignore_cliffords,
32+
ignore_split_join,
33+
)
34+
35+
logger = logging.getLogger(__name__)
36+
37+
38+
def get_all_call_graph(bes: Iterable[BloqExample]):
39+
"""Create a call graph that is the union of all of the bloqs in the list of bloq examples.
40+
41+
This applies some standard generalizers, and will stop at a larger-than-default set
42+
of leaf bloqs in accordance with https://github.com/quantumlib/Qualtran/issues/873
43+
"""
44+
generalize = _make_composite_generalizer(
45+
ignore_split_join,
46+
generalize_cvs,
47+
generalize_rotation_angle,
48+
ignore_alloc_free,
49+
ignore_cliffords,
50+
)
51+
52+
def keep(b: Bloq) -> bool:
53+
if b == Toffoli():
54+
return True
55+
56+
if b == TGate():
57+
return True
58+
59+
if isinstance(b, (Rx, Ry, Rz, XPowGate, YPowGate, ZPowGate)):
60+
return True
61+
62+
try:
63+
_ = b.build_call_graph(SympySymbolAllocator())
64+
except DecomposeTypeError:
65+
return True
66+
except DecomposeNotImplementedError:
67+
warnings.warn(f"{b} lacks a call graph.")
68+
return True
69+
70+
return False
71+
72+
g = nx.DiGraph()
73+
ssa = SympySymbolAllocator()
74+
75+
for be in bes:
76+
logger.info("Building call graph for: %s", be.name)
77+
bloq = be.make()
78+
_build_call_graph(
79+
bloq=bloq, generalizer=generalize, ssa=ssa, keep=keep, max_depth=None, g=g, depth=0
80+
)
81+
82+
return g
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import networkx as nx
16+
import pytest
17+
18+
from .all_call_graph import get_all_call_graph
19+
from .bloq_finder import get_bloq_examples
20+
21+
22+
@pytest.mark.slow
23+
def test_get_all_call_graph():
24+
# This test generates a union of the call graphs of every bloq example in the library.
25+
# This test makes sure that there aren't any bloq examples with broken call graphs.
26+
bes = get_bloq_examples()
27+
g = get_all_call_graph(bes)
28+
res = list(nx.simple_cycles(g))
29+
assert res == []

dev_tools/requirements/envs/dev.env.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ jupyter-server==2.14.2
288288
# notebook-shim
289289
jupyter-server-terminals==0.5.3
290290
# via jupyter-server
291-
jupyterlab==4.2.4
291+
jupyterlab==4.2.5
292292
# via notebook
293293
jupyterlab-pygments==0.3.0
294294
# via nbconvert

dev_tools/requirements/envs/docs.env.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ jupyter-server-terminals==0.5.3
340340
# via
341341
# -c envs/dev.env.txt
342342
# jupyter-server
343-
jupyterlab==4.2.4
343+
jupyterlab==4.2.5
344344
# via
345345
# -c envs/dev.env.txt
346346
# notebook

dev_tools/requirements/envs/format.env.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ jupyter-server-terminals==0.5.3
310310
# via
311311
# -c envs/dev.env.txt
312312
# jupyter-server
313-
jupyterlab==4.2.4
313+
jupyterlab==4.2.5
314314
# via
315315
# -c envs/dev.env.txt
316316
# notebook

dev_tools/requirements/envs/pylint.env.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ jupyter-server-terminals==0.5.3
360360
# via
361361
# -c envs/dev.env.txt
362362
# jupyter-server
363-
jupyterlab==4.2.4
363+
jupyterlab==4.2.5
364364
# via
365365
# -c envs/dev.env.txt
366366
# notebook

dev_tools/requirements/envs/pytest.env.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ jupyter-server-terminals==0.5.3
334334
# via
335335
# -c envs/dev.env.txt
336336
# jupyter-server
337-
jupyterlab==4.2.4
337+
jupyterlab==4.2.5
338338
# via
339339
# -c envs/dev.env.txt
340340
# notebook

dev_tools/requirements/envs/runtime.env.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ jupyter-server-terminals==0.5.3
293293
# via
294294
# -c envs/dev.env.txt
295295
# jupyter-server
296-
jupyterlab==4.2.4
296+
jupyterlab==4.2.5
297297
# via
298298
# -c envs/dev.env.txt
299299
# notebook

docs/bloq_infra.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ types (``Register``), and algorithms (``CompositeBloq``).
2424
:maxdepth: 1
2525
:caption: Quantum Computer Architectures:
2626

27-
surface_code/azure_cost_model.ipynb
27+
surface_code/physical_cost_model.ipynb
28+
surface_code/beverland_et_al_model.ipynb
2829
surface_code/thc_compilation.ipynb
2930
surface_code/msft_resource_estimator_interop.ipynb
3031

@@ -35,6 +36,7 @@ types (``Register``), and algorithms (``CompositeBloq``).
3536
_infra/composite_bloq.ipynb
3637
cirq_interop/cirq_interop.ipynb
3738
cirq_interop/t_complexity.ipynb
39+
qref_interop/bartiq_demo.ipynb
3840
_infra/gate_with_registers.ipynb
3941
drawing/graphviz.ipynb
4042
drawing/musical_score.ipynb

docs/bloqs/index.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Bloqs Library
3434
basic_gates/y_gate.ipynb
3535
mcmt/and_bloq.ipynb
3636
basic_gates/states_and_effects.ipynb
37+
basic_gates/swap.ipynb
3738
swap_network/swap_network.ipynb
3839
basic_gates/global_phase.ipynb
3940
basic_gates/identity.ipynb
@@ -80,7 +81,8 @@ Bloqs Library
8081
:caption: Modular Arithmetic:
8182

8283
mod_arithmetic/mod_addition.ipynb
83-
factoring/mod_mul.ipynb
84+
mod_arithmetic/mod_subtraction.ipynb
85+
mod_arithmetic/mod_multiplication.ipynb
8486
factoring/mod_exp.ipynb
8587
factoring/ecc/ec_add.ipynb
8688
factoring/ecc/ecc.ipynb
@@ -102,6 +104,7 @@ Bloqs Library
102104
qft/qft_phase_gradient.ipynb
103105
phase_estimation/lp_resource_state.ipynb
104106
phase_estimation/text_book_qpe.ipynb
107+
phase_estimation/kaiser_window_state.ipynb
105108
qubitization/qubitization_walk_operator.ipynb
106109
phase_estimation/qubitization_qpe.ipynb
107110

qualtran/Protocols.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"\n",
3434
"### Call Graph\n",
3535
"\n",
36-
"You can get a directed-acyclic graph representing the hierarchical decomposition of bloqs by calling `bloq.call_graph()` or direct callees with `bloq.bloq_counts()`. Additional functionality is contained in the `qualtran.resource_counting` module. To implement this protocol, bloq authors can override `Bloq.build_call_graph(...)`. The default fallback uses the decomposition protocol and `build_cbloq_call_graph(...)`. See the full [call graph protocol documentation](./resource_counting/bloq_counts.ipynb) for details.\n",
36+
"You can get a directed-acyclic graph representing the hierarchical decomposition of bloqs by calling `bloq.call_graph()` or direct callees with `bloq.bloq_counts()`. Additional functionality is contained in the `qualtran.resource_counting` module. To implement this protocol, bloq authors can override `Bloq.build_call_graph(...)`. The default fallback uses the decomposition protocol and `build_cbloq_call_graph(...)`. See the full [call graph protocol documentation](./resource_counting/call_graph.ipynb) for details.\n",
3737
"\n",
3838
"### Tensor\n",
3939
"\n",
@@ -65,7 +65,7 @@
6565
"name": "python",
6666
"nbconvert_exporter": "python",
6767
"pygments_lexer": "ipython3",
68-
"version": "3.10.9"
68+
"version": "3.11.8"
6969
}
7070
},
7171
"nbformat": 4,

qualtran/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
QFxp,
5252
QIntOnesComp,
5353
QUInt,
54-
BoundedQUInt,
54+
BQUInt,
5555
QMontgomeryUInt,
5656
)
5757

0 commit comments

Comments
 (0)