-
Notifications
You must be signed in to change notification settings - Fork 18
feat: add qsystem op for measure leaked #1057
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1057 +/- ##
==========================================
- Coverage 92.37% 92.31% -0.07%
==========================================
Files 112 112
Lines 10818 10848 +30
==========================================
+ Hits 9993 10014 +21
- Misses 825 834 +9 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Everything seems to be working. The
I'm not sure that we can omit discard, because I don't think that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are Marks changes in #1075. I'm happy to rebase to that branch if you want, but I'm inclined to just wait until that's merged.
tests/integration/test_qsystem.py
Outdated
| q = qubit() | ||
| m = measure(q) | ||
| return m |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the intention of this code pattern?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't represent a "real" pattern. It is intended to make sure that things type check and that the variable q was properly consumed when measure_leaked(q) was called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be nice to document that. Or remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
mark-koch
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, but we should wait to merge until #1075 is merged
I'm not sure that we can omit discard, because I don't think that is_leaked should consume _measurement. Concrete example is in test_qsystem.
I think discard is nice to have 👍
|
|
||
| @guppy | ||
| @no_type_check | ||
| def measure_leaked(q: qubit @ owned) -> "MaybeLeaked": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a dosctring here?
guppylang/std/qsystem/__init__.py
Outdated
| @guppy | ||
| @no_type_check | ||
| def to_result(self: "MaybeLeaked @ owned") -> Option[bool]: | ||
| """Get the measurement result if not leaked.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe something like this would be more accurate?
| """Get the measurement result if not leaked.""" | |
| """Returns the measurement result or `nothing` if leaked.""" |
|
@mark-koch - it looks like #1075 was merged. Anything else we should wait on for this one? |
pyproject.toml
Outdated
| # Uncomment these to test the latest dependency version during development | ||
| # hugr = { git = "https://github.com/CQCL/hugr", subdirectory = "hugr-py", tag = "hugr-v0.20.2" } | ||
| # tket2-exts = { git = "https://github.com/CQCL/tket2", subdirectory = "tket2-exts", rev = "652a7d0" } | ||
| tket2-exts = { git = "https://github.com/CQCL/tket2", subdirectory = "tket2-exts", rev = "38d1c6f" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this rev dependency still needed? If yes we should wait for a tket-exts release before merging
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, good catch, we can wait until then (corresponding tket2 release PR CQCL/tket2#952)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is the one you need: CQCL/tket2#951
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, exts. Got it, thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now released
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bumped exts to the new release. Will merge when you remove wait to merge in case there are any other gotchas :).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the only concern is selene support, @jake-arkinstall thoughts on merging?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From @jake-arkinstall in teams:
I have no concerns, merge away. It won’t work with Selene and it’ll link error if used, but it won’t break existing usage (if it isn’t used it isn’t emitted). Selene can play catch up next week.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ss2165 - I think this is ready to merge. I'll do so tomorrow morning (Colorado time) unless you tell me otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
![]()
🤖 I have created a release *beep* *boop* --- ## [0.21.0](guppylang-v0.20.0...guppylang-v0.21.0) (2025-08-04) ### ⚠ BREAKING CHANGES * All compiler-internal and non-userfacing functionality is moved into a new `guppylang_internals` package * `guppy.compile(foo)` and `guppy.check(foo)` replaced with `foo.check()` and `foo.compile()` * default HUGR output uses compressed binary encoding. * `guppylang.tracing.object.GuppyDefinition` moved to `guppylang.defs.GuppyDefinition` `guppylang.tracing.object.TypeVarGuppyDefinition` moved and renamed to `guppylang.defs.GuppyTypeVarDefinition` * All `to_hugr` methods on types, arguments, and parameters now require a `ToHugrContext` `CompileableDef.compile_outer` now requires a `ToHugrContext` `guppy.hugr_op` now passes the compiler context to the function generating the op `CheckedFunctionDef` now implements `MonomorphizableDef` instead of `CompileableDef` `CompilerContext.build_compiled_def` now requires an instantiation for the definition's type parameters The `ToHugrContext` protocol now requires two additional methods: `type_var_to_hugr` and `const_var_to_hugr` `CompilerContext.{compiled, worklist}` and `CompilationEngine.compiled` are now indexed by a tuple of `DefId` and optional `PartiallyMonomorphizedArgs` * comptime code that previously used constant integers outside i64 will now fail to compile. * Capturing closures are now disabled by default. Enabling them requires calling `guppylang.enable_experimental_features()`, however note that they are not supported throughout the stack. ### Features * Add `Future` type ([#1075](#1075)) ([5ad7673](5ad7673)) * add error when constant integer out of bounds ([#1084](#1084)) ([eee77ae](eee77ae)) * Add guppy version metadata to hugr entrypoint ([#1039](#1039)) ([0eafbd9](0eafbd9)), closes [#1037](#1037) * Add manual registration of extensions ([#1045](#1045)) ([4b42936](4b42936)) * add qsystem op for measure leaked ([#1057](#1057)) ([c555727](c555727)) * add selene via optional feature and use for testing ([#1081](#1081)) ([cefc70e](cefc70e)) * Add support for V and Vdg. ([#1094](#1094)) ([6b0d44a](6b0d44a)) * Allow indexing on tuples ([#1038](#1038)) ([0e9097e](0e9097e)), closes [#711](#711) * Declare WASM modules in guppy ([#942](#942)) ([e1240fb](e1240fb)) * Extend comptime arguments to arbitrary non-linear types ([#1110](#1110)) ([384dd8c](384dd8c)) * Make decorator return types more precise ([#1115](#1115)) ([c84e8b1](c84e8b1)) * set hugr entrypoint to compiled function ([#1063](#1063)) ([16bd267](16bd267)) * store used extensions and versions in HUGR metadata ([#1049](#1049)) ([a9a300c](a9a300c)), closes [#1048](#1048) * Support arbitrary const generics via monomorphisation ([#1033](#1033)) ([bcf9865](bcf9865)) * Support Python 3.12 generic syntax ([#1051](#1051)) ([ab2e118](ab2e118)), closes [#823](#823) * Top level compile + emulate Interface ([#1127](#1127)) ([5e2f595](5e2f595)) * update to hugr-py v0.13 ([#1083](#1083)) ([8f071c8](8f071c8)) * use `core.` prefix for metadata keys ([#1055](#1055)) ([2bf0d68](2bf0d68)) ### Bug Fixes * Allow array comprehension syntax in comptime functions ([#1068](#1068)) ([da8f04a](da8f04a)), closes [#1067](#1067) * Allow struct redefinitions for Python < 3.13 ([#1108](#1108)) ([959a4e4](959a4e4)), closes [#1107](#1107) * Correctly detect `[@Custom](https://github.com/custom)_guppy_decorator` in nested scopes ([#1086](#1086)) ([678583c](678583c)) * Fix diagnostics rendering for comptime entrypoints ([#1099](#1099)) ([fdd2676](fdd2676)), closes [#1097](#1097) * Fix frame lookup for Python 3.12 annotation scopes ([#1120](#1120)) ([a69e489](a69e489)), closes [#1116](#1116) * Fix hugr conversion and bounds checks on numeric literals ([#1100](#1100)) ([73d5e92](73d5e92)) * Fix Jupyter notebook diagnostic rendering ([#1109](#1109)) ([6002474](6002474)) * Fix nested function definitions in Python 3.12 ([#1064](#1064)) ([090f920](090f920)) * Stop showing temporary variables in comptime diagnostics ([#1112](#1112)) ([63854c5](63854c5)), closes [#1111](#1111) * support comptime entrypoint ([#1079](#1079)) ([721e3dd](721e3dd)) * Turn capturing closures into experimental feature ([#1065](#1065)) ([a959b18](a959b18)) ### Documentation * add docstrings for emulator module ([#1131](#1131)) ([b33e065](b33e065)) * add quantum and qsystem gate definitions ([#912](#912)) ([32a4bbc](32a4bbc)) * Fix docstrings ([#1128](#1128)) ([0aded85](0aded85)) * Improve RNG docs ([#1043](#1043)) ([8640f06](8640f06)) * replace `compile_module` usage in README ([#1041](#1041)) ([03ccf3a](03ccf3a)) * Update guppy examples ([#1121](#1121)) ([b994655](b994655)) ### Code Refactoring * Split up into `guppylang_internals` package ([#1126](#1126)) ([81d50c0](81d50c0)) --- 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]>
Closes: #1056
Depends on:
Futuretype #1075