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!: Support implicit modules for all decorators and turn builtins into implicit module #476

Merged
merged 23 commits into from
Sep 16, 2024

Conversation

mark-koch
Copy link
Collaborator

Closes #463.

BREAKING CHANGE: The GuppyModule argument is now optional for all decorators and no longer the first positional argument. Removed the explicit module objects builtins, quantum, and angle.

Comment on lines 107 to 127
for s in inspect.stack():
if s.filename != __file__:
filename = s.filename
module = inspect.getmodule(s.frame)
frame = inspect.currentframe()
while frame:
info = inspect.getframeinfo(frame)
if info and info.filename != __file__:
filename = info.filename
module = inspect.getmodule(frame)
# Skip frames from the `pretty_error` decorator
if module != guppylang.error:
break
frame = frame.f_back
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Drive-by: inspect.stack() is inefficient, it suffices to get the current frame and walk back. Now that we make heavy use of implicit modues, this actually makes a difference

@codecov-commenter
Copy link

codecov-commenter commented Sep 11, 2024

Codecov Report

Attention: Patch coverage is 97.69231% with 9 lines in your changes missing coverage. Please review.

Project coverage is 91.42%. Comparing base (0b0b1af) to head (8f75828).

Files with missing lines Patch % Lines
guppylang/decorator.py 94.89% 5 Missing ⚠️
guppylang/ipython_inspect.py 33.33% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #476      +/-   ##
==========================================
- Coverage   91.45%   91.42%   -0.03%     
==========================================
  Files          59       59              
  Lines        6015     6064      +49     
==========================================
+ Hits         5501     5544      +43     
- Misses        514      520       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ss2165 ss2165 removed this from the guppylang 0.12.0 milestone Sep 11, 2024
@mark-koch mark-koch marked this pull request as ready for review September 12, 2024 10:01
@mark-koch mark-koch requested a review from a team as a code owner September 12, 2024 10:01
@mark-koch mark-koch requested a review from croyzor September 12, 2024 10:01
@croyzor croyzor requested review from ss2165 and acl-cqc and removed request for croyzor September 13, 2024 16:03
Copy link
Member

@ss2165 ss2165 left a comment

Choose a reason for hiding this comment

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

🚀

defn = RawStructDef(DefId.fresh(module), cls.__name__, None, cls)
module.register_def(defn)
module._register_buffered_instance_funcs(defn)
# If we mistakenly initialised the method buffer of the implicit module
# we can just clear it here
if module != implicit_module:
Copy link
Member

Choose a reason for hiding this comment

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

this is doing pointer equality on the module then?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, since GuppyModule doesn't implement __eq__


def declare(self, module: GuppyModule) -> FuncDeclDecorator:
@overload
Copy link
Member

Choose a reason for hiding this comment

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

nice

@ss2165 ss2165 force-pushed the feat/implicit-decorators branch from 1a51d1c to 6f6a564 Compare September 13, 2024 17:13
@mark-koch mark-koch changed the base branch from main to feat/quantum-module September 13, 2024 20:59
Base automatically changed from feat/quantum-module to main September 16, 2024 10:03
@acl-cqc acl-cqc added this pull request to the merge queue Sep 16, 2024
Merged via the queue into main with commit cc8a424 Sep 16, 2024
3 checks passed
@acl-cqc acl-cqc deleted the feat/implicit-decorators branch September 16, 2024 12:00
github-merge-queue bot pushed a commit that referenced this pull request Sep 18, 2024
🤖 I have created a release *beep* *boop*
---


## [0.12.0](v0.11.0...v0.12.0)
(2024-09-18)


### ⚠ BREAKING CHANGES

* Pytket circuits loaded via a `py` expression no longer take ownership
of the passed qubits.
* Lists and function tensors are no longer available by default.
`guppylang.enable_experimental_features()` must be called before
compilation to enable them.
* The `GuppyModule` argument is now optional for all decorators and no
longer the first positional argument. Removed the explicit module
objects `builtins`, `quantum`, and `angle`.
* `quantum_functional` is now its own Guppy module and no longer
implicitly comes with `quantum`.
* Linear function arguments are now borrowed by default; removed the now
redundant `@inout` annotation

### Features

* Add functions to quantum module and make quantum_functional
independent ([#494](#494))
([0b0b1af](0b0b1af))
* Hide lists and function tensors behind experimental flag
([#501](#501))
([c867f48](c867f48))
* Make linear types [@inout](https://github.com/inout) by default; add
[@owned](https://github.com/owned) annotation
([#486](#486))
([e900c96](e900c96))
* Only lower definitions to Hugr if they are used
([#496](#496))
([cc2c8a4](cc2c8a4))
* Support implicit modules for all decorators and turn builtins into
implicit module ([#476](#476))
([cc8a424](cc8a424))
* Use inout for pytket circuits
([#500](#500))
([a980ec2](a980ec2))


### Bug Fixes

* `angle` is now a struct and emitted as a rotation
([#485](#485))
([992b138](992b138))
* Evade false positives for inout variable usage
([#493](#493))
([6fdb5d6](6fdb5d6))
* Fix redefinition of structs
([#499](#499))
([0b156e9](0b156e9))
* Initialise _checked in GuppyModule
([#491](#491))
([3dd5dd3](3dd5dd3)),
closes [#489](#489)
* use correct array ops
([#503](#503))
([720d8b8](720d8b8))

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

Add implicit versions of decorator methods
4 participants