├── qualtran
├── bloqs
│ ├── chemistry
│ │ ├── hubbard_model
│ │ │ ├── __init__.py
│ │ │ └── qubitization
│ │ │ │ ├── walk_operator.py
│ │ │ │ └── prepare_hubbard_test.py
│ │ ├── __init__.py
│ │ ├── df
│ │ │ └── __init__.py
│ │ ├── pbc
│ │ │ ├── __init__.py
│ │ │ └── first_quantization
│ │ │ │ ├── prepare_zeta_test.py
│ │ │ │ ├── prepare_test.py
│ │ │ │ ├── select_t_test.py
│ │ │ │ ├── projectile
│ │ │ │ └── select_t_test.py
│ │ │ │ └── select_uv_test.py
│ │ ├── sf
│ │ │ ├── __init__.py
│ │ │ └── select_bloq_test.py
│ │ ├── trotter
│ │ │ ├── __init__.py
│ │ │ ├── grid_ham
│ │ │ │ ├── __init__.py
│ │ │ │ ├── trotter_test.py
│ │ │ │ ├── qvr_test.py
│ │ │ │ └── kinetic_test.py
│ │ │ ├── ising
│ │ │ │ └── __init__.py
│ │ │ └── hubbard
│ │ │ │ ├── trotter_step_test.py
│ │ │ │ ├── interaction_test.py
│ │ │ │ └── hopping_test.py
│ │ ├── quad_fermion
│ │ │ └── __init__.py
│ │ ├── ising
│ │ │ └── __init__.py
│ │ ├── thc
│ │ │ ├── select_bloq_test.py
│ │ │ └── __init__.py
│ │ ├── sparse
│ │ │ └── select_bloq_test.py
│ │ └── black_boxes_test.py
│ ├── qsp
│ │ └── __init__.py
│ ├── cryptography
│ │ ├── __init__.py
│ │ ├── ecc
│ │ │ ├── ec_phase_estimate_r_test.py
│ │ │ └── find_ecc_private_key_test.py
│ │ └── rsa
│ │ │ └── rsa_phase_estimate_test.py
│ ├── mean_estimation
│ │ └── __init__.py
│ ├── optimization
│ │ ├── __init__.py
│ │ └── k_xor_sat
│ │ │ ├── __init__.py
│ │ │ └── kxor_instance_test.py
│ ├── reflections
│ │ ├── __init__.py
│ │ └── prepare_identity_test.py
│ ├── __init__.py
│ ├── qubitization
│ │ └── __init__.py
│ ├── hamiltonian_simulation
│ │ ├── __init__.py
│ │ └── guided_hamiltonian_test.py
│ ├── arithmetic
│ │ ├── lists
│ │ │ └── __init__.py
│ │ ├── trigonometric
│ │ │ ├── __init__.py
│ │ │ └── arcsin_test.py
│ │ └── conversions
│ │ │ ├── __init__.py
│ │ │ ├── contiguous_index_test.py
│ │ │ └── ones_complement_to_twos_complement_test.py
│ ├── qft
│ │ ├── __init__.py
│ │ └── two_bit_ffft_test.py
│ ├── block_encoding
│ │ ├── block_encoding_base_test.py
│ │ └── __init__.py
│ ├── for_testing
│ │ ├── casting_test.py
│ │ ├── __init__.py
│ │ ├── many_registers_test.py
│ │ ├── costing_test.py
│ │ ├── interior_alloc_test.py
│ │ ├── qubit_count_many_alloc_test.py
│ │ ├── with_decomposition_test.py
│ │ ├── matrix_gate_test.py
│ │ ├── with_call_graph.py
│ │ ├── with_call_graph_test.py
│ │ └── interior_alloc.py
│ ├── multiplexers
│ │ └── __init__.py
│ ├── bookkeeping
│ │ ├── arbitrary_clifford_test.py
│ │ ├── always_test.py
│ │ ├── __init__.py
│ │ ├── free_test.py
│ │ └── allocate_test.py
│ ├── gf_poly_arithmetic
│ │ └── __init__.py
│ ├── data_loading
│ │ └── __init__.py
│ ├── mod_arithmetic
│ │ └── __init__.py
│ ├── swap_network
│ │ └── __init__.py
│ ├── mcmt
│ │ ├── __init__.py
│ │ └── classically_controlled_test.py
│ ├── phase_estimation
│ │ ├── kaiser_window_state_test.py
│ │ ├── __init__.py
│ │ └── qpe_window_state_test.py
│ ├── state_preparation
│ │ ├── __init__.py
│ │ └── black_box_prepare_test.py
│ ├── gf_arithmetic
│ │ ├── __init__.py
│ │ ├── gf_utils.py
│ │ └── gf2_add_k_test.py
│ └── rotations
│ │ └── __init__.py
├── third_party
│ └── flamegraph
│ │ └── METADATA
├── protos
│ ├── __init__.py
│ ├── annotations.proto
│ ├── ec_point.proto
│ ├── ctrl_spec.proto
│ ├── args.proto
│ ├── registers.proto
│ ├── annotations_pb2.py
│ ├── ctrl_spec_pb2.py
│ ├── ec_point_pb2.py
│ ├── args_pb2.py
│ └── annotations_pb2.pyi
├── linalg
│ ├── polynomial
│ │ ├── __init__.py
│ │ ├── basic_test.py
│ │ └── basic.py
│ ├── __init__.py
│ ├── matrix_test.py
│ ├── testing.py
│ └── permutation_test.py
├── _version.py
├── serialization
│ ├── __init__.py
│ ├── annotations_test.py
│ ├── annotations.py
│ ├── ec_point_test.py
│ ├── ctrl_spec_test.py
│ ├── ec_point.py
│ ├── args_test.py
│ └── ctrl_spec.py
├── rotation_synthesis
│ ├── relative_norm
│ │ └── __init__.py
│ ├── channels
│ │ └── __init__.py
│ ├── rings
│ │ ├── _test_utils.py
│ │ └── __init__.py
│ ├── __init__.py
│ ├── lattice
│ │ └── __init__.py
│ ├── _typing.py
│ ├── matrix
│ │ └── __init__.py
│ └── protocols
│ │ └── __init__.py
├── surface_code
│ ├── physical_cost_model_test.py
│ ├── msft_resource_estimator_interop_test.py
│ ├── physical_cost_summary.py
│ └── data_block_test.py
├── simulation
│ ├── __init__.py
│ └── tensor
│ │ ├── _flattening_test.py
│ │ └── __init__.py
├── _infra
│ ├── __init__.py
│ └── bloq_example_test.py
├── exception
│ └── __init__.py
├── symbolics
│ ├── types_test.py
│ └── __init__.py
├── cirq_interop
│ ├── decompose_protocol_test.py
│ ├── __init__.py
│ └── _interop_qubit_manager_test.py
├── resource_counting
│ ├── _success_prob_test.py
│ ├── _generalization.py
│ └── __init__.py
├── drawing
│ ├── musical_score.html
│ ├── musical_score_test.py
│ ├── classical_sim_graph_test.py
│ └── __init__.py
├── qref_interop
│ └── __init__.py
└── dtype
│ └── __init__.py
├── MANIFEST.in
├── dev_tools
├── requirements
│ ├── deps
│ │ ├── pip-tools.txt
│ │ ├── format.txt
│ │ ├── mypy.txt
│ │ ├── dev-tools.txt
│ │ ├── docs.txt
│ │ ├── pylint.txt
│ │ ├── packaging.txt
│ │ ├── pytest.txt
│ │ └── runtime.txt
│ ├── Dockerfile
│ ├── envs
│ │ └── pip-tools.env.txt
│ └── re-pip-compile-in-docker.sh
├── templates
│ ├── root.jinja
│ ├── type_alias.jinja
│ ├── function.jinja
│ └── page.jinja
├── conf
│ ├── .coveragerc
│ ├── .pylintrc
│ └── mypy.ini
├── pyproject.toml
├── qualtran_dev_tools
│ ├── make_reference_docs
│ │ ├── _pages
│ │ │ └── __init__.py
│ │ ├── _components
│ │ │ ├── __init__.py
│ │ │ └── aliases.py
│ │ └── __init__.py
│ ├── __init__.py
│ ├── git_tools.py
│ └── all_call_graph_test.py
├── build-reference-docs.py
├── build-reference-docs-2.py
├── repomix
│ └── README.md
├── clean-notebooks.py
├── README.md
├── execute-notebooks.py
└── check-incremental-coverage-annotations.py
├── docs
├── _static
│ ├── favicon.png
│ ├── qualtran-logo-sm.png
│ └── fixes.css
├── reference
│ └── index.rst
├── .gitignore
└── _templates
│ ├── qai_logo.html
│ └── qualtran-sidebar.html
├── .github
├── report-vulnerability-button.png
└── problem-matchers
│ ├── black.json
│ ├── mypy.json
│ ├── pylint.json
│ └── README.md
├── .gitattributes
├── .readthedocs.yaml
├── check
├── autogenerate-notebooks
├── mypy
├── pylint
├── pytest
├── mypy-dev-tools
└── pytest-dev-tools
├── pyproject.toml
├── SUPPORT.md
└── .yamllint.yaml
/qualtran/bloqs/chemistry/hubbard_model/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/MANIFEST.in:
--------------------------------------------------------------------------------
1 | include dev_tools/requirements/deps/runtime.txt
--------------------------------------------------------------------------------
/dev_tools/requirements/deps/pip-tools.txt:
--------------------------------------------------------------------------------
1 | pip-tools
2 |
--------------------------------------------------------------------------------
/dev_tools/templates/root.jinja:
--------------------------------------------------------------------------------
1 | {{- self.content() -}}
2 |
--------------------------------------------------------------------------------
/dev_tools/requirements/deps/format.txt:
--------------------------------------------------------------------------------
1 | flynt~=0.60
2 | black~=24.8.0
3 | isort~=5.10.1
4 |
--------------------------------------------------------------------------------
/docs/_static/favicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/Qualtran/HEAD/docs/_static/favicon.png
--------------------------------------------------------------------------------
/dev_tools/requirements/deps/mypy.txt:
--------------------------------------------------------------------------------
1 | # the mypy dependency file
2 | mypy~=1.14
3 | mypy-protobuf
4 | sympy
5 |
--------------------------------------------------------------------------------
/docs/_static/qualtran-logo-sm.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/Qualtran/HEAD/docs/_static/qualtran-logo-sm.png
--------------------------------------------------------------------------------
/.github/report-vulnerability-button.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quantumlib/Qualtran/HEAD/.github/report-vulnerability-button.png
--------------------------------------------------------------------------------
/dev_tools/requirements/deps/dev-tools.txt:
--------------------------------------------------------------------------------
1 | -r pip-tools.txt
2 | -r mypy.txt
3 | -r pytest.txt
4 | -r format.txt
5 | -r pylint.txt
6 | -r docs.txt
7 | -r packaging.txt
8 |
9 | notebook
10 |
--------------------------------------------------------------------------------
/dev_tools/requirements/deps/docs.txt:
--------------------------------------------------------------------------------
1 | ipywidgets
2 | nbconvert
3 | nbformat
4 | sphinx
5 | sphinx-autobuild
6 | pydata-sphinx-theme
7 | myst-nb
8 | tensorflow-docs~=2023.5.24
9 |
10 | griffe
11 |
--------------------------------------------------------------------------------
/dev_tools/conf/.coveragerc:
--------------------------------------------------------------------------------
1 | [run]
2 | # Omit files outside the current working directory.
3 | # Note: this means coverage must be run from the cirq repo root.
4 | # Failure to do so will result in false positives.
5 | include = ./*
6 |
--------------------------------------------------------------------------------
/docs/reference/index.rst:
--------------------------------------------------------------------------------
1 | .. _reference:
2 |
3 | API Reference
4 | =============
5 |
6 | This section of the docs provides an API reference for all symbols
7 | in ``qualtran``.
8 |
9 |
10 | .. include:: autotoc.rst.inc
11 |
--------------------------------------------------------------------------------
/dev_tools/requirements/deps/pylint.txt:
--------------------------------------------------------------------------------
1 | pylint~=3.3.1
2 |
3 | # for checking _test.py files
4 | pytest
5 | openfermion[resources]
6 |
7 | # dev tools
8 | tensorflow-docs
9 | sphinx
10 | filelock
11 | griffe
12 | mdit-py-plugins
13 |
--------------------------------------------------------------------------------
/docs/.gitignore:
--------------------------------------------------------------------------------
1 | # Sphinx (stage 3) generation
2 | _build/
3 |
4 | # Generated reference toc
5 | reference/autotoc.rst.inc
6 |
7 | # All the generated reference pages
8 | **/*.md
9 |
10 | # All the generated notebooks
11 | **/*.ipynb
12 |
--------------------------------------------------------------------------------
/dev_tools/requirements/deps/packaging.txt:
--------------------------------------------------------------------------------
1 | # for testing packaging in isolation
2 | virtualenv
3 |
4 | # for building protos
5 | grpcio-tools
6 |
7 | # for creating packages
8 | setuptools
9 | wheel
10 |
11 | # for uploading packages to pypi
12 | twine
13 |
--------------------------------------------------------------------------------
/docs/_templates/qai_logo.html:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
--------------------------------------------------------------------------------
/dev_tools/requirements/deps/pytest.txt:
--------------------------------------------------------------------------------
1 | # dependencies to run pytest
2 | pytest
3 | pytest-asyncio
4 | pytest-cov
5 | pytest-xdist
6 |
7 | # test executing notebooks
8 | ipykernel
9 | filelock
10 |
11 | # chemistry resource estimates
12 | openfermion[resources]
13 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Mark generated protobuf files to be collapsed by default in PRs
2 | # See: https://docs.github.com/en/repositories/working-with-files/managing-files/customizing-how-changed-files-appear-on-github
3 | *_pb2.py linguist-generated=true
4 | *_pb2.pyi linguist-generated=true
5 |
--------------------------------------------------------------------------------
/.github/problem-matchers/black.json:
--------------------------------------------------------------------------------
1 | {
2 | "problemMatcher": [
3 | {
4 | "owner": "black",
5 | "severity": "error",
6 | "pattern": [
7 | {
8 | "regexp": "^(would reformat) (.+)$",
9 | "file": 2,
10 | "message": 1
11 | }
12 | ]
13 | }
14 | ]
15 | }
16 |
--------------------------------------------------------------------------------
/dev_tools/pyproject.toml:
--------------------------------------------------------------------------------
1 | [build-system]
2 | requires = ["setuptools>=61.0"]
3 | build-backend = "setuptools.build_meta"
4 |
5 | [project]
6 | name = "qualtran-dev-tools"
7 | version = "0.1.0"
8 | description = "Local development tools for the Qualtran project."
9 | requires-python = ">=3.10"
10 |
11 | [tool.setuptools]
12 | packages = ["qualtran_dev_tools"]
13 |
--------------------------------------------------------------------------------
/.github/problem-matchers/mypy.json:
--------------------------------------------------------------------------------
1 | {
2 | "problemMatcher": [
3 | {
4 | "owner": "mypy",
5 | "pattern": [
6 | {
7 | "regexp": "^(.+):(\\d+):\\s(error|warning):\\s(.+)$",
8 | "file": 1,
9 | "line": 2,
10 | "severity": 3,
11 | "message": 4
12 | }
13 | ]
14 | }
15 | ]
16 | }
17 |
--------------------------------------------------------------------------------
/qualtran/third_party/flamegraph/METADATA:
--------------------------------------------------------------------------------
1 | name: "Flamegraph"
2 | description:
3 | "The script allows plotting flamegraphs, useful to visualize T-costs for Bloqs."
4 |
5 | third_party {
6 | url {
7 | type: HOMEPAGE
8 | value: "https://github.com/brendangregg/FlameGraph"
9 | }
10 | last_upgrade_date { year: 2023 month: 10 day: 07 }
11 | license_type: CDDL1.0
12 | }
13 |
--------------------------------------------------------------------------------
/.readthedocs.yaml:
--------------------------------------------------------------------------------
1 | # .readthedocs.yaml
2 | # Read the Docs configuration file
3 | # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
4 |
5 | # Required
6 | version: 2
7 |
8 | # Set the OS, Python version and other tools you might need
9 | build:
10 | os: ubuntu-22.04
11 | tools:
12 | python: "3.10"
13 |
14 | # Build documentation in the "docs/" directory with Sphinx
15 | sphinx:
16 | configuration: docs/conf.py
17 |
18 | python:
19 | install:
20 | - requirements: dev_tools/requirements/deps/docs.txt
21 |
--------------------------------------------------------------------------------
/docs/_static/fixes.css:
--------------------------------------------------------------------------------
1 |
2 | /* Args etc tables
3 | - increase width so it isn't centered in the middle of the page
4 | */
5 | table.fixed.responsive {
6 | width: 100%;
7 | }
8 |
9 | /* "View on GitHub"
10 | - increase width so it is the only thing on this line
11 | - add some margin beneath it to let things breathe
12 | */
13 | table.tfo-notebook-buttons.tfo-api {
14 | width: 100%;
15 | margin-bottom: 1.5em;
16 | }
17 |
18 | /* Adjust size of GitHub icon in the nav bar.
19 | */
20 | html .pst-navbar-icon {
21 | font-size: 1.5rem;
22 | }
23 |
--------------------------------------------------------------------------------
/check/autogenerate-notebooks:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ################################################################################
4 | # Autogenerates the notebooks and reports whether there were any changes.
5 | #
6 | # Usage:
7 | # check/autogenerate-notebooks
8 | #
9 | ################################################################################
10 |
11 | python dev_tools/autogenerate-bloqs-notebooks-v2.py || exit $?
12 |
13 | if output=$(git status --porcelain) && [ -z "$output" ]; then
14 | # Working directory clean
15 | exit 0
16 | else
17 | # Uncommitted changes
18 | echo $output
19 | exit 1
20 | fi
21 |
--------------------------------------------------------------------------------
/qualtran/protos/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 |
--------------------------------------------------------------------------------
/qualtran/bloqs/qsp/__init__.py:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/qualtran/bloqs/chemistry/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 |
--------------------------------------------------------------------------------
/qualtran/bloqs/chemistry/df/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 |
--------------------------------------------------------------------------------
/qualtran/bloqs/chemistry/pbc/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 |
--------------------------------------------------------------------------------
/qualtran/bloqs/chemistry/sf/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 |
--------------------------------------------------------------------------------
/qualtran/bloqs/cryptography/__init__.py:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/qualtran/bloqs/mean_estimation/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 |
--------------------------------------------------------------------------------
/qualtran/bloqs/optimization/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2025 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 |
--------------------------------------------------------------------------------
/qualtran/bloqs/reflections/__init__.py:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/qualtran/linalg/polynomial/__init__.py:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/qualtran/bloqs/chemistry/trotter/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 |
--------------------------------------------------------------------------------
/qualtran/bloqs/chemistry/quad_fermion/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 |
--------------------------------------------------------------------------------
/docs/_templates/qualtran-sidebar.html:
--------------------------------------------------------------------------------
1 | {# Displays the TOC-subtree for pages nested under the currently active top-level TOCtree element. #}
2 |
17 |
--------------------------------------------------------------------------------
/qualtran/_version.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | __version__ = "0.7.0.dev0"
16 |
--------------------------------------------------------------------------------
/dev_tools/qualtran_dev_tools/make_reference_docs/_pages/__init__.py:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/dev_tools/qualtran_dev_tools/make_reference_docs/_components/__init__.py:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/qualtran/bloqs/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | """The standard library of quantum subroutines."""
16 |
--------------------------------------------------------------------------------
/qualtran/linalg/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | """Linear algebra routines for building bloqs."""
16 |
--------------------------------------------------------------------------------
/qualtran/serialization/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | """Functions for protobuf serialization of bloqs."""
16 |
--------------------------------------------------------------------------------
/check/mypy:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ################################################################################
4 | # Runs mypy on the repository using a preconfigured mypy.ini file.
5 | #
6 | # Usage:
7 | # check/mypy [--flags]
8 | ################################################################################
9 |
10 | # Get the working directory to the repo root.
11 | thisdir="$(dirname "${BASH_SOURCE[0]}")" || exit $?
12 | topdir="$(git -C "${thisdir}" rev-parse --show-toplevel)" || exit $?
13 | cd "${topdir}" || exit $?
14 |
15 | CONFIG_FILE='mypy.ini'
16 |
17 | echo -e -n "\033[31m"
18 | mypy --config-file=dev_tools/conf/$CONFIG_FILE "$@" qualtran/
19 | result=$?
20 | echo -e -n "\033[0m"
21 |
22 | exit ${result}
23 |
--------------------------------------------------------------------------------
/dev_tools/qualtran_dev_tools/make_reference_docs/__init__.py:
--------------------------------------------------------------------------------
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 | from ._make import make_reference_docs
16 |
--------------------------------------------------------------------------------
/qualtran/bloqs/qubitization/__init__.py:
--------------------------------------------------------------------------------
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 | from .qubitization_walk_operator import QubitizationWalkOperator
16 |
--------------------------------------------------------------------------------
/dev_tools/templates/type_alias.jinja:
--------------------------------------------------------------------------------
1 | {% extends "templates/page.jinja" %}
2 |
3 | {#----------------------------------------------------------------------------#}
4 |
5 | {% block header %}
6 | # {{page_info.short_name}}
7 |
8 | {% endblock header%}
9 |
10 | {#----------------------------------------------------------------------------#}
11 |
12 | {% block metadata %}
13 | This symbol is a **type alias**.
14 |
15 | {{ page_info.doc.brief }}
16 |
17 | {% endblock metadata %}
18 |
19 | {#----------------------------------------------------------------------------#}
20 |
21 | {% block body %}
22 | {% if page_info.signature %}
23 | #### Source:
24 |
25 | {{ builder.build_signature() }}
26 | {% endif %}
27 | {{ super() -}}
28 | {% endblock %}
29 |
--------------------------------------------------------------------------------
/check/pylint:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ################################################################################
4 | # Runs pylint on the repository using a preconfigured .pylintrc file.
5 | #
6 | # Usage:
7 | # check/pylint [--flags for pylint]
8 | ################################################################################
9 |
10 | # Get the working directory to the repo root.
11 | thisdir="$(dirname "${BASH_SOURCE[0]}")" || exit $?
12 | topdir="$(git -C "${thisdir}" rev-parse --show-toplevel)" || exit $?
13 | cd "${topdir}" || exit $?
14 |
15 | # Add dev_tools to $PYTHONPATH so that pylint can find custom checkers
16 | PYTHONPATH=dev_tools:dev_tools/qualtran_dev_tools pylint --jobs=0 --rcfile=dev_tools/conf/.pylintrc "$@" qualtran/ dev_tools/
17 |
--------------------------------------------------------------------------------
/qualtran/bloqs/hamiltonian_simulation/__init__.py:
--------------------------------------------------------------------------------
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 | from .guided_hamiltonian import GuidedHamiltonian, GuidedHamiltonianPhaseEstimation
15 |
--------------------------------------------------------------------------------
/check/pytest:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ################################################################################
4 | # Runs pytest on the repository.
5 | #
6 | # Usage:
7 | # check/pytest [--flags for pytest]
8 | #
9 | ################################################################################
10 |
11 | # Get the working directory to the repo root.
12 | thisdir="$(dirname "${BASH_SOURCE[0]}")" || exit $?
13 | topdir="$(git -C "${thisdir}" rev-parse --show-toplevel)" || exit $?
14 | cd "${topdir}" || exit $?
15 |
16 | # Run in parallel by default. Pass the `-n0` option for a single-process run.
17 | # (the last `-n` option wins)
18 | PYTEST_ARGS=( "-n=auto" "$@" )
19 |
20 | pytest "${PYTEST_ARGS[@]}" qualtran/
21 | RESULT=$?
22 |
23 | exit "$RESULT"
24 |
--------------------------------------------------------------------------------
/qualtran/bloqs/chemistry/ising/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | from .hamiltonian import get_1d_ising_hamiltonian, get_1d_ising_lcu_coeffs, get_1d_ising_pauli_terms
16 |
--------------------------------------------------------------------------------
/check/mypy-dev-tools:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ################################################################################
4 | # Runs mypy on the dev_tools/ folder using a preconfigured mypy.ini file.
5 | #
6 | # Usage:
7 | # check/mypy-dev-tool [--flags]
8 | ################################################################################
9 |
10 | # Get the working directory to the repo root.
11 | thisdir="$(dirname "${BASH_SOURCE[0]}")" || exit $?
12 | topdir="$(git -C "${thisdir}" rev-parse --show-toplevel)" || exit $?
13 | cd "${topdir}" || exit $?
14 |
15 | CONFIG_FILE='mypy.ini'
16 |
17 | echo -e -n "\033[31m"
18 | mypy --config-file=dev_tools/conf/$CONFIG_FILE --no-namespace-packages "$@" dev_tools/
19 | result=$?
20 | echo -e -n "\033[0m"
21 |
22 | exit ${result}
23 |
--------------------------------------------------------------------------------
/qualtran/rotation_synthesis/relative_norm/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2025 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 | from qualtran.rotation_synthesis.relative_norm._clifford_t import CliffordTRelativeNormSolver
16 |
--------------------------------------------------------------------------------
/.github/problem-matchers/pylint.json:
--------------------------------------------------------------------------------
1 | {
2 | "problemMatcher": [
3 | {
4 | "owner": "pylint-error",
5 | "severity": "error",
6 | "pattern": [
7 | {
8 | "regexp": "^(.+):(\\d+):(\\d+):\\s(([EF]\\d{4}):\\s.+)$",
9 | "file": 1,
10 | "line": 2,
11 | "column": 3,
12 | "message": 4,
13 | "code": 5
14 | }
15 | ]
16 | },
17 | {
18 | "owner": "pylint-warning",
19 | "severity": "warning",
20 | "pattern": [
21 | {
22 | "regexp": "^(.+):(\\d+):(\\d+):\\s(([CRW]\\d{4}):\\s.+)$",
23 | "file": 1,
24 | "line": 2,
25 | "column": 3,
26 | "message": 4,
27 | "code": 5
28 | }
29 | ]
30 | }
31 | ]
32 | }
33 |
--------------------------------------------------------------------------------
/check/pytest-dev-tools:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ################################################################################
4 | # Runs pytest on the dev_tools/ folder.
5 | #
6 | # Usage:
7 | # check/pytest-dev-tools [--flags for pytest]
8 | #
9 | ################################################################################
10 |
11 | # Get the working directory to the repo root.
12 | thisdir="$(dirname "${BASH_SOURCE[0]}")" || exit $?
13 | topdir="$(git -C "${thisdir}" rev-parse --show-toplevel)" || exit $?
14 | cd "${topdir}" || exit $?
15 |
16 | # Run in parallel by default. Pass the `-n0` option for a single-process run.
17 | # (the last `-n` option wins)
18 | PYTEST_ARGS=( "-n=auto" "$@" )
19 |
20 | pytest "${PYTEST_ARGS[@]}" dev_tools/
21 | RESULT=$?
22 |
23 | exit "$RESULT"
24 |
--------------------------------------------------------------------------------
/dev_tools/build-reference-docs.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | from qualtran_dev_tools.reference_docs import build_reference_docs
16 |
17 | if __name__ == '__main__':
18 | build_reference_docs()
19 |
--------------------------------------------------------------------------------
/qualtran/bloqs/arithmetic/lists/__init__.py:
--------------------------------------------------------------------------------
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 | from .has_duplicates import HasDuplicates
15 | from .sort_in_place import SortInPlace
16 | from .symmetric_difference import SymmetricDifference
17 |
--------------------------------------------------------------------------------
/qualtran/bloqs/arithmetic/trigonometric/__init__.py:
--------------------------------------------------------------------------------
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 | from qualtran.bloqs.arithmetic.trigonometric.arcsin import ArcSin
15 | from qualtran.bloqs.arithmetic.trigonometric.arctan import ArcTan
16 |
--------------------------------------------------------------------------------
/qualtran/bloqs/chemistry/sf/select_bloq_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | from qualtran.bloqs.chemistry.sf.select_bloq import _select
15 |
16 |
17 | def test_select(bloq_autotester):
18 | bloq_autotester(_select)
19 |
--------------------------------------------------------------------------------
/qualtran/protos/annotations.proto:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2023 Google LLC
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | https://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | syntax = "proto3";
18 |
19 | package qualtran;
20 |
21 | message TComplexity {
22 | int64 clifford = 1;
23 | int64 rotations = 2;
24 | int64 t = 3;
25 | }
--------------------------------------------------------------------------------
/qualtran/bloqs/chemistry/thc/select_bloq_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | from qualtran.bloqs.chemistry.thc.select_bloq import _thc_sel
16 |
17 |
18 | def test_thc_uniform_prep(bloq_autotester):
19 | bloq_autotester(_thc_sel)
20 |
--------------------------------------------------------------------------------
/qualtran/bloqs/qft/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | from .approximate_qft import ApproximateQFT
15 | from .qft_phase_gradient import QFTPhaseGradient
16 | from .qft_text_book import QFTTextBook
17 | from .two_bit_ffft import TwoBitFFFT
18 |
--------------------------------------------------------------------------------
/qualtran/rotation_synthesis/channels/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2025 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 | from qualtran.rotation_synthesis.channels._channel import (
16 | Channel,
17 | ProbabilisticChannel,
18 | ProjectiveChannel,
19 | UnitaryChannel,
20 | )
21 |
--------------------------------------------------------------------------------
/dev_tools/templates/function.jinja:
--------------------------------------------------------------------------------
1 | {% extends "templates/page.jinja" %}
2 |
3 | {#----------------------------------------------------------------------------#}
4 |
5 | {% block header %}
6 | # {{page_info.short_name}}
7 |
8 | {% endblock header%}
9 |
10 | {#----------------------------------------------------------------------------#}
11 |
12 | {% block metadata %}
13 | {{ builder.top_source_link() }}
14 |
15 | {{ page_info.doc.brief }}
16 |
17 | {% if page_info.header %}
18 |
19 |
20 | {{ page_info.header -}}
21 | {% endif %}
22 |
23 | {{ builder.build_collapsable_aliases() -}}
24 | {% endblock metadata %}
25 |
26 | {#----------------------------------------------------------------------------#}
27 |
28 | {% block body %}
29 | {% if page_info.signature %}
30 | {{ builder.build_signature() }}
31 | {% endif %}
32 | {{ super() -}}
33 | {% endblock %}
34 |
--------------------------------------------------------------------------------
/qualtran/bloqs/chemistry/trotter/grid_ham/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | """Bloqs for Trotter simulation of the real space grid Hamiltonian."""
15 |
16 | from .kinetic import KineticEnergy
17 | from .potential import PairPotential, PotentialEnergy
18 |
--------------------------------------------------------------------------------
/qualtran/rotation_synthesis/rings/_test_utils.py:
--------------------------------------------------------------------------------
1 | # Copyright 2025 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 | # fmt: off
16 | PRIMES_LESS_THAN_100 = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47,\
17 | 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
18 | # fmt: on
19 |
--------------------------------------------------------------------------------
/qualtran/bloqs/arithmetic/conversions/__init__.py:
--------------------------------------------------------------------------------
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 | from .contiguous_index import ToContiguousIndex
15 | from .ones_complement_to_twos_complement import SignedIntegerToTwosComplement
16 | from .sign_extension import SignExtend, SignTruncate
17 |
--------------------------------------------------------------------------------
/qualtran/surface_code/physical_cost_model_test.py:
--------------------------------------------------------------------------------
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 | import pytest
15 |
16 | import qualtran.testing as qlt_testing
17 |
18 |
19 | @pytest.mark.notebook
20 | def test_notebook():
21 | qlt_testing.execute_notebook('physical_cost_model')
22 |
--------------------------------------------------------------------------------
/dev_tools/requirements/deps/runtime.txt:
--------------------------------------------------------------------------------
1 | # core dependencies
2 | attrs>=23.2.0
3 | cachetools>=5.3
4 | networkx
5 | numpy>=1.26,<3.0
6 | sympy
7 | cirq-core~=1.4
8 | fxpmath
9 | galois
10 |
11 | # qualtran/testing.py
12 | nbconvert
13 | nbformat
14 |
15 | # drawing
16 | notebook
17 | pydot
18 | ipython
19 | matplotlib
20 | ipywidgets
21 | plotly
22 |
23 | # ui
24 | dash
25 |
26 | # quimb simulation
27 | quimb
28 |
29 | # qsharp resource estimator interop
30 | qsharp
31 | qsharp-widgets
32 |
33 | # qref bartiq interop
34 | qref==0.11.0
35 | bartiq==0.12.1
36 |
37 | # pyzx interop
38 | pyzx
39 |
40 | # Pennylane interop
41 | pennylane
42 |
43 | # serialization
44 | protobuf
45 |
46 | # typing
47 | typing_extensions>=4.10.0
48 |
49 | # rotation_synthesis
50 | mpmath
51 |
52 | # Note: use `pipreqs` to generate a list of dependencies based on the imports in our files.
53 |
--------------------------------------------------------------------------------
/qualtran/bloqs/block_encoding/block_encoding_base_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 pytest
16 |
17 | from qualtran.testing import execute_notebook
18 |
19 |
20 | @pytest.mark.notebook
21 | def test_notebook():
22 | execute_notebook('block_encoding')
23 |
--------------------------------------------------------------------------------
/qualtran/bloqs/chemistry/pbc/first_quantization/prepare_zeta_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | from qualtran.bloqs.chemistry.pbc.first_quantization.prepare_zeta import _prepare_zeta
15 |
16 |
17 | def test_prepare_zeta(bloq_autotester):
18 | bloq_autotester(_prepare_zeta)
19 |
--------------------------------------------------------------------------------
/qualtran/rotation_synthesis/rings/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2025 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 | """A sub-package representing the rings used in rotation synthesis."""
16 |
17 | from qualtran.rotation_synthesis.rings._zsqrt2 import ZSqrt2
18 | from qualtran.rotation_synthesis.rings._zw import ZW
19 |
--------------------------------------------------------------------------------
/dev_tools/build-reference-docs-2.py:
--------------------------------------------------------------------------------
1 | # Copyright 2025 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 | from qualtran_dev_tools.git_tools import get_git_root
16 | from qualtran_dev_tools.make_reference_docs import make_reference_docs
17 |
18 | if __name__ == "__main__":
19 | make_reference_docs(get_git_root())
20 |
--------------------------------------------------------------------------------
/qualtran/bloqs/chemistry/thc/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | """SELECT and PREPARE for the second quantized Tensor Hypercontracted (THC) chemistry Hamtiltonian.
15 | """
16 |
17 | from .prepare import PrepareTHC, UniformSuperpositionTHC
18 | from .select_bloq import SelectTHC
19 |
--------------------------------------------------------------------------------
/qualtran/protos/ec_point.proto:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2024 Google LLC
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 | https://www.apache.org/licenses/LICENSE-2.0
7 | Unless required by applicable law or agreed to in writing, software
8 | distributed under the License is distributed on an "AS IS" BASIS,
9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 | See the License for the specific language governing permissions and
11 | limitations under the License.
12 | */
13 |
14 | syntax = "proto3";
15 |
16 | import "qualtran/protos/args.proto";
17 |
18 | package qualtran;
19 |
20 | message ECPoint {
21 | IntOrSympy x = 1;
22 | IntOrSympy y = 2;
23 | IntOrSympy mod = 3;
24 | optional IntOrSympy curve_a = 4;
25 | }
26 |
--------------------------------------------------------------------------------
/dev_tools/qualtran_dev_tools/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | """Python functionality to support development of Qualtran.
16 |
17 | Modules in this package should provide library functionality (not scripts). Scripts
18 | can import this functionality from the parent (dev_tools/) directory.
19 | """
20 |
--------------------------------------------------------------------------------
/qualtran/bloqs/for_testing/casting_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 qualtran.testing as qlt_testing
16 | from qualtran.bloqs.for_testing.casting import TestCastToFrom
17 |
18 |
19 | def test_casting():
20 | cast = TestCastToFrom()
21 | qlt_testing.assert_valid_bloq_decomposition(cast)
22 |
--------------------------------------------------------------------------------
/qualtran/protos/ctrl_spec.proto:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2024 Google LLC
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | https://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | syntax = "proto3";
18 |
19 | import "qualtran/protos/data_types.proto";
20 | import "qualtran/protos/args.proto";
21 |
22 | package qualtran;
23 |
24 | message CtrlSpec {
25 | repeated QDataType qdtypes = 1;
26 | repeated NDArray cvs = 2;
27 | }
28 |
--------------------------------------------------------------------------------
/qualtran/simulation/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | """Simulators for quantum programs.
16 |
17 | This module includes `qualtran.simulation.classical_sim` for basis state simulation of
18 | classical-reversible bloqs and `qualtran.simulation.tensor` for Quimb-based tensor network
19 | contraction.
20 | """
21 |
--------------------------------------------------------------------------------
/qualtran/surface_code/msft_resource_estimator_interop_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | import pytest
15 |
16 | import qualtran.testing as qlt_testing
17 |
18 |
19 | @pytest.mark.notebook
20 | def test_msft_resource_estimator_interop_notebook():
21 | qlt_testing.execute_notebook('msft_resource_estimator_interop')
22 |
--------------------------------------------------------------------------------
/qualtran/bloqs/multiplexers/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | r"""Multiplexed Bloqs that can be used to apply a coherent "for-loop" via unary iteration.
16 |
17 | Unary iteration can be used to implement unitaries of the form
18 |
19 | $$
20 | U = \sum_{l=0}^{2^n-1} U_{l}|l\rangle \langle l|
21 | $$
22 | """
23 |
--------------------------------------------------------------------------------
/qualtran/bloqs/bookkeeping/arbitrary_clifford_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 subprocess
16 |
17 | import pytest
18 |
19 |
20 | @pytest.mark.slow
21 | def test_no_circular_import():
22 | subprocess.check_call(
23 | ['python', '-c', 'from qualtran.bloqs.bookkeeping import arbitrary_clifford']
24 | )
25 |
--------------------------------------------------------------------------------
/qualtran/bloqs/for_testing/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | from .atom import TestAtom, TestTwoBitOp
16 | from .casting import TestCastToFrom
17 | from .many_registers import TestMultiRegister
18 | from .with_call_graph import TestBloqWithCallGraph
19 | from .with_decomposition import TestParallelCombo, TestSerialCombo
20 |
--------------------------------------------------------------------------------
/qualtran/bloqs/gf_poly_arithmetic/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2025 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 |
16 | from qualtran.bloqs.gf_poly_arithmetic.gf2_poly_add import GF2PolyAdd
17 | from qualtran.bloqs.gf_poly_arithmetic.gf2_poly_add_k import GF2PolyAddK
18 | from qualtran.bloqs.gf_poly_arithmetic.gf_poly_split_and_join import GFPolyJoin, GFPolySplit
19 |
--------------------------------------------------------------------------------
/qualtran/bloqs/chemistry/pbc/first_quantization/prepare_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | from qualtran.bloqs.chemistry.pbc.first_quantization.prepare import (
15 | UniformSuperpostionIJFirstQuantization,
16 | )
17 |
18 |
19 | def test_uniform_super_position_ij():
20 | prep = UniformSuperpostionIJFirstQuantization(eta=10, num_bits_rot_aa=8)
21 |
--------------------------------------------------------------------------------
/qualtran/bloqs/data_loading/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | """Bloqs to load classical data in a quantum register"""
16 |
17 | from qualtran.bloqs.data_loading.qroam_clean import QROAMClean, QROAMCleanAdjoint
18 | from qualtran.bloqs.data_loading.qrom import QROM
19 | from qualtran.bloqs.data_loading.select_swap_qrom import SelectSwapQROM
20 |
--------------------------------------------------------------------------------
/qualtran/bloqs/cryptography/ecc/ec_phase_estimate_r_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | from qualtran.bloqs.cryptography.ecc.ec_phase_estimate_r import _ec_pe, _ec_pe_small
16 |
17 |
18 | def test_ec_pe(bloq_autotester):
19 | bloq_autotester(_ec_pe)
20 |
21 |
22 | def test_ec_pe_small(bloq_autotester):
23 | bloq_autotester(_ec_pe_small)
24 |
--------------------------------------------------------------------------------
/qualtran/bloqs/mod_arithmetic/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | from .mod_addition import CModAdd, CModAddK, CtrlScaleModAdd, ModAdd, ModAddK
16 | from .mod_division import KaliskiModInverse
17 | from .mod_multiplication import CModMulK, DirtyOutOfPlaceMontgomeryModMul, ModDbl
18 | from .mod_subtraction import CModNeg, CModSub, ModNeg, ModSub
19 |
--------------------------------------------------------------------------------
/qualtran/bloqs/swap_network/__init__.py:
--------------------------------------------------------------------------------
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 | """Functionality for moving data between registers (swapping)."""
15 |
16 | from qualtran.bloqs.swap_network.cswap_approx import CSwapApprox
17 | from qualtran.bloqs.swap_network.multiplexed_cswap import MultiplexedCSwap
18 | from qualtran.bloqs.swap_network.swap_with_zero import SwapWithZero
19 |
--------------------------------------------------------------------------------
/qualtran/_infra/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | # ------------------------------------------------------------------------------
16 | # Note to intrepid developers: everything under _infra/ is re-exported in the
17 | # top-level qualtran/__init__.py
18 | # ------------------------------------------------------------------------------
19 |
--------------------------------------------------------------------------------
/pyproject.toml:
--------------------------------------------------------------------------------
1 | [tool.black]
2 | line-length = 100
3 | target_version = ['py39', 'py310', 'py311', 'py312']
4 | skip-string-normalization = true
5 | skip-magic-trailing-comma = true
6 | exclude = "qualtran/protos/*"
7 |
8 | [tool.isort]
9 | profile = 'black'
10 | order_by_type = false
11 | line_length = 100
12 | remove_redundant_aliases = true
13 | skip_glob = ["qualtran/protos/*"]
14 |
15 | [tool.pytest.ini_options]
16 | filterwarnings = [
17 | 'ignore::DeprecationWarning:quimb.linalg.approx_spectral:',
18 | 'ignore:.*standard platformdirs.*:DeprecationWarning:jupyter_client.*'
19 | ]
20 | # we define classes like TestBloq etc. which pytest tries to collect,
21 | # so if you really want to collect a class as a test use '*TestSuite'.
22 | # (but please stick to the convention of test_* functions)
23 | python_classes = '*TestSuite'
24 | addopts = '--strict-markers'
25 | markers = [
26 | "slow: slow tests.",
27 | "notebook: unit tests that execute a notebook."
28 | ]
29 |
--------------------------------------------------------------------------------
/qualtran/bloqs/chemistry/trotter/grid_ham/trotter_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | import pytest
15 |
16 | import qualtran.testing as qlt_testing
17 |
18 |
19 | @pytest.mark.notebook
20 | def test_costing_notebook():
21 | qlt_testing.execute_notebook('trotter_costs')
22 |
23 |
24 | @pytest.mark.notebook
25 | def test_notebook():
26 | qlt_testing.execute_notebook('trotter')
27 |
--------------------------------------------------------------------------------
/dev_tools/requirements/Dockerfile:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | FROM python:3.10
16 |
17 | WORKDIR /pip-compile
18 |
19 | # Step 0: install pip-tools
20 | COPY envs/pip-tools.env.txt ./
21 | RUN pip install -r pip-tools.env.txt
22 |
23 | # Step 1: compile a complete & consistent environment with all dependencies
24 | COPY deps/ ./deps/
25 | COPY re-pip-compile.sh ./
26 | RUN bash re-pip-compile.sh
--------------------------------------------------------------------------------
/qualtran/simulation/tensor/_flattening_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | from qualtran.bloqs.basic_gates import CNOT
15 | from qualtran.bloqs.mcmt.and_bloq import MultiAnd
16 | from qualtran.simulation.tensor import bloq_has_custom_tensors
17 |
18 |
19 | def test_bloq_has_custom_tensors():
20 | assert bloq_has_custom_tensors(CNOT())
21 | assert not bloq_has_custom_tensors(MultiAnd((1,) * 5))
22 |
--------------------------------------------------------------------------------
/qualtran/bloqs/mcmt/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | from qualtran.bloqs.mcmt.and_bloq import And, MultiAnd
16 | from qualtran.bloqs.mcmt.controlled_via_and import ControlledViaAnd
17 | from qualtran.bloqs.mcmt.ctrl_spec_and import CtrlSpecAnd
18 | from qualtran.bloqs.mcmt.multi_control_pauli import MultiControlX, MultiControlZ
19 | from qualtran.bloqs.mcmt.multi_target_cnot import MultiTargetCNOT
20 |
--------------------------------------------------------------------------------
/qualtran/bloqs/cryptography/ecc/find_ecc_private_key_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | import pytest
15 |
16 | import qualtran.testing as qlt_testing
17 | from qualtran.bloqs.cryptography.ecc.find_ecc_private_key import _ecc
18 |
19 |
20 | def test_ecc(bloq_autotester):
21 | bloq_autotester(_ecc)
22 |
23 |
24 | @pytest.mark.notebook
25 | def test_notebook():
26 | qlt_testing.execute_notebook('ecc')
27 |
--------------------------------------------------------------------------------
/qualtran/bloqs/phase_estimation/kaiser_window_state_test.py:
--------------------------------------------------------------------------------
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 | from qualtran.bloqs.phase_estimation.kaiser_window_state import (
16 | _kaiser_window_state_small,
17 | _kaiser_window_state_symbolic,
18 | )
19 |
20 |
21 | def test_kaiser_window_state_auto(bloq_autotester):
22 | bloq_autotester(_kaiser_window_state_small)
23 | bloq_autotester(_kaiser_window_state_symbolic)
24 |
--------------------------------------------------------------------------------
/dev_tools/requirements/envs/pip-tools.env.txt:
--------------------------------------------------------------------------------
1 | #
2 | # This file is autogenerated by pip-compile with Python 3.10
3 | # by the following command:
4 | #
5 | # pip-compile --constraint=envs/dev.env.txt --output-file=envs/pip-tools.env.txt deps/pip-tools.txt
6 | #
7 | build==1.3.0
8 | # via
9 | # -c envs/dev.env.txt
10 | # pip-tools
11 | click==8.3.0
12 | # via
13 | # -c envs/dev.env.txt
14 | # pip-tools
15 | packaging==25.0
16 | # via
17 | # -c envs/dev.env.txt
18 | # build
19 | pip-tools==7.5.1
20 | # via
21 | # -c envs/dev.env.txt
22 | # -r deps/pip-tools.txt
23 | pyproject-hooks==1.2.0
24 | # via
25 | # -c envs/dev.env.txt
26 | # build
27 | # pip-tools
28 | tomli==2.3.0
29 | # via
30 | # -c envs/dev.env.txt
31 | # build
32 | # pip-tools
33 | wheel==0.45.1
34 | # via
35 | # -c envs/dev.env.txt
36 | # pip-tools
37 |
38 | # The following packages are considered to be unsafe in a requirements file:
39 | # pip
40 | # setuptools
41 |
--------------------------------------------------------------------------------
/qualtran/protos/args.proto:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2023 Google LLC
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | https://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | syntax = "proto3";
18 |
19 | package qualtran;
20 |
21 | message IntOrSympy {
22 | oneof val {
23 | int64 int_val = 1;
24 | string sympy_expr = 2;
25 | }
26 | }
27 |
28 | message NDArray {
29 | // A Numpy array serialized as bytes using np.save() / np.load().
30 | bytes ndarray = 1;
31 | }
32 |
33 | message Complex {
34 | float real = 1;
35 | float imag = 2;
36 | }
--------------------------------------------------------------------------------
/qualtran/rotation_synthesis/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2025 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 | from qualtran.rotation_synthesis._math_config import NumpyConfig, with_dps
16 | from qualtran.rotation_synthesis.matrix import to_cirq, to_quirk, to_sequence
17 | from qualtran.rotation_synthesis.protocols import (
18 | diagonal_unitary_approx,
19 | fallback_protocol,
20 | magnitude_approx,
21 | mixed_diagonal_protocol,
22 | mixed_fallback_protocol,
23 | )
24 |
--------------------------------------------------------------------------------
/qualtran/bloqs/chemistry/trotter/ising/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | r"""Bloqs implementing Trotter steps for the 1D Ising model under periodic boundary conditions.
15 |
16 | The Ising model is given as
17 | $$
18 | H = -J\sum_{k=0}^{L-1}\sigma_{k}^{Z}\sigma_{(k+1)}^{Z} - \Gamma\sum_{k=0}^{L-1}\sigma_{k}^{X}
19 | $$
20 |
21 | where $J$ and $\Gamma$ are coupling parameters.
22 | """
23 |
24 | from .unitaries import IsingXUnitary, IsingZZUnitary
25 |
--------------------------------------------------------------------------------
/qualtran/bloqs/chemistry/sparse/select_bloq_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | from qualtran.bloqs.chemistry.sparse.select_bloq import _sel_sparse
16 |
17 |
18 | def test_prep_inner(bloq_autotester):
19 | bloq_autotester(_sel_sparse)
20 |
21 |
22 | def test_decompose_bloq_counts():
23 | sel = _sel_sparse()
24 | cost_decomp = sel.decompose_bloq().call_graph()[1]
25 | cost_call = sel.call_graph()[1]
26 | assert cost_call == cost_decomp
27 |
--------------------------------------------------------------------------------
/qualtran/exception/__init__.py:
--------------------------------------------------------------------------------
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 | """Qualtran exceptions that may be raised by the framework."""
16 |
17 | from qualtran._infra.bloq import DecomposeNotImplementedError, DecomposeTypeError
18 | from qualtran._infra.composite_bloq import BloqError, DidNotFlattenAnythingError
19 |
20 | __all__ = [
21 | 'DecomposeTypeError',
22 | 'DecomposeNotImplementedError',
23 | 'BloqError',
24 | 'DidNotFlattenAnythingError',
25 | ]
26 |
--------------------------------------------------------------------------------
/qualtran/bloqs/for_testing/many_registers_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 qualtran.testing as qlt_testing
16 | from qualtran.bloqs.for_testing.many_registers import TestMultiRegister
17 |
18 |
19 | def test_test_multi_register():
20 | bloq = TestMultiRegister()
21 | assert [r.name for r in bloq.signature] == ['xx', 'yy', 'zz']
22 | assert sum(r.total_bits() for r in bloq.signature) == 12
23 |
24 | qlt_testing.assert_valid_bloq_decomposition(bloq)
25 |
--------------------------------------------------------------------------------
/qualtran/bloqs/phase_estimation/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | from qualtran.bloqs.phase_estimation.kaiser_window_state import KaiserWindowState
16 | from qualtran.bloqs.phase_estimation.lp_resource_state import LPResourceState
17 | from qualtran.bloqs.phase_estimation.qpe_window_state import RectangularWindowState
18 | from qualtran.bloqs.phase_estimation.qubitization_qpe import QubitizationQPE
19 | from qualtran.bloqs.phase_estimation.text_book_qpe import TextbookQPE
20 |
--------------------------------------------------------------------------------
/qualtran/symbolics/types_test.py:
--------------------------------------------------------------------------------
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 pytest
16 | import sympy
17 |
18 | from qualtran.symbolics import is_symbolic, Shaped, slen
19 |
20 |
21 | @pytest.mark.parametrize(
22 | "shape",
23 | [(4,), (1, 2), (1, 2, 3), (sympy.Symbol('n'),), (sympy.Symbol('n'), sympy.Symbol('m'), 100)],
24 | )
25 | def test_shaped(shape: tuple[int, ...]):
26 | shaped = Shaped(shape=shape)
27 | assert is_symbolic(shaped)
28 | assert slen(shaped) == shape[0]
29 |
--------------------------------------------------------------------------------
/qualtran/bloqs/chemistry/trotter/grid_ham/qvr_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | import pytest
15 |
16 | from qualtran.bloqs.chemistry.trotter.grid_ham.qvr import _qvr, QuantumVariableRotation
17 |
18 |
19 | def test_kinetic_energy(bloq_autotester):
20 | bloq_autotester(_qvr)
21 |
22 |
23 | @pytest.mark.parametrize('bitsize', [8, 16, 32])
24 | def test_qvr_t_complexity(bitsize: int):
25 | bloq = QuantumVariableRotation(bitsize)
26 | assert bloq.t_complexity().rotations == bitsize
27 |
--------------------------------------------------------------------------------
/qualtran/bloqs/cryptography/rsa/rsa_phase_estimate_test.py:
--------------------------------------------------------------------------------
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 pytest
16 |
17 | import qualtran.testing as qlt_testing
18 | from qualtran.bloqs.cryptography.rsa.rsa_phase_estimate import _rsa_pe, _rsa_pe_small
19 |
20 |
21 | @pytest.mark.parametrize('bloq', [_rsa_pe_small, _rsa_pe])
22 | def test_rsa_pe(bloq_autotester, bloq):
23 | bloq_autotester(bloq)
24 |
25 |
26 | @pytest.mark.notebook
27 | def test_notebook():
28 | qlt_testing.execute_notebook('rsa')
29 |
--------------------------------------------------------------------------------
/qualtran/bloqs/state_preparation/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | from qualtran.bloqs.state_preparation.prepare_uniform_superposition import (
16 | PrepareUniformSuperposition,
17 | )
18 | from qualtran.bloqs.state_preparation.state_preparation_alias_sampling import (
19 | SparseStatePreparationAliasSampling,
20 | StatePreparationAliasSampling,
21 | )
22 | from qualtran.bloqs.state_preparation.state_preparation_via_rotation import (
23 | StatePreparationViaRotations,
24 | )
25 |
--------------------------------------------------------------------------------
/dev_tools/qualtran_dev_tools/git_tools.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 subprocess
16 | from pathlib import Path
17 |
18 |
19 | def get_git_root() -> Path:
20 | """Get the root git repository path."""
21 | cp = subprocess.run(
22 | ['git', 'rev-parse', '--show-toplevel'],
23 | capture_output=True,
24 | universal_newlines=True,
25 | check=True,
26 | )
27 | path = Path(cp.stdout.strip()).absolute()
28 | assert path.exists()
29 | return path
30 |
--------------------------------------------------------------------------------
/qualtran/bloqs/arithmetic/trigonometric/arcsin_test.py:
--------------------------------------------------------------------------------
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 numpy as np
16 |
17 | from qualtran.bloqs.arithmetic.trigonometric.arcsin import _arcsin
18 |
19 |
20 | def test_arcsin(bloq_autotester):
21 | bloq_autotester(_arcsin)
22 |
23 |
24 | def test_arcsin_classical():
25 | bloq = _arcsin()
26 | x = int(1 / np.sqrt(2) * 2**10)
27 | result_out = int(np.arcsin(1 / np.sqrt(2)) * 2**10)
28 | assert bloq.call_classically(x=x, result=0) == (x, result_out)
29 |
--------------------------------------------------------------------------------
/qualtran/cirq_interop/decompose_protocol_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 cirq
16 |
17 | from qualtran.cirq_interop.decompose_protocol import _decompose_once_considering_known_decomposition
18 |
19 |
20 | def test_known_decomposition_empty_unitary():
21 | class DecomposeEmptyList(cirq.testing.SingleQubitGate):
22 | def _decompose_(self, _):
23 | return []
24 |
25 | gate = DecomposeEmptyList()
26 | assert _decompose_once_considering_known_decomposition(gate) == []
27 |
--------------------------------------------------------------------------------
/qualtran/bloqs/optimization/k_xor_sat/__init__.py:
--------------------------------------------------------------------------------
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 | from .kikuchi_adjacency_list import KikuchiNonZeroIndex
15 | from .kikuchi_adjacency_matrix import KikuchiMatrixEntry
16 | from .kikuchi_block_encoding import KikuchiHamiltonian, KikuchiMatrixEntry, KikuchiNonZeroIndex
17 | from .kikuchi_guiding_state import GuidingState, SimpleGuidingState
18 | from .kxor_instance import Constraint, KXorInstance
19 | from .load_kxor_instance import LoadConstraintScopes, LoadUniqueScopeIndex, PRGAUniqueConstraintRHS
20 |
--------------------------------------------------------------------------------
/qualtran/serialization/annotations_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | from qualtran.cirq_interop.t_complexity_protocol import TComplexity
16 | from qualtran.serialization import annotations
17 |
18 |
19 | def test_t_complexity_to_proto():
20 | t_complexity = TComplexity(t=10, clifford=100, rotations=1000)
21 | proto = annotations.t_complexity_to_proto(t_complexity)
22 | assert (proto.t, proto.clifford, proto.rotations) == (10, 100, 1000)
23 | assert annotations.t_complexity_from_proto(proto) == t_complexity
24 |
--------------------------------------------------------------------------------
/qualtran/cirq_interop/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | # isort:skip_file
15 |
16 | """Bi-directional interop between Qualtran & Cirq."""
17 |
18 | from ._cirq_to_bloq import (
19 | CirqQuregT,
20 | CirqGateAsBloq,
21 | CirqGateAsBloqBase,
22 | cirq_optree_to_cbloq,
23 | cirq_gate_to_bloq,
24 | decompose_from_cirq_style_method,
25 | )
26 |
27 | from ._bloq_to_cirq import BloqAsCirqGate
28 |
29 | from .._infra.gate_with_registers import get_named_qubits, merge_qubits
30 |
31 | assert [get_named_qubits, merge_qubits]
32 |
--------------------------------------------------------------------------------
/qualtran/bloqs/bookkeeping/always_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2025 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 | import pytest
15 |
16 | from qualtran.bloqs.bookkeeping.always import _always_and, Always
17 | from qualtran.bloqs.for_testing import TestAtom
18 | from qualtran.testing import execute_notebook
19 |
20 |
21 | def test_example(bloq_autotester):
22 | bloq_autotester(_always_and)
23 |
24 |
25 | def test_always():
26 | bloq = Always(TestAtom())
27 | assert bloq.controlled() == bloq
28 |
29 |
30 | @pytest.mark.notebook
31 | def test_notebook():
32 | execute_notebook('always')
33 |
--------------------------------------------------------------------------------
/qualtran/bloqs/for_testing/costing_test.py:
--------------------------------------------------------------------------------
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 | from qualtran.bloqs.for_testing.costing import make_example_costing_bloqs
16 | from qualtran.resource_counting import format_call_graph_debug_text
17 |
18 |
19 | def test_costing_bloqs():
20 | algo = make_example_costing_bloqs()
21 | g, _ = algo.call_graph()
22 | assert (
23 | format_call_graph_debug_text(g)
24 | == """\
25 | Algo -- 2 -> Func1
26 | Algo -- 1 -> Func2
27 | Func1 -- 10 -> H
28 | Func1 -- 10 -> T
29 | Func1 -- 10 -> T†
30 | Func2 -- 100 -> Toffoli"""
31 | )
32 |
--------------------------------------------------------------------------------
/qualtran/bloqs/reflections/prepare_identity_test.py:
--------------------------------------------------------------------------------
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 | from qualtran import Signature
15 | from qualtran.bloqs.basic_gates import Identity
16 | from qualtran.bloqs.reflections.prepare_identity import _prepare_identity, PrepareIdentity
17 |
18 |
19 | def test_prepare_identity(bloq_autotester):
20 | bloq_autotester(_prepare_identity)
21 |
22 |
23 | def test_prepare_identity_call_graph():
24 | bloq = PrepareIdentity(tuple(Signature.build(a=4, b=4, c=5)))
25 | _, sigma = bloq.call_graph()
26 | assert sigma == {Identity(4): 2, Identity(5): 1}
27 |
--------------------------------------------------------------------------------
/qualtran/bloqs/chemistry/black_boxes_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | import pytest
15 | from openfermion.resource_estimates.utils import QI, QR
16 |
17 | from qualtran.bloqs.chemistry.black_boxes import get_qroam_cost_clean_ancilla
18 |
19 |
20 | @pytest.mark.parametrize("data_size, bitsize", ((100, 10), (100, 3), (1_000, 13), (1_000_000, 20)))
21 | def test_qroam_factors(data_size, bitsize):
22 | assert get_qroam_cost_clean_ancilla(data_size, bitsize) == QR(data_size, bitsize)[-1]
23 | assert get_qroam_cost_clean_ancilla(data_size, bitsize, adjoint=True) == QI(data_size)[-1]
24 |
--------------------------------------------------------------------------------
/qualtran/bloqs/for_testing/interior_alloc_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | import qualtran.testing as qlt_testing
15 | from qualtran import QAny
16 | from qualtran.bloqs.basic_gates.swap import Swap
17 | from qualtran.bloqs.bookkeeping import Allocate, Free
18 | from qualtran.bloqs.for_testing.interior_alloc import InteriorAlloc
19 |
20 |
21 | def test_interior_alloc():
22 | ia = InteriorAlloc(10)
23 | qlt_testing.assert_valid_bloq_decomposition(ia)
24 | g, counts = ia.call_graph(max_depth=1)
25 | assert counts == {Allocate(QAny(10)): 1, Free(QAny(10)): 1, Swap(10): 2}
26 |
--------------------------------------------------------------------------------
/qualtran/rotation_synthesis/lattice/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2025 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 | """A package that provides methods for integer point enumeration."""
16 |
17 | from qualtran.rotation_synthesis.lattice._geometry import Ellipse, Range, Rectangle
18 | from qualtran.rotation_synthesis.lattice._grid_operators import GridOperator
19 | from qualtran.rotation_synthesis.lattice._ipe import (
20 | enumerate_1d,
21 | enumerate_upright,
22 | get_overall_action,
23 | get_points_from_state,
24 | )
25 | from qualtran.rotation_synthesis.lattice._state import GridOperatorAction, SelingerState
26 |
--------------------------------------------------------------------------------
/qualtran/bloqs/chemistry/trotter/grid_ham/kinetic_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | import pytest
15 |
16 | import qualtran.testing as qlt_testing
17 | from qualtran.bloqs.chemistry.trotter.grid_ham.kinetic import _kinetic_energy, KineticEnergy
18 |
19 |
20 | @pytest.mark.parametrize("nelec, nx", ((2, 10), (6, 8), (8, 12)))
21 | def test_kinetic_bloq(nelec, nx):
22 | ngrid_x = 2 * nx + 1
23 | ke = KineticEnergy(nelec, ngrid_x)
24 | qlt_testing.assert_valid_bloq_decomposition(ke)
25 |
26 |
27 | def test_kinetic_energy(bloq_autotester):
28 | bloq_autotester(_kinetic_energy)
29 |
--------------------------------------------------------------------------------
/dev_tools/templates/page.jinja:
--------------------------------------------------------------------------------
1 | {%- extends 'templates/root.jinja' -%}
2 |
3 | {#----------------------------------------------------------------------------#}
4 |
5 | {% block content %}
6 | {{- self.header() -}}
7 | {{- self.metadata() -}}
8 | {{- self.body() -}}
9 | {% endblock content %}}
10 |
11 | {#----------------------------------------------------------------------------#}
12 |
13 | {% block header %}
14 | {{ builder.get_devsite_headers() }}
15 | # {{page_info.short_name}}
16 |
17 |
18 |
19 | {% endblock header%}
20 |
21 | {#----------------------------------------------------------------------------#}
22 |
23 | {% block metadata %}
24 |
25 | {{ page_info.doc.brief }}
26 |
27 | {{ builder.build_collapsable_aliases() -}}
28 | {% endblock metadata %}
29 |
30 | {#----------------------------------------------------------------------------#}
31 |
32 | {% block body %}
33 |
34 | {{ builder.top_compat() -}}
35 |
36 | {% for part in page_info.doc.docstring_parts %}
37 | {{- builder.format_docstring_part(part) -}}
38 | {% endfor %}
39 | {{ builder.bottom_compat() -}}
40 | {% endblock body %}
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/qualtran/bloqs/optimization/k_xor_sat/kxor_instance_test.py:
--------------------------------------------------------------------------------
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 | import numpy as np
15 | import pytest
16 |
17 | from qualtran.bloqs.optimization.k_xor_sat.kxor_instance import KXorInstance
18 |
19 |
20 | @pytest.mark.slow
21 | @pytest.mark.parametrize("rho", [0, 0.8, 0.9])
22 | def test_max_rhs(rho: float):
23 | rng = np.random.default_rng(402)
24 |
25 | rhs = []
26 | for i in range(100):
27 | inst = KXorInstance.random_instance(n=100, m=1000, k=4, planted_advantage=rho, rng=rng)
28 | rhs.append(inst.max_rhs)
29 |
30 | assert max(rhs) == 2
31 |
--------------------------------------------------------------------------------
/qualtran/protos/registers.proto:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2023 Google LLC
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | https://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | syntax = "proto3";
18 |
19 | import "qualtran/protos/args.proto";
20 | import "qualtran/protos/data_types.proto";
21 |
22 | package qualtran;
23 |
24 | message Register {
25 | // A quantum register.
26 | enum Side {
27 | UNKNOWN = 0;
28 | LEFT = 1;
29 | RIGHT = 2;
30 | THRU = 3;
31 | }
32 | string name = 1;
33 | QDataType dtype = 2;
34 | repeated IntOrSympy shape = 3;
35 | Side side = 4;
36 | }
37 |
38 | message Registers {
39 | // A collection of Registers.
40 | repeated Register registers = 1;
41 | }
--------------------------------------------------------------------------------
/dev_tools/repomix/README.md:
--------------------------------------------------------------------------------
1 | # Qualtran Repomix
2 |
3 | We use the [repomix](https://github.com/yamadashy/repomix) tool to concatenate relevant
4 | context so LLMs can write Qualtran code.
5 |
6 | The repository is too large to naively include everything in the context window, so we're
7 | a little selective. The packed output contains:
8 |
9 | - Reference docs for core modules and subpackages, via markdown. You must first run
10 | `dev_tools/build-reference-docs-2.py`.
11 | - Documentation notebooks (bloq notebooks and concept notebooks), via markdown. You must
12 | first run `dev_tools/execute-notebooks.py --output-md`.
13 | - Selected `*.py` files in `qualtran/bloqs/**/*.py`. The list is enumerated in
14 | `repomix-driver.py`.
15 |
16 | After ensuring the docs are rendered in markdown format, run `python repomix-driver.py`. This
17 | will run the repomix program, which requires Node.js.
18 |
19 |
20 | --------------
21 |
22 | You may want to run `git clean -ndX` (change `n` to `f`) in the `docs/` directory before
23 | running the markdown-export scripts to get a fresh build of the docs. `repomix-driver.py` will
24 | include anything with a `*.md` extension, including any vestigial files.
--------------------------------------------------------------------------------
/qualtran/bloqs/gf_arithmetic/__init__.py:
--------------------------------------------------------------------------------
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 | from qualtran.bloqs.gf_arithmetic.gf2_add_k import GF2AddK
16 | from qualtran.bloqs.gf_arithmetic.gf2_addition import GF2Addition
17 | from qualtran.bloqs.gf_arithmetic.gf2_inverse import GF2Inverse
18 | from qualtran.bloqs.gf_arithmetic.gf2_multiplication import (
19 | BinaryPolynomialMultiplication,
20 | GF2MulK,
21 | GF2Multiplication,
22 | GF2MulViaKaratsuba,
23 | GF2ShiftLeft,
24 | GF2ShiftRight,
25 | MultiplyPolyByOnePlusXk,
26 | )
27 | from qualtran.bloqs.gf_arithmetic.gf2_square import GF2Square
28 |
--------------------------------------------------------------------------------
/qualtran/linalg/matrix_test.py:
--------------------------------------------------------------------------------
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 | import numpy as np
15 | import pytest
16 | from cirq.testing import random_unitary
17 |
18 | from qualtran.linalg.matrix import unitary_distance_ignoring_global_phase
19 |
20 |
21 | @pytest.mark.parametrize("dim", [2, 3])
22 | def test_unitary_distance_zero(dim: int):
23 | rs = np.random.RandomState(1234)
24 | for _ in range(3):
25 | U = random_unitary(dim, random_state=rs)
26 | V = np.exp(1j * rs.random()) * U
27 | d = unitary_distance_ignoring_global_phase(U, V)
28 | np.testing.assert_almost_equal(d, 0)
29 |
--------------------------------------------------------------------------------
/qualtran/resource_counting/_success_prob_test.py:
--------------------------------------------------------------------------------
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 | from qualtran.bloqs.for_testing.costing import CostingBloq
15 | from qualtran.resource_counting import get_cost_cache, get_cost_value, SuccessProb
16 |
17 |
18 | def test_coin_flip():
19 | flip = CostingBloq('CoinFlip', num_qubits=1, static_costs=[(SuccessProb(), 0.5)])
20 | algo = CostingBloq('Algo', num_qubits=0, callees=[(flip, 4)])
21 |
22 | p = get_cost_value(algo, SuccessProb())
23 | assert p == 0.5**4
24 |
25 | costs = get_cost_cache(algo, SuccessProb())
26 | assert costs == {algo: p, flip: 0.5}
27 |
--------------------------------------------------------------------------------
/qualtran/rotation_synthesis/_typing.py:
--------------------------------------------------------------------------------
1 | # Copyright 2025 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 | from typing import Union
16 |
17 | import mpmath
18 | import numpy as np
19 | from typing_extensions import TypeIs
20 |
21 | # mypy has a bug where it doesn't understand numbers.* https://github.com/python/mypy/issues/3186
22 | # So we define our own types
23 | Real = Union[float, np.floating, mpmath.ctx_mp_python.mpf]
24 | Integral = Union[int, np.integer]
25 | Complex = Union[complex, np.complexfloating, mpmath.ctx_mp_python.mpc]
26 |
27 |
28 | def is_int(x) -> TypeIs[Integral]:
29 | return isinstance(x, (int, np.integer))
30 |
--------------------------------------------------------------------------------
/dev_tools/qualtran_dev_tools/all_call_graph_test.py:
--------------------------------------------------------------------------------
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 == []
30 |
--------------------------------------------------------------------------------
/qualtran/bloqs/gf_arithmetic/gf_utils.py:
--------------------------------------------------------------------------------
1 | # Copyright 2025 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 | from typing import Sequence, Union
15 |
16 | from galois import Poly
17 |
18 | from qualtran import QGF
19 | from qualtran.symbolics import is_symbolic, SymbolicInt
20 |
21 |
22 | def qgf_converter(x: Union[QGF, int, Poly, SymbolicInt, Sequence[int]]) -> QGF:
23 | if isinstance(x, QGF):
24 | return x
25 | if isinstance(x, int):
26 | return QGF(2, x)
27 | if is_symbolic(x):
28 | return QGF(2, x)
29 | if isinstance(x, Poly):
30 | return QGF(2, x.degree, x)
31 | p = Poly.Degrees(x)
32 | return QGF(2, p.degree, p)
33 |
--------------------------------------------------------------------------------
/qualtran/bloqs/chemistry/pbc/first_quantization/select_t_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | from qualtran.bloqs.chemistry.pbc.first_quantization.select_t import (
15 | _select_t,
16 | SelectTFirstQuantization,
17 | )
18 | from qualtran.resource_counting import get_cost_value, QECGatesCost
19 |
20 |
21 | def test_select_t(bloq_autotester):
22 | bloq_autotester(_select_t)
23 |
24 |
25 | def test_select_kinetic_t_counts():
26 | num_bits_p = 6
27 | sel = SelectTFirstQuantization(num_bits_p, 10)
28 | toffolis = get_cost_value(sel, QECGatesCost()).total_toffoli_only()
29 | assert toffolis == 5 * (num_bits_p - 1) + 2
30 |
--------------------------------------------------------------------------------
/dev_tools/clean-notebooks.py:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | import argparse
15 | import sys
16 |
17 | from qualtran_dev_tools.clean_notebooks import clean_notebooks
18 | from qualtran_dev_tools.git_tools import get_git_root
19 |
20 |
21 | def parse_args():
22 | p = argparse.ArgumentParser()
23 | p.add_argument('--apply', action=argparse.BooleanOptionalAction, default=False)
24 | args = p.parse_args()
25 |
26 | reporoot = get_git_root()
27 | sourceroot = reporoot / 'qualtran'
28 | n_bad = clean_notebooks(sourceroot, do_clean=args.apply)
29 | sys.exit(n_bad)
30 |
31 |
32 | if __name__ == '__main__':
33 | parse_args()
34 |
--------------------------------------------------------------------------------
/qualtran/drawing/musical_score.html:
--------------------------------------------------------------------------------
1 |
17 |
18 |
19 |
20 |