fix: guppy_to_circuit always returns num_operations = 0#1200
fix: guppy_to_circuit always returns num_operations = 0#1200aborgna-q merged 10 commits intoQuantinuum:mainfrom
Conversation
d1d5028 to
930f7ef
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1200 +/- ##
==========================================
+ Coverage 78.87% 79.14% +0.27%
==========================================
Files 160 160
Lines 20421 20412 -9
Branches 19489 19480 -9
==========================================
+ Hits 16107 16156 +49
+ Misses 3324 3275 -49
+ Partials 990 981 -9
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Hi, thanks for the PR! The code looks good. Counting operations on an structure program is not well defined, so defaulting to "count everything on all function definitions" sounds reasonable. We'll have to think about alternative count operations in the future. Your test should go in |
|
I have added the tests using Update: For the CI tests to succeed, I would need to add |
Ah, yes. Let me push a commit to your branch that sets it up (we have to move the dependency from elsewhere to the root workspace). |
|
As a side note, I think the tests may fail since the guppy functions are all defined on the same file (so you'll end up counting all the operations in all of the definitions). The alternative is to create circuits for each test case separatedly, def global_calls() -> Tk2Circuit:
@guppy
def inner(q0: qubit @ owned, angle: angle) -> qubit:
rz(q0, angle)
return q0
@guppy
def mid(q0: qubit @ owned) -> qubit:
a = angle(3.14)
return inner(q0, a)
@guppy
def outer(q0: qubit @ owned) -> qubit:
h(q0)
return mid(q0)
return guppy_to_circuit(outer)
testdata = [
(global_calls, 3),
...
] |
|
Sorry for the noise. Adding guppy as a dependency here is somewhat annoying since we're trying to avoid the Our previous solution was pinning a specific commit of guppylang for the tests that required it in The ideal alternative to avoid this is to use pre-compiled guppy programs here (like the ones in |
|
I moved your tests to pre-compiled hugrs, to avoid the guppylang dependency. Thanks again for the PR! |
🤖 I have created a release *beep* *boop* --- ## [0.12.11](tket-py-v0.12.10...tket-py-v0.12.11) (2025-11-13) ### Bug Fixes * **ci:** Make wheels compatible with MacOS 15.0 (#1248) ([49c5996](49c5996)) * Don't use opgroup in pytket barrier encoding (#1251) ([49c5996](49c5996)) * guppy_to_circuit always returns num_operations = 0 (#1200) ([49c5996](49c5996)) * **pytket-decoder:** Avoid QAllocating and immediately freeing qubits ([#1256](#1256)) ([228ff52](228ff52)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). --------- Co-authored-by: Agustín Borgna <[email protected]>
## 🤖 New release * `tket`: 0.16.0 -> 0.17.0 (✓ API compatible changes) * `tket-qsystem`: 0.22.0 -> 0.23.0 (✓ API compatible changes) <details><summary><i><b>Changelog</b></i></summary><p> ## `tket` <blockquote> ## [0.17.0](tket-v0.16.0...tket-v0.17.0) - 2026-02-02 ### Bug Fixes - *(encoded-circ)* Track unsupported wires between input and output ([#1224](#1224)) - Multiple fixes to the pytket encoder ([#1226](#1226)) - Don't use opgroup in pytket barrier encoding ([#1251](#1251)) - guppy_to_circuit always returns num_operations = 0 ([#1200](#1200)) - *(pytket-decoder)* Avoid QAllocating and immediately freeing qubits ([#1256](#1256)) - Encoding of opaque subgraphs with no associated qubit/bit ([#1295](#1295)) - [**breaking**] Don't rely on command params for pytket barriers ([#1298](#1298)) - Track output qubits in CircuitInfo ([#1304](#1304)) - Wrongly reused qubit IDs in pytket encoding ([#1358](#1358)) ### New Features - Deprecate local find_tuple_unpack rewrite ([#1188](#1188)) - Add CopyableExpressionAST ([#1209](#1209)) - `NormalizeGuppy` pass to simplify generated structure ([#1220](#1220)) - [**breaking**] pytket EncodedCircuit struct for in-place pytket optimisation ([#1211](#1211)) - [**breaking**] Interval is independent of resource IDs and scope position ([#1205](#1205)) - Don't translate usizes to pytket ([#1241](#1241)) - BorrowSquashPass to elide redundant borrow/return ops ([#1159](#1159)) - [**breaking**] Bump hugr to 0.25.0 ([#1325](#1325)) - Remove order edges in NormalizeGuppy pass ([#1326](#1326)) - [**breaking**] Remove deprecated unpack tuple pass ([#1387](#1387)) ### Refactor - Remove contain_qubits, use TypeUnpacker ([#1283](#1283)) - [**breaking**] Replace Subcircuit with SiblingSubgraph ([#1288](#1288)) - *(metadata)* [**breaking**] Migrate all metadata keys onto the new metadata traits ([#1328](#1328)) </blockquote> ## `tket-qsystem` <blockquote> ## [0.23.0](tket-qsystem-v0.22.0...tket-qsystem-v0.23.0) - 2026-02-02 ### Bug Fixes - [**breaking**] Don't rely on command params for pytket barriers ([#1298](#1298)) - Wrongly reused qubit IDs in pytket encoding ([#1358](#1358)) ### New Features - `NormalizeGuppy` pass to simplify generated structure ([#1220](#1220)) - Allow running arbitrary serializable pytket passes on hugrs ([#1266](#1266)) - BorrowSquashPass to elide redundant borrow/return ops ([#1159](#1159)) - [**breaking**] Bump hugr to 0.25.0 ([#1325](#1325)) - Remove order edges in NormalizeGuppy pass ([#1326](#1326)) - hide new public funcs introduced by linearization ([#1333](#1333)) ### Testing - regenerate guppy_opt examples, and count gates ([#1249](#1249)) - run pytket on guppy_opt tests, measure (very limited) success ([#1250](#1250)) </blockquote> </p></details> --- This PR was generated with [release-plz](https://github.com/release-plz/release-plz/).
Addresses #1130
Fixes the bug where the
num_operationsmethod oftket::circuit::Circuitalways returned0for circuits whose top-levelFuncDefcontained onlyInput,Output, andCfgnodes. Additionally, the existing implementation never visited siblingFuncDefs.Root cause
DataflowParent, butCfgandConditionalnodes (which also containExtensionOpandOpaqueOpops) do not have that tag.self.parent(), which is the entry-point of the underlying hugr, without any explicit handling ofCallops.Fix
CfgandConditionalnodes as traversal parents in addition toDataflowParentnodes.self.hugr().module_root()to cover allFuncDefs.Testing
The script test_count_ops.py extends the script in the issue by creating a variety of Guppy circuits and checks that
num_operations()returns nonzero and scales with circuit complexity.I’d appreciate guidance on:
tketortket-py.PS: The error in the example
tket-py/examples/2-Rewriting-Circuits.ipynbis resolved, however the renderedmerged_circuitdoesn't show the intended rewrite.