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

fix: use correct array ops #503

Merged
merged 4 commits into from
Sep 17, 2024
Merged

fix: use correct array ops #503

merged 4 commits into from
Sep 17, 2024

Conversation

doug-q
Copy link
Contributor

@doug-q doug-q commented Sep 16, 2024

No description provided.

@doug-q doug-q requested a review from a team as a code owner September 16, 2024 12:39
@codecov-commenter
Copy link

codecov-commenter commented Sep 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.59%. Comparing base (a980ec2) to head (a44709b).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #503      +/-   ##
==========================================
+ Coverage   91.54%   91.59%   +0.04%     
==========================================
  Files          60       60              
  Lines        6130     6152      +22     
==========================================
+ Hits         5612     5635      +23     
+ Misses        518      517       -1     

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

Copy link
Contributor

@acl-cqc acl-cqc left a comment

Choose a reason for hiding this comment

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

Tests? Let's make sure that the non-starred build_panic does actually work....
(EDIT: other than that, this is super-neat 👍 )

@@ -50,21 +50,17 @@ class ArrayGetitemCompiler(CustomCallCompiler):
def build_classical_getitem(
self,
array: Wire,
array_ty: ht.Type,
array_ty: ht.Array,
Copy link
Contributor

Choose a reason for hiding this comment

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

in passing, it seems a bit redundant to pass both array_ty and elem_ty in at the same time. There seem to be about 5 different ways to get hold of the element type (all of which should give the same answer - type args to the array type, type args to the op, type of the input wire, .....)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes indeed. I will change this back to Type, as it was before.

conditional = builder.add_conditional(result)
with conditional.add_case(0) as case:
error = build_error(case, 1, "array get index out of bounds")
case.set_outputs(build_panic(case, [], [elem_ty], error))
Copy link
Contributor

Choose a reason for hiding this comment

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

not *build_panic? Ah, it returns a Wire (rather than a singleton tuple/collection) if there is exactly one result type (even if that's passed in as a list rather than as a type)? I.e.

case.set_outputs(*build_panic(case, [], [elem_ty], error))

or

case.set_outputs(build_panic(case, [], elem_ty, error))

this may well be right, but does look a bit like there is something non-uniform about the handling of singleton elements by these various different APIs that we might want to come back to later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's very confusing, figuring out to add the asterisk to the other callsite took me more than an hour. I will change this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think mypy is complaining about this too

Copy link
Contributor

Choose a reason for hiding this comment

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

AFAICS set_outputs takes *Wire (i.e. varargs), so the elements need to be individual Wires not a list[Wire] - if you had a list[Wire] you would have to use *. That's in hugr repo.

However, build_panic (in guppy repo) claims to return a single Wire, so there shouldn't be any *ing of that (?!). And the body of build_panic returns builder.add_op(...), where add_op (in Hugr repo) claims to return a Node - so that doesn't look right, either.

So I'm not sure what's going on here!

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, got it - your latest commit fixes things so they make sense and even mypy agrees. (build_panic returning Node means you can * that to get a series of Wires). Looks good now!

@doug-q
Copy link
Contributor Author

doug-q commented Sep 16, 2024

Tests?

There are already tests for all of this. Changing from "UnsupportedOp" to an op from "prelude" does change the codepath, but it still passes.

@doug-q doug-q requested a review from acl-cqc September 16, 2024 14:32
@acl-cqc
Copy link
Contributor

acl-cqc commented Sep 17, 2024

Tests?

There are already tests for all of this. Changing from "UnsupportedOp" to an op from "prelude" does change the codepath, but it still passes.

Can we do an execution test now? (If execute-llvm doesn't lower array ops then fair enough but otherwise it might only be a few lines and would be good to have!)

Copy link
Contributor

@acl-cqc acl-cqc left a comment

Choose a reason for hiding this comment

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

It'd be nice to have an execution test, but that could follow in another PR. This looks great, thanks @doug! :)

@doug-q
Copy link
Contributor Author

doug-q commented Sep 17, 2024

It'd be nice to have an execution test, but that could follow in another PR. This looks great, thanks @doug! :)

You're right Alan, I've added said test.

@doug-q doug-q added this pull request to the merge queue Sep 17, 2024
Merged via the queue into main with commit 720d8b8 Sep 17, 2024
3 checks passed
@doug-q doug-q deleted the doug/prelude-arrays branch September 17, 2024 10:43
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.

3 participants