From 3e8170950dd31528e003a555cbb24b678f8dae6f Mon Sep 17 00:00:00 2001 From: Coull Date: Wed, 11 Mar 2026 12:21:30 -0400 Subject: [PATCH] infra: move to use a pyproject.toml --- .coveragerc | 18 ---- doc/conf.py | 4 +- .../textbook/Quantum_Counting_Algorithm.ipynb | 32 +++--- pyproject.toml | 98 ++++++++++++++++++- setup.cfg | 10 -- setup.py | 70 ------------- .../quantum_counting/quantum_counting.py | 16 +-- .../quantum_counting/test_quantum_counting.py | 6 +- 8 files changed, 112 insertions(+), 142 deletions(-) delete mode 100644 .coveragerc delete mode 100644 setup.cfg delete mode 100644 setup.py diff --git a/.coveragerc b/.coveragerc deleted file mode 100644 index db07fb6e..00000000 --- a/.coveragerc +++ /dev/null @@ -1,18 +0,0 @@ -[run] -parallel = True -branch = True -source = braket.experimental - -[paths] -source = - src/braket - .tox/*/lib/python*/site-packages/braket - -[report] -show_missing = True - -[html] -directory = build/coverage - -[xml] -output = build/coverage/coverage.xml diff --git a/doc/conf.py b/doc/conf.py index 9d1a4460..c1353552 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -2,11 +2,11 @@ import datetime -import pkg_resources +from importlib.metadata import version as pkg_version # Sphinx configuration below. project = "amazon-braket-algorithm-library" -version = pkg_resources.require(project)[0].version +version = pkg_version(project) release = version copyright = f"{datetime.datetime.now().year}, Amazon.com" diff --git a/notebooks/textbook/Quantum_Counting_Algorithm.ipynb b/notebooks/textbook/Quantum_Counting_Algorithm.ipynb index eb6b50d9..25ef0572 100644 --- a/notebooks/textbook/Quantum_Counting_Algorithm.ipynb +++ b/notebooks/textbook/Quantum_Counting_Algorithm.ipynb @@ -204,9 +204,11 @@ "# This phase shift is corrected in get_quantum_counting_results.\n", "theta = 2 * np.arcsin(np.sqrt(len(marked_states) / N))\n", "print(f\"\\nGrover angle theta = {theta:.4f} rad\")\n", - "print(f\"Ideal eigenvalues in solution subspace: \"\n", - " f\"e^(+i*theta) = {np.exp(1j * theta):.4f}, \"\n", - " f\"e^(-i*theta) = {np.exp(-1j * theta):.4f}\")\n", + "print(\n", + " f\"Ideal eigenvalues in solution subspace: \"\n", + " f\"e^(+i*theta) = {np.exp(1j * theta):.4f}, \"\n", + " f\"e^(-i*theta) = {np.exp(-1j * theta):.4f}\"\n", + ")\n", "print(f\"Circuit eigenvalues (with -1 global phase): {np.round(nontrivial, 4)}\")" ] }, @@ -479,17 +481,13 @@ "search_qubits_2 = list(range(n_counting, n_counting + n_search))\n", "\n", "circ_2 = Circuit()\n", - "circ_2 = quantum_counting_circuit(\n", - " circ_2, counting_qubits_2, search_qubits_2, marked_states_2\n", - ")\n", + "circ_2 = quantum_counting_circuit(circ_2, counting_qubits_2, search_qubits_2, marked_states_2)\n", "\n", "device = LocalSimulator()\n", "task_2 = run_quantum_counting(circ_2, device, shots=2000)\n", "\n", "print(f\"Quantum Counting Results (N={N_2}, M={len(marked_states_2)}):\")\n", - "results_2 = get_quantum_counting_results(\n", - " task_2, counting_qubits_2, search_qubits_2, verbose=True\n", - ")\n", + "results_2 = get_quantum_counting_results(task_2, counting_qubits_2, search_qubits_2, verbose=True)\n", "\n", "print(f\"\\nActual M = {len(marked_states_2)}\")\n", "print(f\"Estimated M = {results_2['best_estimate']:.4f}\")" @@ -586,16 +584,12 @@ "search_qubits_3 = list(range(n_counting, n_counting + n_search))\n", "\n", "circ_3 = Circuit()\n", - "circ_3 = quantum_counting_circuit(\n", - " circ_3, counting_qubits_3, search_qubits_3, marked_states_3\n", - ")\n", + "circ_3 = quantum_counting_circuit(circ_3, counting_qubits_3, search_qubits_3, marked_states_3)\n", "\n", "device = LocalSimulator()\n", "task_3 = run_quantum_counting(circ_3, device, shots=1000)\n", "\n", - "results_3 = get_quantum_counting_results(\n", - " task_3, counting_qubits_3, search_qubits_3, verbose=True\n", - ")\n", + "results_3 = get_quantum_counting_results(task_3, counting_qubits_3, search_qubits_3, verbose=True)\n", "\n", "print(\"\\nActual M = 0\")\n", "print(f\"Estimated M = {results_3['best_estimate']:.4f}\")" @@ -650,16 +644,12 @@ "search_qubits_4 = list(range(n_counting, n_counting + n_search))\n", "\n", "circ_4 = Circuit()\n", - "circ_4 = quantum_counting_circuit(\n", - " circ_4, counting_qubits_4, search_qubits_4, marked_states_4\n", - ")\n", + "circ_4 = quantum_counting_circuit(circ_4, counting_qubits_4, search_qubits_4, marked_states_4)\n", "\n", "device = LocalSimulator()\n", "task_4 = run_quantum_counting(circ_4, device, shots=1000)\n", "\n", - "results_4 = get_quantum_counting_results(\n", - " task_4, counting_qubits_4, search_qubits_4, verbose=True\n", - ")\n", + "results_4 = get_quantum_counting_results(task_4, counting_qubits_4, search_qubits_4, verbose=True)\n", "\n", "print(f\"\\nActual M = {N_4}\")\n", "print(f\"Estimated M = {results_4['best_estimate']:.4f}\")" diff --git a/pyproject.toml b/pyproject.toml index 62a87f65..0f3a72e4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,8 +1,96 @@ +[build-system] +requires = ["setuptools>=64", "wheel"] +build-backend = "setuptools.build_meta" + +[project] +name = "amazon-braket-algorithm-library" +dynamic = ["version"] +description = "An open source library of quantum computing algorithms implemented on Amazon Braket" +readme = "README.md" +license = "Apache-2.0" +requires-python = ">= 3.11" +authors = [ + { name = "Amazon Web Services" }, +] +keywords = ["Amazon", "AWS", "Quantum"] +classifiers = [ + "Intended Audience :: Developers", + "Natural Language :: English", + "Programming Language :: Python", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", +] +dependencies = [ + "amazon-braket-sdk>=1.35.1", + "numpy", + "openfermion>=1.5.1", + "pennylane>=0.34.0", + "scipy>=1.5.2", + # Sympy 1.13 produces different results for Simon's algorithm + "sympy<1.13", + "qiskit-braket-provider", +] + +[project.optional-dependencies] +test = [ + "pytest", + "pytest-cov", + "pytest-rerunfailures", + "pytest-xdist", + "ruff", + "sphinx", + "sphinx-rtd-theme", + "sphinxcontrib-apidoc", + "tox", +] + +[project.urls] +Homepage = "https://github.com/amazon-braket/amazon-braket-algorithm-library" + +[tool.setuptools.packages.find] +where = ["src"] +exclude = ["test"] + +[tool.setuptools.dynamic] +version = { attr = "braket._algos._version.__version__" } + +[tool.setuptools.package-data] +"*" = ["*.md"] + +[tool.pytest.ini_options] +xfail_strict = true +# removing pytest-xdist config currently since that conflicts with -s option in --mock-level=LEAST tests +addopts = "--verbose -n auto --durations=0 --durations-min=1" +testpaths = ["test/unit_tests"] + +[tool.coverage.run] +parallel = true +branch = true +source = ["braket.experimental"] + +[tool.coverage.paths] +source = [ + "src/braket", + ".tox/*/lib/python*/site-packages/braket", +] + +[tool.coverage.report] +show_missing = true + +[tool.coverage.html] +directory = "build/coverage" + +[tool.coverage.xml] +output = "build/coverage/coverage.xml" + [tool.ruff] target-version = "py311" line-length = 100 -lint.isort = { known-first-party = [ - "braket", -] } -lint.extend-select = ["I", "PERF"] -lint.preview = false #TODO: set back to true + +[tool.ruff.lint] +extend-select = ["I", "PERF"] +preview = false #TODO: set back to true + +[tool.ruff.lint.isort] +known-first-party = ["braket"] diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 038b4aba..00000000 --- a/setup.cfg +++ /dev/null @@ -1,10 +0,0 @@ -[aliases] -test=pytest - -[tool:pytest] -xfail_strict = true -# removing pytest-xdist config currently since that conflicts with -s option in --mock-level=LEAST tests -addopts = --verbose -n auto --durations=0 --durations-min=1 -testpaths = test/unit_tests - - diff --git a/setup.py b/setup.py deleted file mode 100644 index c89aa705..00000000 --- a/setup.py +++ /dev/null @@ -1,70 +0,0 @@ -# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"). You -# may not use this file except in compliance with the License. A copy of -# the License is located at -# -# http://aws.amazon.com/apache2.0/ -# -# or in the "license" file accompanying this file. This file is -# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF -# ANY KIND, either express or implied. See the License for the specific -# language governing permissions and limitations under the License. - -from setuptools import find_namespace_packages, setup - -with open("README.md", "r", encoding="utf8") as fh: - long_description = fh.read() - -with open("src/braket/_algos/_version.py") as f: - version = f.readlines()[-1].split()[-1].strip("\"'") - -setup( - name="amazon-braket-algorithm-library", - version=version, - license="Apache License 2.0", - python_requires=">= 3.11", - packages=find_namespace_packages(where="src", exclude=("test",)), - package_dir={"": "src"}, - install_requires=[ - "amazon-braket-sdk>=1.35.1", - "numpy", - "openfermion>=1.5.1", - "pennylane>=0.34.0", - "scipy>=1.5.2", - # Sympy 1.13 produces different results for Simon's algorithm - "sympy<1.13", - "qiskit-braket-provider", - ], - extras_require={ - "test": [ - "pytest", - "pytest-cov", - "pytest-rerunfailures", - "pytest-xdist", - "ruff", - "sphinx", - "sphinx-rtd-theme", - "sphinxcontrib-apidoc", - "tox", - ] - }, - include_package_data=True, - url="https://github.com/amazon-braket/amazon-braket-algorithm-library", - author="Amazon Web Services", - description=( - "An open source library of quantum computing algorithms implemented on Amazon Braket" - ), - long_description=long_description, - long_description_content_type="text/markdown", - keywords="Amazon AWS Quantum", - classifiers=[ - "Intended Audience :: Developers", - "Natural Language :: English", - "License :: OSI Approved :: Apache Software License", - "Programming Language :: Python", - "Programming Language :: Python :: 3.11", - "Programming Language :: Python :: 3.12", - "Programming Language :: Python :: 3.13", - ], -) diff --git a/src/braket/experimental/algorithms/quantum_counting/quantum_counting.py b/src/braket/experimental/algorithms/quantum_counting/quantum_counting.py index 68aadb0f..6ffc73fb 100644 --- a/src/braket/experimental/algorithms/quantum_counting/quantum_counting.py +++ b/src/braket/experimental/algorithms/quantum_counting/quantum_counting.py @@ -235,9 +235,7 @@ def controlled_grover_circuit( ) # Controlled diffusion - circ.add_circuit( - _controlled_diffusion_circuit(control, search_qubits, decompose_ccnot) - ) + circ.add_circuit(_controlled_diffusion_circuit(control, search_qubits, decompose_ccnot)) return circ @@ -292,9 +290,7 @@ def quantum_counting_circuit( """ new_circuit = Circuit().add_circuit(counting_circ) new_circuit.add_circuit( - quantum_counting( - counting_qubits, search_qubits, marked_states, decompose_ccnot - ) + quantum_counting(counting_qubits, search_qubits, marked_states, decompose_ccnot) ) return new_circuit.probability(counting_qubits) @@ -338,9 +334,7 @@ def quantum_counting( for ii, qubit in enumerate(reversed(counting_qubits)): power = 2**ii qc_circ.add_circuit( - controlled_grover_circuit( - qubit, search_qubits, marked_states, power, decompose_ccnot - ) + controlled_grover_circuit(qubit, search_qubits, marked_states, power, decompose_ccnot) ) # Inverse QFT on counting qubits @@ -436,9 +430,7 @@ def get_quantum_counting_results( if verbose: print(f"Search space size N = {N}") - sorted_cr = sorted( - counting_register_results.items(), key=lambda x: x[1], reverse=True - ) + sorted_cr = sorted(counting_register_results.items(), key=lambda x: x[1], reverse=True) print("\nCounting register distribution (top outcomes):") for bitstring, count in sorted_cr[:6]: y_val = int(bitstring, 2) diff --git a/test/unit_tests/braket/experimental/algorithms/quantum_counting/test_quantum_counting.py b/test/unit_tests/braket/experimental/algorithms/quantum_counting/test_quantum_counting.py index 784b6131..c59e4ecd 100644 --- a/test/unit_tests/braket/experimental/algorithms/quantum_counting/test_quantum_counting.py +++ b/test/unit_tests/braket/experimental/algorithms/quantum_counting/test_quantum_counting.py @@ -266,10 +266,8 @@ def test_count_with_marked_initial_state(): # Controlled-G^(2^k) using gate-level circuit for ii, qubit in enumerate(reversed(counting_qubits)): - power = 2 ** ii - circ.add_circuit( - qc.controlled_grover_circuit(qubit, search_qubits, marked_states, power) - ) + power = 2**ii + circ.add_circuit(qc.controlled_grover_circuit(qubit, search_qubits, marked_states, power)) # Inverse QFT on counting qubits circ.add_circuit(qc.inverse_qft_for_counting(counting_qubits))