From 4fe9e389422c05c36e238e5be910dba61c36e8bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20Borgna?= <121866228+aborgna-q@users.noreply.github.com> Date: Fri, 3 Nov 2023 15:51:04 +0100 Subject: [PATCH] refactor: Restructure the python code (#211) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Renames `pyrs` → `tket2`. Closes #207. - Adds a poetry configuration and makes sure all commands can be run from the root. - Expands the justfile and other development docs. `poetry run just pytest` will take care of everything. - Enables ruff checks (lints and format) on CI. - Fixes rust binding imports requiring duplicated `import pyrs.pyrs`. Closes #208. This was caused by the python `__init__.py` overriding the one [generated by maturin](https://www.maturin.rs/project_layout.html#mixed-rustpython-project). --- .github/pre-commit | 19 +++++++- .github/workflows/ci.yml | 28 ++++++----- .gitignore | 9 +++- .gitmodules | 3 -- Cargo.toml | 2 +- DEVELOPMENT.md | 44 +++++++---------- README.md | 2 +- ...v-requirements.txt => dev-requirements.txt | 5 +- devenv.nix | 2 +- ext/symengine.rs | 1 - justfile | 32 ++++++++++-- pyproject.toml | 46 ++++++++++++++++++ pyrs/pyproject.toml | 13 ----- pyrs/pyrs/__init__.py | 0 pyrs/requirements.txt | 1 - .../circ.qasm => test_files/simple.qasm | 0 {pyrs => tket2-py}/.gitignore | 0 {pyrs => tket2-py}/Cargo.toml | 13 +++-- {pyrs => tket2-py}/README.md | 4 +- {pyrs => tket2-py}/src/circuit.rs | 0 {pyrs => tket2-py}/src/lib.rs | 10 ++-- {pyrs => tket2-py}/src/optimiser.rs | 0 {pyrs => tket2-py}/src/pass.rs | 0 {pyrs => tket2-py}/test/test_bindings.py | 6 +-- {pyrs => tket2-py}/test/test_optimiser.py | 8 +-- {pyrs => tket2-py}/test/test_pass.py | 4 +- {pyrs => tket2-py}/test/test_portmatching.py | 12 ++--- tket2-py/tket2/__init__.py | 5 ++ {pyrs/pyrs => tket2-py/tket2}/custom_base.py | 2 +- .../pyrs => tket2-py/tket2}/data/nam_6_3.rwr | Bin {pyrs/pyrs => tket2-py/tket2}/passes.py | 6 +-- tket2/src/json.rs | 2 +- tket2/src/passes/commutation.rs | 2 +- tket2/src/portmatching/pattern.rs | 2 +- 34 files changed, 181 insertions(+), 102 deletions(-) delete mode 100644 .gitmodules rename pyrs/dev-requirements.txt => dev-requirements.txt (70%) delete mode 160000 ext/symengine.rs create mode 100644 pyproject.toml delete mode 100644 pyrs/pyproject.toml delete mode 100644 pyrs/pyrs/__init__.py delete mode 100644 pyrs/requirements.txt rename pyrs/test/test_files/circ.qasm => test_files/simple.qasm (100%) rename {pyrs => tket2-py}/.gitignore (100%) rename {pyrs => tket2-py}/Cargo.toml (67%) rename {pyrs => tket2-py}/README.md (91%) rename {pyrs => tket2-py}/src/circuit.rs (100%) rename {pyrs => tket2-py}/src/lib.rs (91%) rename {pyrs => tket2-py}/src/optimiser.rs (100%) rename {pyrs => tket2-py}/src/pass.rs (100%) rename {pyrs => tket2-py}/test/test_bindings.py (98%) rename {pyrs => tket2-py}/test/test_optimiser.py (51%) rename {pyrs => tket2-py}/test/test_pass.py (66%) rename {pyrs => tket2-py}/test/test_portmatching.py (79%) create mode 100644 tket2-py/tket2/__init__.py rename {pyrs/pyrs => tket2-py/tket2}/custom_base.py (83%) rename {pyrs/pyrs => tket2-py/tket2}/data/nam_6_3.rwr (100%) rename {pyrs/pyrs => tket2-py/tket2}/passes.py (88%) diff --git a/.github/pre-commit b/.github/pre-commit index d7693569..b5ac4209 100755 --- a/.github/pre-commit +++ b/.github/pre-commit @@ -11,8 +11,16 @@ fi if ! cargo fmt -- --check then - echo "There are some code style issues." - echo "Run cargo fmt first." + echo "There are some rust code style issues." + echo "Run `cargo fmt` first." + exit 1 +fi + +# Run `ruff` python formatting if it is available +if command -v ruff &> /dev/null && ! ruff format --check . +then + echo "There are some python code style issues." + echo "Run `ruff format .` first." exit 1 fi @@ -28,4 +36,11 @@ then exit 1 fi +# Run `ruff` python linting if it is available +if command -v ruff &> /dev/null && ! ruff check . +then + echo "There are some python linting issues." + exit 1 +fi + exit 0 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8cf7d526..f4e037e1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,14 +29,22 @@ jobs: with: components: rustfmt, clippy - uses: mozilla-actions/sccache-action@v0.0.3 - - name: Check formatting + - name: Check rust formatting run: cargo fmt -- --check + - name: Check python formatting + uses: chartboost/ruff-action@v1 + with: + args: format --check - name: Run clippy run: cargo clippy --all-targets --all-features --workspace -- -D warnings - name: Build docs run: cargo doc --no-deps --all-features env: RUSTDOCFLAGS: "-Dwarnings" + - name: Python lints + uses: chartboost/ruff-action@v1 + with: + args: check benches: # Not required, we can ignore it for the merge queue check. @@ -101,14 +109,11 @@ jobs: cache: 'pip' - name: Build pyo3 bindings run: | - pip install -r requirements.txt - cd pyrs + pip install -r dev-requirements.txt maturin build - pip install ../target/wheels/*.whl + pip install target/wheels/*.whl - name: Test pyo3 bindings - run: | - cd pyrs - pytest + run: pytest coverage: if: github.event_name != 'merge_group' @@ -149,15 +154,12 @@ jobs: cache: 'pip' - name: Build pyo3 bindings run: | - pip install -r requirements.txt + pip install -r dev-requirements.txt pip install pytest-cov - cd pyrs maturin build - pip install ../target/wheels/*.whl + pip install target/wheels/*.whl - name: Run python tests with coverage instrumentation - run: | - cd pyrs - pytest --cov=./ --cov-report=xml + run: pytest --cov=./ --cov-report=xml - name: Upload python coverage to codecov.io uses: codecov/codecov-action@v3 with: diff --git a/.gitignore b/.gitignore index 8414c4fb..a74e7b4f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,13 @@ +# Build artifacts /target +tket2-py/target/ + +# Lock files Cargo.lock -pyrs/target/ +poetry.lock + +# Python caches +__pycache__ .ipynb_checkpoints # Devenv diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 8014a43a..00000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "ext/symengine.rs"] - path = ext/symengine.rs - url = git@github.com:podo-os/symengine.rs.git diff --git a/Cargo.toml b/Cargo.toml index 33f9c941..b6c886f0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ lto = "thin" [workspace] resolver = "2" -members = ["tket2", "pyrs", "compile-rewriter", "taso-optimiser"] +members = ["tket2", "tket2-py", "compile-rewriter", "taso-optimiser"] default-members = ["tket2"] [workspace.package] diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index b930aecd..2f2e1530 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -24,40 +24,24 @@ devenv shell All the required dependencies should be available. You can automate loading the shell by setting up [direnv](https://devenv.sh/automatic-shell-activation/). -### Manual setup +### Poetry setup To setup the environment manually you will need: -- Rust: https://www.rust-lang.org/tools/install +- Rust 1.70+: https://www.rust-lang.org/tools/install -- Python 3.10+: https://www.python.org/downloads/ +- Poetry: https://python-poetry.org/ - It is advisable to use a virtual environment for keeping the python - environment isolated, see - [`venv`](https://docs.python.org/3/tutorial/venv.html) for more details. - - Install the python development dependencies with: - - ```bash - pip install -r pyrs/dev-requirements.txt - ``` - - -You can use the git hook in [`.github/pre-commit`](.github/pre-commit) to automatically run the test and check formatting before committing. -To install it, run: - -```bash -ln -s .github/pre-commit .git/hooks/pre-commit -# Or, to check before pushing instead -ln -s .github/pre-commit .git/hooks/pre-push -``` +Simply run `poetry shell` to activate an environment with all the required dependencies. ## 🏃 Running the tests -To compile and test the rust code, run: +The repository root contains a Justfile with the most common development tasks. +Run `just` to see a list. + +To manually compile and test the rust code, run: ```bash -cargo build cargo test ``` @@ -78,11 +62,19 @@ cargo +nightly miri test To run the python tests, run: ```bash -cd pyrs maturin develop pytest ``` +You can use the script in [`.github/pre-commit`](.github/pre-commit) to run the test and formatting required by our CI. +To automatically check that before each commit, install it as a hook with: + +```bash +ln -s .github/pre-commit .git/hooks/pre-commit +# Or, to check before pushing instead +ln -s .github/pre-commit .git/hooks/pre-push +``` + ## 💅 Coding Style The rustfmt tool is used to enforce a consistent rust coding style. The CI will fail if the code is not formatted correctly. Python code is formatted with black. @@ -93,7 +85,7 @@ To format your code, run: # Format rust code cargo fmt # Format python code -black . +ruff format . ``` We also check for clippy warnings, which are a set of linting rules for rust. To run clippy, run: diff --git a/README.md b/README.md index daf3c96b..eff080f0 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Version 2 of the TKET compiler. ## Features - `pyo3` -This optional feature enables some python bindings via pyo3. See the `pyrs` folder for more. +This optional feature enables some python bindings via pyo3. See the `tket2-py` folder for more. - `portmatching` This enables pattern matching using the `portmatching` crate. diff --git a/pyrs/dev-requirements.txt b/dev-requirements.txt similarity index 70% rename from pyrs/dev-requirements.txt rename to dev-requirements.txt index 2406e2fe..da3643d0 100644 --- a/pyrs/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,9 +1,10 @@ -# Use common dependencies +# Runtime requirements -r requirements.txt # Development requirements maturin # Build wheels -black # Code formatting +pytest # Unit testing +ruff # Code formatting pytket # TKET1 jupyterlab # For running the examples graphviz # Visualisation of Hugrs in the notebooks \ No newline at end of file diff --git a/devenv.nix b/devenv.nix index a1dd0d15..88389e65 100644 --- a/devenv.nix +++ b/devenv.nix @@ -39,7 +39,7 @@ enable = true; venv.enable = true; - venv.requirements = "-r ${config.env.DEVENV_ROOT}/pyrs/dev-requirements.txt"; + venv.requirements = "-r ${config.env.DEVENV_ROOT}/tket2-py/dev-requirements.txt"; }; # https://devenv.sh/pre-commit-hooks/ diff --git a/ext/symengine.rs b/ext/symengine.rs deleted file mode 160000 index 05ae9caf..00000000 --- a/ext/symengine.rs +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 05ae9caf81173095938632454b2f1d6b412adb86 diff --git a/justfile b/justfile index bbee89e0..a190bde1 100644 --- a/justfile +++ b/justfile @@ -1,8 +1,32 @@ +# List the available commands +help: + @just --list --justfile {{justfile()}} + +# Run all the rust tests test: - cargo test + cargo test --all-features +# Auto-fix all clippy warnings fix: - cargo clippy --fix --allow-staged + cargo clippy --all-targets --all-features --workspace --fix --allow-staged + +# Build the python package wheels +pybuild: + maturin build --release + +# Build the python package for local development +pydevelop: + maturin develop + +# Run the python tests +pytest: pydevelop + pytest + +# Run the pre-commit checks +check: + ./.github/pre-commit -ptest: - (cd pyrs && maturin develop && pytest) \ No newline at end of file +# Format the code +format: + cargo fmt + ruff format . \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..58b7864b --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,46 @@ +[tool.poetry] +name = "tket2-py" +version = "0.1.0" +description = "pytket extension for the tket 2 compiler" +classifiers = [] # TODO +authors = [] # TODO +maintainers = [] # TODO +include = ["pyproject.toml"] +license = "Apache-2.0" +readme = "README.md" + +packages = [{ include = "tket2-py" }] + +[tool.poetry.dependencies] +python = ">=3.10" + +[tool.poetry.dev-dependencies] +maturin = "^1.3.0" +pytket = "*" +pytest = "^7.1.2" +ruff = "^0.1.3" + +[build-system] +requires = ["maturin~=1.3"] +build-backend = "maturin" + +[project] +name = "tket2" +version = "0.1.0" +description = "pytket extension for the tket 2 compiler" +authors = [] # TODO +classifiers = [] # TODO +requires-python = ">=3.10" +license = "Apache-2.0" + +[project.urls] +homepage = "https://github.com/CQCL/tket2" +repository = "https://github.com/CQCL/tket2" + +[tool.maturin] +manifest-path = "tket2-py/Cargo.toml" +python-source = "tket2-py" + +[tool.pytest.ini_options] +# Lark throws deprecation warnings for `src_parse` and `src_constants`. +filterwarnings = "ignore::DeprecationWarning:lark.*" diff --git a/pyrs/pyproject.toml b/pyrs/pyproject.toml deleted file mode 100644 index 019c5658..00000000 --- a/pyrs/pyproject.toml +++ /dev/null @@ -1,13 +0,0 @@ -[build-system] -requires = ["maturin~=1.3"] -build-backend = "maturin" - -[project] -name = "pyrs" -requires-python = ">=3.6" -classifiers = [ - "Programming Language :: Rust", - "Programming Language :: Python :: Implementation :: CPython", - "Programming Language :: Python :: Implementation :: PyPy", -] -dependencies = ["pytket~=1.0", "pytest~=7.1"] diff --git a/pyrs/pyrs/__init__.py b/pyrs/pyrs/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/pyrs/requirements.txt b/pyrs/requirements.txt deleted file mode 100644 index e854c1b6..00000000 --- a/pyrs/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -# pyrs dependencies \ No newline at end of file diff --git a/pyrs/test/test_files/circ.qasm b/test_files/simple.qasm similarity index 100% rename from pyrs/test/test_files/circ.qasm rename to test_files/simple.qasm diff --git a/pyrs/.gitignore b/tket2-py/.gitignore similarity index 100% rename from pyrs/.gitignore rename to tket2-py/.gitignore diff --git a/pyrs/Cargo.toml b/tket2-py/Cargo.toml similarity index 67% rename from pyrs/Cargo.toml rename to tket2-py/Cargo.toml index 89c98c06..b6de354a 100644 --- a/pyrs/Cargo.toml +++ b/tket2-py/Cargo.toml @@ -1,11 +1,14 @@ [package] -name = "pyrs" -version = "0.1.0" -edition = "2018" +name = "tket2-py" +edition = { workspace = true } +version = { workspace = true } +rust-version = { workspace = true } +homepage = { workspace = true } +license-file = { workspace = true } # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [lib] -name = "pyrs" +name = "tket2" crate-type = ["cdylib"] [dependencies] @@ -17,3 +20,5 @@ quantinuum-hugr = { workspace = true } portgraph = { workspace = true, features = ["pyo3", "serde"] } pyo3 = { workspace = true, features = ["extension-module"] } num_cpus = "1.16.0" +derive_more = "0.99.17" +itertools = { workspace = true } diff --git a/pyrs/README.md b/tket2-py/README.md similarity index 91% rename from pyrs/README.md rename to tket2-py/README.md index 620dff0a..609ea527 100644 --- a/pyrs/README.md +++ b/tket2-py/README.md @@ -1,8 +1,8 @@ -## pyrs +## tket2-py This package uses [pyo3](https://pyo3.rs/v0.16.4/) and [maturin](https://github.com/PyO3/maturin) to bind TKET2 functionality to -python as the `pyrs` package. +python as the `tket2` package. Recommended: diff --git a/pyrs/src/circuit.rs b/tket2-py/src/circuit.rs similarity index 100% rename from pyrs/src/circuit.rs rename to tket2-py/src/circuit.rs diff --git a/pyrs/src/lib.rs b/tket2-py/src/lib.rs similarity index 91% rename from pyrs/src/lib.rs rename to tket2-py/src/lib.rs index 36ac11b3..315eaae5 100644 --- a/pyrs/src/lib.rs +++ b/tket2-py/src/lib.rs @@ -11,10 +11,9 @@ use pass::add_pass_module; use hugr::Hugr; use pyo3::prelude::*; -use tket2::{ - portmatching::{pyo3::PyPatternMatch, CircuitPattern, PatternMatcher}, - rewrite::CircuitRewrite, -}; +use tket2::portmatching::pyo3::PyPatternMatch; +use tket2::portmatching::{CircuitPattern, PatternMatcher}; +use tket2::rewrite::CircuitRewrite; #[derive(Clone)] #[pyclass] @@ -66,7 +65,8 @@ impl RuleMatcher { /// The Python bindings to TKET2. #[pymodule] -fn pyrs(py: Python, m: &PyModule) -> PyResult<()> { +#[pyo3(name = "tket2")] +fn tket2_py(py: Python, m: &PyModule) -> PyResult<()> { add_circuit_module(py, m)?; add_pattern_module(py, m)?; add_pass_module(py, m)?; diff --git a/pyrs/src/optimiser.rs b/tket2-py/src/optimiser.rs similarity index 100% rename from pyrs/src/optimiser.rs rename to tket2-py/src/optimiser.rs diff --git a/pyrs/src/pass.rs b/tket2-py/src/pass.rs similarity index 100% rename from pyrs/src/pass.rs rename to tket2-py/src/pass.rs diff --git a/pyrs/test/test_bindings.py b/tket2-py/test/test_bindings.py similarity index 98% rename from pyrs/test/test_bindings.py rename to tket2-py/test/test_bindings.py index 0a1c66fb..e06cf840 100644 --- a/pyrs/test/test_bindings.py +++ b/tket2-py/test/test_bindings.py @@ -1,5 +1,5 @@ from dataclasses import dataclass -from pyrs.pyrs import passes, circuit, pattern +from tket2 import passes, circuit, pattern from pytket.circuit import Circuit @@ -77,7 +77,7 @@ def test_multiple_rules(): # from functools import wraps # import pytest -# from pyrs.pyrs import ( +# from tket2 import ( # RsCircuit, # WireType, # RsOpType, @@ -96,7 +96,7 @@ def test_multiple_rules(): # decompose_custom_pass, # count_pycustom, # ) -# from pyrs.custom_base import CustomOpBase +# from tket2.custom_base import CustomOpBase # from pytket import Circuit, OpType, Qubit diff --git a/pyrs/test/test_optimiser.py b/tket2-py/test/test_optimiser.py similarity index 51% rename from pyrs/test/test_optimiser.py rename to tket2-py/test/test_optimiser.py index de213d82..ed49e802 100644 --- a/pyrs/test/test_optimiser.py +++ b/tket2-py/test/test_optimiser.py @@ -1,14 +1,14 @@ from pytket import Circuit -from pyrs.pyrs import optimiser +from tket2 import optimiser def test_simple_optimiser(): - """ a simple circuit matching test """ + """a simple circuit matching test""" c = Circuit(3).CX(0, 1).CX(0, 1).CX(1, 2) - opt = optimiser.TasoOptimiser.compile_eccs("../test_files/cx_cx_eccs.json") + opt = optimiser.TasoOptimiser.compile_eccs("test_files/cx_cx_eccs.json") # optimise for 1s cc = opt.optimise(c, 3) exp_c = Circuit(3).CX(1, 2) - assert cc == exp_c \ No newline at end of file + assert cc == exp_c diff --git a/pyrs/test/test_pass.py b/tket2-py/test/test_pass.py similarity index 66% rename from pyrs/test/test_pass.py rename to tket2-py/test/test_pass.py index 3ad701d8..392a48eb 100644 --- a/pyrs/test/test_pass.py +++ b/tket2-py/test/test_pass.py @@ -1,9 +1,9 @@ from pytket import Circuit, OpType -from pyrs.passes import taso_pass +from tket2.passes import taso_pass def test_simple_taso_pass_no_opt(): c = Circuit(3).CCX(0, 1, 2) - taso = taso_pass(max_threads = 1, timeout = 0) + taso = taso_pass(max_threads=1, timeout=0) taso.apply(c) assert c.n_gates_of_type(OpType.CX) == 6 diff --git a/pyrs/test/test_portmatching.py b/tket2-py/test/test_portmatching.py similarity index 79% rename from pyrs/test/test_portmatching.py rename to tket2-py/test/test_portmatching.py index 2f4828bf..d55cf9d4 100644 --- a/pyrs/test/test_portmatching.py +++ b/tket2-py/test/test_portmatching.py @@ -1,10 +1,10 @@ from pytket import Circuit from pytket.qasm import circuit_from_qasm -from pyrs.pyrs import pattern +from tket2 import pattern def test_simple_matching(): - """ a simple circuit matching test """ + """a simple circuit matching test""" c = Circuit(2).CX(0, 1).H(1).CX(0, 1) p1 = pattern.CircuitPattern(Circuit(2).CX(0, 1).H(1)) @@ -16,7 +16,7 @@ def test_simple_matching(): def test_non_convex_pattern(): - """ two-qubit circuits can't match three-qb ones """ + """two-qubit circuits can't match three-qb ones""" p1 = pattern.CircuitPattern(Circuit(3).CX(0, 1).CX(1, 2)) matcher = pattern.PatternMatcher(iter([p1])) @@ -31,8 +31,8 @@ def test_non_convex_pattern(): def test_larger_matching(): - """ a larger crafted circuit with matches WIP """ - c = circuit_from_qasm("test/test_files/circ.qasm") + """a larger crafted circuit with matches WIP""" + c = circuit_from_qasm("test_files/simple.qasm") p1 = pattern.CircuitPattern(Circuit(2).CX(0, 1).H(1)) p2 = pattern.CircuitPattern(Circuit(2).H(0).CX(1, 0)) @@ -41,4 +41,4 @@ def test_larger_matching(): matcher = pattern.PatternMatcher(iter([p1, p2, p3, p4])) - assert len(matcher.find_matches(c)) == 6 \ No newline at end of file + assert len(matcher.find_matches(c)) == 6 diff --git a/tket2-py/tket2/__init__.py b/tket2-py/tket2/__init__.py new file mode 100644 index 00000000..8bed83d8 --- /dev/null +++ b/tket2-py/tket2/__init__.py @@ -0,0 +1,5 @@ +from .tket2 import * # noqa: F403,F405 + +__doc__ = tket2.__doc__ # noqa: F405 +if hasattr(tket2, "__all__"): # noqa: F405 + __all__ = tket2.__all__ # noqa: F405 diff --git a/pyrs/pyrs/custom_base.py b/tket2-py/tket2/custom_base.py similarity index 83% rename from pyrs/pyrs/custom_base.py rename to tket2-py/tket2/custom_base.py index 894eec87..3851edaf 100644 --- a/pyrs/pyrs/custom_base.py +++ b/tket2-py/tket2/custom_base.py @@ -1,5 +1,5 @@ # from abc import ABC, abstractmethod -# from pyrs.pyrs import RsCircuit, Signature +# from tket2 import RsCircuit, Signature # class CustomOpBase(ABC): diff --git a/pyrs/pyrs/data/nam_6_3.rwr b/tket2-py/tket2/data/nam_6_3.rwr similarity index 100% rename from pyrs/pyrs/data/nam_6_3.rwr rename to tket2-py/tket2/data/nam_6_3.rwr diff --git a/pyrs/pyrs/passes.py b/tket2-py/tket2/passes.py similarity index 88% rename from pyrs/pyrs/passes.py rename to tket2-py/tket2/passes.py index 05b6c89f..b1cb76ed 100644 --- a/pyrs/pyrs/passes.py +++ b/tket2-py/tket2/passes.py @@ -1,10 +1,10 @@ from pathlib import Path from typing import Optional -import pkg_resources +import importlib from pytket import Circuit from pytket.passes import CustomPass -from pyrs.pyrs import passes, optimiser +from tket2 import passes, optimiser def taso_pass( @@ -23,7 +23,7 @@ def taso_pass( The arguments `max_threads`, `timeout`, `log_dir` and `rebase` are optional and will be passed on to the TASO optimiser if provided.""" if rewriter is None: - rewriter = pkg_resources.resource_filename("pyrs", "data/nam_6_3.rwr") + rewriter = Path(importlib.resources.files("tket2").joinpath("data/nam_6_3.rwr")) opt = optimiser.TasoOptimiser.load_precompiled(rewriter) def apply(circuit: Circuit) -> Circuit: diff --git a/tket2/src/json.rs b/tket2/src/json.rs index 21590610..62b0c982 100644 --- a/tket2/src/json.rs +++ b/tket2/src/json.rs @@ -106,7 +106,7 @@ pub enum OpConvertError { #[cfg(feature = "pyo3")] create_exception!( - pyrs, + tket2, PyOpConvertError, PyException, "Error type for conversion between tket2's `Op` and `OpType`" diff --git a/tket2/src/passes/commutation.rs b/tket2/src/passes/commutation.rs index bbca13ff..e9148cab 100644 --- a/tket2/src/passes/commutation.rs +++ b/tket2/src/passes/commutation.rs @@ -204,7 +204,7 @@ pub enum PullForwardError { #[cfg(feature = "pyo3")] create_exception!( - pyrs, + tket2, PyPullForwardError, PyException, "Error in applying PullForward rewrite." diff --git a/tket2/src/portmatching/pattern.rs b/tket2/src/portmatching/pattern.rs index fce1e05e..9154e9bf 100644 --- a/tket2/src/portmatching/pattern.rs +++ b/tket2/src/portmatching/pattern.rs @@ -138,7 +138,7 @@ impl From for InvalidPattern { #[cfg(feature = "pyo3")] create_exception!( - pyrs, + tket2, PyInvalidPatternError, PyException, "Invalid circuit pattern"