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: add Option.take() for swapping with None #809

Merged
merged 3 commits into from
Feb 18, 2025
Merged

feat: add Option.take() for swapping with None #809

merged 3 commits into from
Feb 18, 2025

Conversation

ss2165
Copy link
Member

@ss2165 ss2165 commented Feb 18, 2025

Example use case: measure without changing array indexing

@guppy
def measure_option(ar: array[Option[qubit], N], index: int) -> bool:
    return measure(ar[index].take().unwrap())

Example use case, measure without changing array indexing

```python

@guppy
def measure_option(ar: array[Option[qubit], N], index: int) -> bool:
    return measure(take(ar[index]))
```
@ss2165 ss2165 requested a review from a team as a code owner February 18, 2025 09:54
@ss2165 ss2165 requested a review from qartik February 18, 2025 09:54
@codecov-commenter
Copy link

codecov-commenter commented Feb 18, 2025

Codecov Report

Attention: Patch coverage is 57.14286% with 3 lines in your changes missing coverage. Please review.

Project coverage is 93.06%. Comparing base (622900f) to head (f5e45f5).

Files with missing lines Patch % Lines
guppylang/std/option.py 57.14% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #809      +/-   ##
==========================================
- Coverage   93.09%   93.06%   -0.04%     
==========================================
  Files          71       71              
  Lines        8478     8484       +6     
==========================================
+ Hits         7893     7896       +3     
- Misses        585      588       +3     

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

Copy link
Member

@qartik qartik left a comment

Choose a reason for hiding this comment

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

Just a side comment, what was the rationale behind using nothing in Guppy's option type as opposed to None?

@ss2165
Copy link
Member Author

ss2165 commented Feb 18, 2025

what was the rationale behind using nothing in Guppy's option type as opposed to None?

to avoid confusion with python's None which works quite differently due to how python Unions work dynamically.

Guppy uses None in type signatures to indicate void return

@ss2165 ss2165 added this pull request to the merge queue Feb 18, 2025
Merged via the queue into main with commit 9a459d5 Feb 18, 2025
4 checks passed
@ss2165 ss2165 deleted the ss/take branch February 18, 2025 14:20
github-merge-queue bot pushed a commit that referenced this pull request Feb 20, 2025
🤖 I have created a release *beep* *boop*
---


## [0.16.0](v0.15.0...v0.16.0)
(2025-02-19)


### ⚠ BREAKING CHANGES

* `CompiledGlobals` renamed to `CompilerContext`

### Features

* add `Option.take()` for swapping with None
([#809](#809))
([9a459d5](9a459d5))


### Code Refactoring

* Stop inlining array.__getitem__ and arrary.__setitem__
([#799](#799))
([bb199a0](bb199a0)),
closes [#786](#786)

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