Skip to content
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

Merged
merged 2 commits into from
Jul 10, 2024

Conversation

ss2165
Copy link
Member

@ss2165 ss2165 commented Jul 10, 2024

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:

  • Similar thing for custom types.
  • Optional: allow these types to register themselves with serialization.ops.CustomOp so they can be deserialized directly.

@ss2165 ss2165 requested a review from aborgna-q July 10, 2024 11:31
@ss2165 ss2165 requested a review from a team as a code owner July 10, 2024 11:31
Copy link

codecov bot commented Jul 10, 2024

Codecov Report

Attention: Patch coverage is 89.85507% with 7 lines in your changes missing coverage. Please review.

Project coverage is 87.07%. Comparing base (7d82245) to head (b3824bb).
Report is 3 commits behind head on main.

Files Patch % Lines
hugr-py/src/hugr/std/int.py 80.00% 5 Missing ⚠️
hugr-py/src/hugr/ops.py 94.73% 2 Missing ⚠️
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              
Flag Coverage Δ
python 91.42% <89.85%> (-0.12%) ⬇️

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.

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.
Copy link
Collaborator

@aborgna-q aborgna-q left a comment

Choose a reason for hiding this comment

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

LGTM

case [tys.BoundedNatArg(n=a1), tys.BoundedNatArg(n=a2)]:
return cls(arg1=a1, arg2=a2)
case _:
return None
Copy link
Collaborator

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

@ss2165 ss2165 enabled auto-merge July 10, 2024 15:40
@ss2165 ss2165 added this pull request to the merge queue Jul 10, 2024
Merged via the queue into main with commit 1db43eb Jul 10, 2024
20 checks passed
@ss2165 ss2165 deleted the ss/custom-eq branch July 10, 2024 15:46
github-merge-queue bot pushed a commit that referenced this pull request Jul 29, 2024
🤖 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).
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.

2 participants