Skip to content

feat(qsystem)!: multiple platform extensions#1567

Open
ss2165 wants to merge 22 commits into
mainfrom
ss/push-xxonxqrlptsq
Open

feat(qsystem)!: multiple platform extensions#1567
ss2165 wants to merge 22 commits into
mainfrom
ss/push-xxonxqrlptsq

Conversation

@ss2165
Copy link
Copy Markdown
Member

@ss2165 ss2165 commented May 5, 2026

Creates new platform specific qsystem extensions. Each extension is self-contained and complete but code is deduplicated to a reasonable degree.

  • pytket conversion and llvm codegen parameterised by platform
  • based on feat!: handling multiple QSystem gatesets #1370 (supersedes)
  • SharedOp enum for shared definitions
  • Extensions differ in two qubit gate: ZZPhase vs. PhasedXX
  • Snapshot tests parametrised over target (hence big diff)
  • tket.qsystem extension and some utilities kept in deprecated form for backwards compatibility

BREAKING CHANGE: tket-qsystem conversion, lowering and codegen methods take additional QSystemPlatform parameter to choose target platform.

@ss2165 ss2165 force-pushed the ss/push-xxonxqrlptsq branch from 65b0cdd to 24f9794 Compare May 8, 2026 18:05
jake-arkinstall and others added 21 commits May 21, 2026 16:55
Disambiguate helios and sol during rebasing, rename N2PhasedX -> TwinPhasedX

Correct descriptions after the reintroduction of the rz gate

Format + rust test fixups

Rebase + document QSystemCodegenExtension::new

Rename python testing of unimplemented sol features and change from pytest.raises to xfail

Ruff format

Remove redundant variable setting in xfail test

Add unimplemented two-qubit operations for sol gateset (#1377)

[decompositions.py](https://github.com/user-attachments/files/24907896/decompositions.py)
Constructions should be as in attached python.

---------

Co-authored-by: Jake Arkinstall <65358059+jake-arkinstall@users.noreply.github.com>

Add missing maximally entangling XXPhase

Update ZZPhase and ZZMax

Correct output wire indexing for 2q sol gates, correct some typos in gate rebasing, add QFT test

Correct add_phased_xx

Apply requested changes, add addition test
- include deprecated tket.qsystem alias for helios
- regenerate extensions
- comment out sol ops in pytket and llvm for now
Parametrise qis-compiler snapshot tests over both 'helios' and 'sol' platforms
(previously only helios was exercised).

Changes:
- Expose 'platform' and 'target_triple' kwargs in the Python .pyi stubs for
  compile_to_llvm_ir / compile_to_bitcode (the Rust signatures already had them).
- Add 'platforms = ["helios", "sol"]' and @parametrize("platform", platforms)
  to test_basic_generation.py::test_llvm; snapshot keys gain a platform suffix
  ({hugr_file}_{target_triple}_{platform}).
- Old platform-less snapshot files deleted.
- Remove residual '# type: ignore[call-arg]' comments from both test files now
  that the stubs are correct.

Expected diff between helios and sol snapshots
-----------------------------------------------
All differences are mechanical consequences of each platform's native gate set:

1. Single-qubit gate name: PhasedX maps to ___rxy on Helios and ___rp on Sol.

2. Two-qubit gate rewriting (rus.hugr, postselect_*.hugr, measure_qb_array.hugr):
   The QSystemPass rewrites tket.quantum gates (cx, h, t, ...) into platform-native
   qsystem gates before LLVM codegen.
   - Helios: cx -> ZZPhase + PhasedX  ->  calls to @___rzz + @___rxy
   - Sol:    cx -> PhasedXX           ->  calls to @___rpp + @___rp
   The control-flow structure is identical; only the runtime-function names and
   the platform string embedded in hugr-llvm's mangled inner-function labels
   ('__tk2_helios_' vs '__tk2_sol_') differ.

3. No differences in discard_qb_array, print_current_shot, rng — these circuits
   contain no 2Q gates and no PhasedX, so codegen is platform-independent.
@ss2165 ss2165 force-pushed the ss/push-xxonxqrlptsq branch from 24f9794 to 08fb061 Compare May 21, 2026 15:56
@codecov
Copy link
Copy Markdown

codecov Bot commented May 21, 2026

Codecov Report

❌ Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.49%. Comparing base (1ab71ed) to head (2e85308).

Files with missing lines Patch % Lines
badger-optimiser/src/main.rs 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1567      +/-   ##
==========================================
- Coverage   85.52%   85.49%   -0.03%     
==========================================
  Files         184      190       +6     
  Lines       29077    30070     +993     
  Branches    27876    28729     +853     
==========================================
+ Hits        24868    25709     +841     
- Misses       3075     3238     +163     
+ Partials     1134     1123      -11     
Flag Coverage Δ
python 89.98% <ø> (-0.48%) ⬇️
qis-compiler 91.78% <ø> (+0.11%) ⬆️
rust 85.28% <0.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hugrbot
Copy link
Copy Markdown
Collaborator

hugrbot commented May 21, 2026

This PR contains breaking changes to the public Rust API.

cargo-semver-checks summary
    Building tket v0.18.0 (current)
     Built [  48.360s] (current)
   Parsing tket v0.18.0 (current)
    Parsed [   0.126s] (current)
  Building tket v0.18.0 (baseline)
     Built [  46.286s] (baseline)
   Parsing tket v0.18.0 (baseline)
    Parsed [   0.118s] (baseline)
  Checking tket v0.18.0 -> v0.18.0 (assume minor change)
   Checked [   0.135s] 196 checks: 196 pass, 56 skip
   Summary no semver update required
  Finished [  97.090s] tket
  Building tket-qec v0.1.0 (current)
     Built [  41.349s] (current)
   Parsing tket-qec v0.1.0 (current)
    Parsed [   0.007s] (current)
  Building tket-qec v0.1.0 (baseline)
     Built [  40.415s] (baseline)
   Parsing tket-qec v0.1.0 (baseline)
    Parsed [   0.007s] (baseline)
  Checking tket-qec v0.1.0 -> v0.1.0 (assume minor change)
   Checked [   0.013s] 196 checks: 196 pass, 56 skip
   Summary no semver update required
  Finished [  83.299s] tket-qec
  Building tket-qsystem v0.24.0 (current)
     Built [  47.442s] (current)
   Parsing tket-qsystem v0.24.0 (current)
    Parsed [   0.034s] (current)
  Building tket-qsystem v0.24.0 (baseline)
     Built [  47.348s] (baseline)
   Parsing tket-qsystem v0.24.0 (baseline)
    Parsed [   0.029s] (baseline)
  Checking tket-qsystem v0.24.0 -> v0.24.0 (assume minor change)
   Checked [   0.049s] 196 checks: 193 pass, 3 fail, 0 warn, 56 skip

--- failure function_parameter_count_changed: pub fn parameter count changed ---

Description:
A publicly-visible function now takes a different number of parameters.
      ref: https://doc.rust-lang.org/cargo/reference/semver.html#fn-change-arity
     impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.47.0/src/lints/function_parameter_count_changed.ron

Failed in:
tket_qsystem::extension::qsystem::lower_tk2_ops now takes 3 parameters instead of 2, in /home/runner/work/tket2/tket2/PR_BRANCH/tket-qsystem/src/extension/qsystem/lower.rs:127
tket_qsystem::pytket::qsystem_decoder_config now takes 1 parameters instead of 0, in /home/runner/work/tket2/tket2/PR_BRANCH/tket-qsystem/src/pytket.rs:20
tket_qsystem::pytket::qsystem_encoder_config now takes 1 parameters instead of 0, in /home/runner/work/tket2/tket2/PR_BRANCH/tket-qsystem/src/pytket.rs:31
tket_qsystem::extension::qsystem::check_lowered now takes 3 parameters instead of 2, in /home/runner/work/tket2/tket2/PR_BRANCH/tket-qsystem/src/extension/qsystem/lower.rs:356

--- failure struct_missing: pub struct removed or renamed ---

Description:
A publicly-visible struct cannot be imported by its prior path. A `pub use` may have been removed, or the struct itself may have been renamed or removed entirely.
      ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
     impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.47.0/src/lints/struct_missing.ron

Failed in:
struct tket_qsystem::extension::qsystem::QSystemOpIter, previously in file /home/runner/work/tket2/tket2/BASELINE_BRANCH/tket-qsystem/src/extension/qsystem.rs:82

--- failure trait_missing: pub trait removed or renamed ---

Description:
A publicly-visible trait cannot be imported by its prior path. A `pub use` may have been removed, or the trait itself may have been renamed or removed entirely.
      ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
     impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.47.0/src/lints/trait_missing.ron

Failed in:
trait tket_qsystem::extension::qsystem::QSystemOpBuilder, previously in file /home/runner/work/tket2/tket2/BASELINE_BRANCH/tket-qsystem/src/extension/qsystem.rs:247

   Summary semver requires new major version: 3 major and 0 minor checks failed
  Finished [  97.277s] tket-qsystem

@ss2165 ss2165 changed the title wip(qsystem): multiple platform extensions feat(qsystem)!: multiple platform extensions May 21, 2026
@ss2165 ss2165 requested a review from aborgna-q May 21, 2026 17:04
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review this pull request because it exceeds the maximum number of lines (20,000). Try reducing the number of changed lines and requesting a review from Copilot again.

@ss2165 ss2165 marked this pull request as ready for review May 21, 2026 17:04
@ss2165 ss2165 requested a review from a team as a code owner May 21, 2026 17:04
Copy link
Copy Markdown
Collaborator

@aborgna-q aborgna-q left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Just a few comments.

Comment on lines +4 to +5
target_triple: str = "native",
platform: str = "helios",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use Literals here for the options, rather than a general str?

.reassemble_inplace(&mut program.hugr, Some(Arc::new(qsystem_decoder_config())))
.reassemble_inplace(
&mut program.hugr,
Some(Arc::new(qsystem_decoder_config(QSystemPlatform::Helios))),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's OK to default to Helios for now, but we'll want to do something configurable in the future.

Opened an issue about it. This is something that we already discussed with Callum.

Suggested change
Some(Arc::new(qsystem_decoder_config(QSystemPlatform::Helios))),
// TODO: Make the decoder set configurable.
// <https://github.com/Quantinuum/tket2/issues/1619>
Some(Arc::new(qsystem_decoder_config(QSystemPlatform::Helios))),

"QSystemRandomExtension",
"QSystemSolExtension",
"QSystemUtilsExtension",
"QSystemGenericExtension",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't exist?

Comment on lines +87 to +88
tket.qsystem.QSystemHeliosExtension(),
tket.qsystem.QSystemSolExtension(),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep the old extension in this set for now, otherwise we'll fail to load hugrs using tket.qsystem.

Suggested change
tket.qsystem.QSystemHeliosExtension(),
tket.qsystem.QSystemSolExtension(),
tket.qsystem.QSystemHeliosExtension(),
tket.qsystem.QSystemSolExtension(),
tket.qsystem.QSystemExtension(),

) -> Result<Vec<Node>, LowerTk2Error> {
let scope = scope.into();
let mut funcs: BTreeMap<TketOp, NodeTemplate> = BTreeMap::new();
let mut lowerer = ReplaceTypes::new_empty().with_scope(scope.clone());
let mut barrier_funcs = BarrierInserter::new();
register_legacy_qsystem_replacements(&mut lowerer);
Copy link
Copy Markdown
Collaborator

@aborgna-q aborgna-q May 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're lowering tket.quantum ops to the target platform here, but any tket.qsystem op gets mapped to tket.quantum.helios.

Should we use the chosen platform for the legacy replacements too?

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.

6 participants