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: Only lower definitions to Hugr if they are used #496

Merged
merged 35 commits into from
Sep 17, 2024
Merged

Conversation

mark-koch
Copy link
Collaborator

@mark-koch mark-koch commented Sep 13, 2024

Closes #434 and closes #470.

@mark-koch mark-koch requested a review from a team as a code owner September 13, 2024 23:24
@mark-koch mark-koch requested review from croyzor and removed request for a team September 13, 2024 23:24
@codecov-commenter
Copy link

codecov-commenter commented Sep 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.55%. Comparing base (cc8a424) to head (232571c).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #496      +/-   ##
==========================================
+ Coverage   91.42%   91.55%   +0.12%     
==========================================
  Files          59       60       +1     
  Lines        6064     6131      +67     
==========================================
+ Hits         5544     5613      +69     
+ Misses        520      518       -2     

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

CompiledLocals = dict[PlaceId, Wire]


class CompiledGlobals:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We should probably rename this, considering the class does way more than just holding the globals. See #497

Base automatically changed from fix/notebook-imports to feat/implicit-decorators September 16, 2024 10:40
Base automatically changed from feat/implicit-decorators to main September 16, 2024 12:00
"""Compilation context containing all available definitions.

This context drives the Hugr lowering by keeping track of which definitions are
used when lowering the definitions provided via the `required` keyword. The
Copy link
Contributor

@acl-cqc acl-cqc Sep 17, 2024

Choose a reason for hiding this comment

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

I dropped the required parameter, as we already have other ways to add to the worklist (and compile_outer) from outside (e.g. for nested functions) - __getitem__ does basically the same thing

return self.compiled[def_id]

def _compile(self, defn: CheckedDef) -> CompiledDef:
if isinstance(defn, CompilableDef):
Copy link
Contributor

Choose a reason for hiding this comment

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

For another PR, I reckon we could probably get rid of CompilableDef by giving CheckedDefs an implementation of compile_outer that just returns self

@@ -325,19 +326,19 @@ def compile(self) -> Package:
return self._compiled_hugr

self.check()
checked_defs = self._imported_checked_defs | self._checked_defs
Copy link
Contributor

Choose a reason for hiding this comment

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

I removed def _compile_defs as the old code (removed here) was the only place calling it

Copy link
Contributor

@doug-q doug-q left a comment

Choose a reason for hiding this comment

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

Just one concerning uncovered function. Will check if it can be removed

@@ -72,6 +73,10 @@ def description(self) -> str:
a function, but got {description of this definition} instead".
"""

def compile(self) -> Package:
Copy link
Contributor

Choose a reason for hiding this comment

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

this is missing coverage, is it unused? I will check

@acl-cqc
Copy link
Contributor

acl-cqc commented Sep 17, 2024

Fixing #470 is a nice side-effect, not the right reason to do this, but this is good anyway :)

Copy link
Contributor

@doug-q doug-q left a comment

Choose a reason for hiding this comment

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

Note I deleted the unused Definition.compile

@acl-cqc
Copy link
Contributor

acl-cqc commented Sep 17, 2024

Note I deleted the unused Definition.compile

This was actually mentioned in the PR description:

Also adds a compile function to every definition that is useful when working with implicit modules: Instead of guppy.compile_module(), user can now do main.compile().

....but given there are no uses in tests, I think that's fair, can become another PR with usage examples easily enough

@acl-cqc acl-cqc added this pull request to the merge queue Sep 17, 2024
Merged via the queue into main with commit cc2c8a4 Sep 17, 2024
4 checks passed
@acl-cqc acl-cqc deleted the feat/lower-used branch September 17, 2024 09:25
@acl-cqc
Copy link
Contributor

acl-cqc commented Sep 17, 2024

Note I deleted the unused Definition.compile

This was actually mentioned in the PR description:
....but given there are no uses in tests, I think that's fair, can become another PR with usage examples easily enough

#504

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).
github-merge-queue bot pushed a commit that referenced this pull request Sep 23, 2024
Pulled out from #496. ~Needs tests.~

---------

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
4 participants