Skip to content

Gridsynth nit-picks and gate sequence normalisation#1376

Merged
PabloAndresCQ merged 5 commits intokc/gridsynth_passfrom
pam/gridsynth_improvements
Jan 29, 2026
Merged

Gridsynth nit-picks and gate sequence normalisation#1376
PabloAndresCQ merged 5 commits intokc/gridsynth_passfrom
pam/gridsynth_improvements

Conversation

@PabloAndresCQ
Copy link
Contributor

@PabloAndresCQ PabloAndresCQ commented Jan 27, 2026

Merging into the open draft PR #1346 with some improvements

@PabloAndresCQ PabloAndresCQ requested a review from a team as a code owner January 27, 2026 15:05
@PabloAndresCQ PabloAndresCQ requested review from doug-q and removed request for a team January 27, 2026 15:05
@codecov
Copy link

codecov bot commented Jan 27, 2026

Codecov Report

❌ Patch coverage is 87.57764% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.90%. Comparing base (e3d4609) to head (02d64d7).

Files with missing lines Patch % Lines
tket/src/serialize/pytket/encoder/value_tracker.rs 73.91% 6 Missing ⚠️
tket-exts/src/tket_exts/__init__.py 37.50% 5 Missing ⚠️
tket-py/tket/passes.py 69.23% 4 Missing ⚠️
tket/src/serialize/pytket/encoder.rs 66.66% 1 Missing and 2 partials ⚠️
tket/src/passes/gridsynth.rs 97.53% 2 Missing ⚠️
Additional details and impacted files
@@                  Coverage Diff                  @@
##           kc/gridsynth_pass    #1376      +/-   ##
=====================================================
- Coverage              79.95%   79.90%   -0.06%     
=====================================================
  Files                    159      159              
  Lines                  20851    20858       +7     
  Branches               19873    19868       -5     
=====================================================
- Hits                   16672    16667       -5     
- Misses                  3192     3204      +12     
  Partials                 987      987              
Flag Coverage Δ
python 91.72% <59.09%> (-0.76%) ⬇️
qis-compiler 100.00% <ø> (ø)
rust 79.29% <92.08%> (-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.

@PabloAndresCQ PabloAndresCQ removed the request for review from doug-q January 27, 2026 15:54
@ss2165
Copy link
Member

ss2165 commented Jan 29, 2026

Looks to be lots of unrelated changes from merges in this PR?

@PabloAndresCQ
Copy link
Contributor Author

Oh wow, sorry, something went wrong when I merged main into this. The file diff must be because the branch to merge into is behind of main. I'll revert that back for ease of reviewing.

And apologies, I didn't mean to request review from anyone other than Chloe, that seems to have been done automatically :/

Copy link

@chloe-quantinuum chloe-quantinuum left a comment

Choose a reason for hiding this comment

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

Looks good to me!

// Remove the W i.e. the exp(i*pi/4) global phases
let gate_sequence = gates.replacen("W", "", gates.len());
// Add the nodes of the gridsynth sequence into the HUGR
let gridsynth_nodes: Vec<Node> = gate_sequence

Choose a reason for hiding this comment

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

Nice one! I had a TODO to rewrite this so thanks for taking care of it :)

while !normal_form_reached {
// Not the most efficient, but it's easiest to reach the normal form by doing
// string rewrites.
// TODO: Can be done with Regex, preferably by providing all LHS to the Regex

Choose a reason for hiding this comment

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

Just wondering, do you have any idea of the efficiency of using regex vs these replacements?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really, other than it's usually preferred. The two main issues with performance of the current approach are:

  • It is not changing the Strings in place, but creating multiple of them. As far as I can tell, Regex doesn't help with that. According to the docs: "The only methods that allocate new strings are the string replacement methods. All other methods (searching and splitting) return borrowed references into the haystack given."
  • The other thing is that we scan the String once per iteration and per LHS of a rewrite rule. Ideally, we would find all matches of the same scan and replace them all at once. This can probably be done with Regex' replace_all since it looks like the Replacer can be a closure |&Captures| -> String (see examples in the replace docs).

After staring at the docs of Regex for 30min, I decided it was not worth doing it (I couldn't figure out how to do it) until we've got some evidence that we need better performance here.

@PabloAndresCQ PabloAndresCQ merged commit ce8dd55 into kc/gridsynth_pass Jan 29, 2026
37 checks passed
@PabloAndresCQ PabloAndresCQ deleted the pam/gridsynth_improvements branch January 29, 2026 18:55
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.

3 participants