Skip to content

Conversation

@hkengo-qtnm
Copy link
Contributor

@hkengo-qtnm hkengo-qtnm commented Oct 6, 2025

This PR implements the Guppy compiler for modifiers.

Major changes

Issues

  • As the python syntax, current syntax of modifiers are not valid (dagger(...)/control(...)/power(...) are undefined) and need to be fixed. (See here)
  • Haven't tested, but I think type variables in modified block are not supported at this point. (See here)

Future implementation

  • UnitaryFlags, the annotations for functions that can be called in modified block.
  • Integrated test including emulation.

first modifier compiler, with extensions imported

modifier_compiler now directly compiles cfgs

minor

reference to tket repository with new extensions

integration test for modifier_compiler

minor
@hkengo-qtnm hkengo-qtnm changed the title feat: compiler for modifier feat: compiler for modifiers Oct 6, 2025
@hugrbot
Copy link
Collaborator

hugrbot commented Oct 6, 2025

This PR contains breaking changes to the public Python API.
Please deprecate the old API instead (if possible), or mark the PR with a ! to indicate a breaking change.

Breaking changes summary

@github-actions
Copy link
Contributor

github-actions bot commented Oct 6, 2025

🐰 Bencher Report

Branchfeat/modifier-compiler
TestbedLinux
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
microseconds (µs)
(Result Δ%)
Upper Boundary
microseconds (µs)
(Limit %)
tests/benchmarks/test_big_array.py::test_big_array_check📈 view plot
🚷 view threshold
672,413.08 µs
(-7.36%)Baseline: 725,827.99 µs
762,119.39 µs
(88.23%)
tests/benchmarks/test_big_array.py::test_big_array_compile📈 view plot
🚷 view threshold
1,599,982.28 µs
(+2.84%)Baseline: 1,555,822.91 µs
1,633,614.05 µs
(97.94%)
tests/benchmarks/test_big_array.py::test_big_array_executable📈 view plot
🚷 view threshold
7,280,427.90 µs
(+1.65%)Baseline: 7,162,481.43 µs
7,520,605.50 µs
(96.81%)
tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_check📈 view plot
🚷 view threshold
48,418.60 µs
(-33.85%)Baseline: 73,194.11 µs
76,853.81 µs
(63.00%)
tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_compile📈 view plot
🚷 view threshold
86,548.86 µs
(+0.82%)Baseline: 85,842.90 µs
90,135.04 µs
(96.02%)
tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_executable📈 view plot
🚷 view threshold
595,737.95 µs
(+0.51%)Baseline: 592,744.59 µs
622,381.81 µs
(95.72%)
tests/benchmarks/test_prelude.py::test_import_guppy📈 view plot
🚷 view threshold
24.54 µs
(-3.44%)Baseline: 25.41 µs
26.68 µs
(91.96%)
🐰 View full continuous benchmarking report in Bencher

@github-actions
Copy link
Contributor

github-actions bot commented Oct 6, 2025

🐰 Bencher Report

Branchfeat/modifier-compiler
TestbedLinux
Click to view all benchmark results
Benchmarkhugr_bytesBenchmark Result
bytes x 1e3
(Result Δ%)
Upper Boundary
bytes x 1e3
(Limit %)
hugr_nodesBenchmark Result
nodes
(Result Δ%)
Upper Boundary
nodes
(Limit %)
tests/benchmarks/test_big_array.py::test_big_array_compile📈 view plot
🚷 view threshold
142.66 x 1e3
(+0.10%)Baseline: 142.52 x 1e3
143.94 x 1e3
(99.11%)
📈 view plot
🚷 view threshold
6,590.00
(0.00%)Baseline: 6,590.00
6,655.90
(99.01%)
tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_compile📈 view plot
🚷 view threshold
21.57 x 1e3
(+0.69%)Baseline: 21.42 x 1e3
21.63 x 1e3
(99.69%)
📈 view plot
🚷 view threshold
606.00
(0.00%)Baseline: 606.00
612.06
(99.01%)
🐰 View full continuous benchmarking report in Bencher

@codecov-commenter
Copy link

codecov-commenter commented Oct 6, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.33%. Comparing base (e5f1e95) to head (7cd962b).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1287      +/-   ##
==========================================
+ Coverage   93.14%   93.33%   +0.18%     
==========================================
  Files         123      124       +1     
  Lines       11007    11096      +89     
==========================================
+ Hits        10253    10356     +103     
+ Misses        754      740      -14     

☔ 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.

@hkengo-qtnm hkengo-qtnm requested a review from mark-koch October 6, 2025 12:45
@hkengo-qtnm hkengo-qtnm marked this pull request as ready for review October 8, 2025 10:03
@hkengo-qtnm hkengo-qtnm requested a review from a team as a code owner October 8, 2025 10:03
Copy link
Collaborator

@mark-koch mark-koch left a comment

Choose a reason for hiding this comment

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

Thanks, looks good to me! Happy to merge once we have a tket release with the extension

Comment on lines +44 to +46
# TODO: Shouldn't this be `to_hugr_poly` since it can contain
# a variable with a generic type?
hugr_ty = body_ty.to_hugr(ctx)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, this will most likely break, but afaik nested functions that reference type variables from the parent function also aren't handled correctly.

I guess the best solution for now would be to detect this case and emit an error telling the user that this isn't supported yet.

To properly handle this, we'll need to turn the modifier into a generic function and then instantiate it with the variables from the parent function...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it okay to merge this PR without such a proper error handling?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, I think it's fine. We just have to wait for the tket release

Comment on lines +7 to +11
# Dummy variables to suppress Undefined name
# TODO: `ruff` fails when without these, which need to be fixed
dagger = object()
control = object()
power = object()
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it would be good to add these to guppylang.std.lang and then reexport in guppylang.std.builtins.

But I'm also happy if you prefer to do this in a separate PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I forgot to mention, but I made an issue for this (#1290)
I would rather think it should be left as a future feature to be handled in a better manner.

@mark-koch mark-koch added this pull request to the merge queue Oct 28, 2025
Merged via the queue into main with commit 439ff1a Oct 28, 2025
6 of 7 checks passed
@mark-koch mark-koch deleted the feat/modifier-compiler branch October 28, 2025 11:28
github-merge-queue bot pushed a commit that referenced this pull request Oct 29, 2025
🤖 I have created a release *beep* *boop*
---


##
[0.25.0](guppylang-internals-v0.24.0...guppylang-internals-v0.25.0)
(2025-10-28)


### ⚠ BREAKING CHANGES

* (guppy-internals) Arrays are now lowered to `borrow_array`s instead of
`value_array`s so elements do no longer need to be wrapped in options
during lowering.
* `checker.core.requires_monomorphization` renamed into
`require_monomorphization` and now operating on all parameters
simultaneously `tys.subst.BoundVarFinder` removed. Instead, use the new
`bound_vars` property on types, arguments, and consts.
`tys.parsing.parse_parameter` now requires a `param_var_mapping`.

### Features

* compiler for modifiers
([#1287](#1287))
([439ff1a](439ff1a))
* modifiers in CFG and its type checker (experimental)
([#1281](#1281))
([fe85018](fe85018))
* Turn type parameters into dependent telescopes
([#1154](#1154))
([b56e056](b56e056))
* update hugr, tket-exts and tket
([#1305](#1305))
([6990d85](6990d85))
* Use `borrow_array` instead of `value_array` for array lowering
([#1166](#1166))
([f9ef42b](f9ef42b))


### Bug Fixes

* compilation of affine-bounded type variables
([#1308](#1308))
([49ecb49](49ecb49))
* Detect unsolved generic parameters even if they are unused
([#1279](#1279))
([f830db0](f830db0)),
closes [#1273](#1273)
* Fix bug in symbolic pytket circuit loading with arrays
([#1302](#1302))
([e6b90e8](e6b90e8)),
closes [#1298](#1298)
* Improve track_hugr_side_effects, adding Order edges from/to
Input/Output ([#1311](#1311))
([3c6ce7a](3c6ce7a))
* multiline loop arguments
([#1309](#1309))
([836ef72](836ef72))

---
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: Seyon Sivarajah <[email protected]>
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.

5 participants