-
Notifications
You must be signed in to change notification settings - Fork 6
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
feat(hugr-py): AsCustomOp
protocol for user-defined custom op types.
#1290
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1290 +/- ##
==========================================
- Coverage 87.07% 87.07% -0.01%
==========================================
Files 106 106
Lines 19295 19335 +40
Branches 17073 17073
==========================================
+ Hits 16801 16835 +34
- Misses 1717 1723 +6
Partials 777 777
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Replace existing custom operation types with this. Follow ups: - Similar thing for custom types. - Optional: allow these types to register themselves with `serialization.ops.CustomOp` so they can be deserialized directly.
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.
LGTM
hugr-py/src/hugr/std/int.py
Outdated
case [tys.BoundedNatArg(n=a1), tys.BoundedNatArg(n=a2)]: | ||
return cls(arg1=a1, arg2=a2) | ||
case _: | ||
return None |
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.
Should this raise an error? If the name and extension match then we should always be able to extract the op
🤖 I have created a release *beep* *boop* --- ## [0.5.0](hugr-py-v0.4.0...hugr-py-v0.5.0) (2024-07-29) ### ⚠ BREAKING CHANGES * Eq type bound removed. References to `Eq` in serialized HUGRs will be treated as `Copyable`. * **hugr-core:** All Hugrs serialised with earlier versions will fail to deserialise * opaque type parameters replaced with string parameters. ### Features * **hugr-py:** `AsCustomOp` protocol for user-defined custom op types. ([#1290](#1290)) ([1db43eb](1db43eb)) * remove the `Eq` type bound. ([#1364](#1364)) ([1218d21](1218d21)) * replace opaque type arguments with String ([#1328](#1328)) ([24b2217](24b2217)), closes [#1308](#1308) * Serialization upgrade path ([#1327](#1327)) ([d493139](d493139)) ### Bug Fixes * add op's extension to signature check in `resolve_opaque_op` ([#1317](#1317)) ([01da7ba](01da7ba)) * **hugr-core:** bump serialisation version with no upgrade path ([#1352](#1352)) ([657cbb0](657cbb0)) * **hugr-py:** ops require their own extensions ([#1303](#1303)) ([026bfcb](026bfcb)), closes [#1301](#1301) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Downstream users can implement this protocol to use their own convenience classes. Typically a use wants to implement:
to_custom
__call__
to provide a useful calling signature.from_custom
if different instances of the type correspond to different ops (non-singleton).Replace existing custom operation types with this.
Follow ups:
serialization.ops.CustomOp
so they can be deserialized directly.