Skip to content

chore: new tket-qsim unitary simulator for unit testing - #1886

Open
ferbetanzo wants to merge 7 commits into
mainfrom
fb/tket2-sim
Open

ferbetanzo wants to merge 7 commits into
mainfrom
fb/tket2-sim

Conversation

@ferbetanzo

@ferbetanzo ferbetanzo commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Closes #1648. Includes the following:

  • New tket-qsim crate that allows to simulate (purely unitary) hugrs. It defines the required <tket|helios|sol>_ops unitary matrices but compares them against roqoqo's gate definitions.
  • New semantics preserving tests for cross-compilation.

@ferbetanzo
ferbetanzo requested a review from a team as a code owner July 28, 2026 11:34
@ferbetanzo
ferbetanzo requested a review from doug-q July 28, 2026 11:34
@ferbetanzo
ferbetanzo marked this pull request as draft July 28, 2026 11:36
@codecov

codecov Bot commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.86207% with 123 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.24%. Comparing base (7e114dd) to head (5bde2bf).

Files with missing lines Patch % Lines
tket-qsim/src/simulate.rs 76.19% 54 Missing and 16 partials ⚠️
tket-qsim/src/matrix.rs 86.06% 28 Missing ⚠️
tket-qsim/src/tket_ops.rs 96.20% 9 Missing ⚠️
tket-qsim/src/helios_ops.rs 87.09% 8 Missing ⚠️
tket-qsim/src/sol_ops.rs 89.47% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1886      +/-   ##
==========================================
- Coverage   86.25%   86.24%   -0.02%     
==========================================
  Files         202      207       +5     
  Lines       31992    32862     +870     
  Branches    30500    31370     +870     
==========================================
+ Hits        27594    28341     +747     
- Misses       3165     3272     +107     
- Partials     1233     1249      +16     
Flag Coverage Δ
python 92.18% <ø> (ø)
qis-compiler 74.17% <ø> (ø)
rust 85.95% <85.86%> (-0.01%) ⬇️

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

☔ View full report in Codecov by Harness.
📢 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.

@ferbetanzo
ferbetanzo marked this pull request as ready for review July 28, 2026 13:35

@doug-q doug-q left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for this. Apologies but I do not think we should proceed with this approach. Happy to discuss.

I think that we can't use selene because of dependency loops, is that right?

Problems with this approach

  • It relys on the hugrs under test to get optimised into single-dfg functions
  • lowerings that contain control flow cannot be handled
  • lowerings that include ancillas or mid circuit measurements cannot be handled
  • The hugrs that are tested are fixed. This approach is not going to catch corner cases (e.g. bugs where special angles cause big problems)

I don't think this is the right solution to verifying our transformations.

I suggest

  • Each op should be verified independently
  • The expected unitary should be specified local to the test
  • I don't think we should build an interpreter here. (I would be ok on depending on a separate, complete(ish) interpreter)
  • A better approach, IMO, would be to
    • depend on selene in such a way as it doesn't create circular dependencies. This is surely possible because we don't need to run any tket transformations in selene (we can do it beforehand)
    • For parameterised gates use property testing to explore the parameter space and catch corner cases


let unitary_after = simulate_circuit(&h, &params).unwrap();
assert!(
unitary_before.approx_eq_up_to_global_phase(&unitary_after, 1e-10),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would prefer to use the https://docs.rs/approx/latest/approx/ crate for this

Comment thread tket-qsim/src/matrix.rs
///
/// Stored in row-major order.
#[derive(Clone)]
pub struct UnitaryMatrix {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would prefer to use the https://www.nalgebra.rs/docs/ crate for this

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.

[Test]: Add a mini-executor for validating rewrite tests

2 participants