Skip to content

[WIP] Toolchain improvements.#2

Draft
gjz010 wants to merge 8 commits into
Youngcius:masterfrom
gjz010-Forks:master
Draft

[WIP] Toolchain improvements.#2
gjz010 wants to merge 8 commits into
Youngcius:masterfrom
gjz010-Forks:master

Conversation

@gjz010

@gjz010 gjz010 commented May 21, 2026

Copy link
Copy Markdown
Contributor
  • Toolchaining with devenv, Nix-based reproducible development environment manager.
  • Switching to battery-included build of monodromy.
    • This build of monodromy is carefully built with portability in mind and does not require separated building of lrslib. Works on Linux and Windows.
    • Main issue is license: this may resulting in entire repo GPLv3 rather than Apache 2.0 since lrslib is GPLv2+.
  • Added tests for SQiSW decomposition.
  • WIP: backport RIIR CanopusMapping implementation.
    • The current canopus.utils._accel extension merely contains a lot of small functions and would in fact result in longer execution time due to Rust-Python FFI boundary.

Summary by Sourcery

Introduce a reproducible Rust+Python development environment and strengthen SQiSW-based two-qubit synthesis validation.

New Features:

  • Add Haar-random and structured test coverage for SQiSW-based two-qubit unitary decomposition, including gate-count validation by KAK invariants.

Enhancements:

  • Switch monodromy to a prebuilt portable wheel and configure uv to track Rust and Python project files for automatic rebuilds.
  • Add temporary diagnostics around KAK decomposition to inspect unitaries and their interaction coefficients.

Build:

  • Add Nix-based devenv configuration (including Rust, Python with uv, and treefmt) and associated lock files for reproducible local development.

Tests:

  • Introduce comprehensive SQiSW decomposition test suite covering canonical gates, local unitaries, and Haar-random SU(4) distributions.

@sourcery-ai

sourcery-ai Bot commented May 21, 2026

Copy link
Copy Markdown

Reviewer's Guide

Introduces a Nix/devenv-based reproducible dev environment, switches monodromy to a prebuilt wheel sourced via uv, and adds an extensive SQiSW decomposition test suite along with minor Rust/Python plumbing tweaks to support and debug two-qubit KAK-based logic.

File-Level Changes

Change Details Files
Add uv/devenv-based reproducible development environment configuration.
  • Introduce devenv.nix to configure Rust (stable), Python with uv and venv, Nix LSP, and treefmt with nixfmt/rustfmt.
  • Add devenv.yaml to declare flake-style inputs (rust-overlay, treefmt-nix) for devenv.
  • Check in devenv.lock and uv.lock to pin environment dependencies.
  • Add .envrc scaffold (likely for direnv integration) and update .gitignore if needed for new environment artifacts.
devenv.nix
devenv.yaml
devenv.lock
uv.lock
.envrc
.gitignore
Switch monodromy dependency to a prebuilt wheel fetched directly by uv and configure Rust rebuild cache keys.
  • Configure [tool.uv.sources] in pyproject.toml to point monodromy to a GitHub release wheel URL.
  • Add [tool.uv] cache-keys to trigger Rust extension rebuilds when Rust or dependency files change (pyproject, Cargo.toml/lock, src/**/*.rs).
pyproject.toml
Tidy Rust canonical_unitary binding signature formatting for readability.
  • Reformat canonical_unitary pyfunction declaration to multi-line argument style without changing behavior.
src/lib.rs
Instrument KAK decomposition helper for debugging Weyl coordinates.
  • Temporarily add prints of the unitary and interaction coefficients inside _kak_from_unitary for inspection.
python/canopus/decomposition/utils.py
Add a comprehensive SQiSW decomposition correctness and distribution test suite.
  • Define an SQiSWGate wrapper using Qiskit’s with_gate_array/SingletonGate to obtain the √iSWAP matrix.
  • Implement helpers to compare unitaries up to global phase, count SQiSW gates in circuits, and synthesize unitaries from given Weyl coordinates with random local unitaries.
  • Add TestSQiSWDecomposition tests for minimal named-gate cases and fixed random examples ensuring expected SQiSW counts (0–3).
  • Add torture tests for measure-zero SU(2)⊗SU(2) local unitaries ensuring zero SQiSWs, and for Haar-random SU(4) unitaries verifying KAK-based expected SQiSW counts and empirical distribution (~79% 2-SQiSW, rest 3-SQiSW).
  • Include an intentional failing assert in check_equivalence (after the overlap check) to force tests to fail while debugging, ensuring this is revisited before merge.
tests/test_sqisw.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant