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 qubit discard/measure methods #580

Merged
merged 5 commits into from
Oct 23, 2024
Merged

feat: add qubit discard/measure methods #580

merged 5 commits into from
Oct 23, 2024

Conversation

ss2165
Copy link
Member

@ss2165 ss2165 commented Oct 18, 2024

Extends the fact that allocation is tied to the qubit type by implementing measure/discard methods.

Note this includes a drive-by measure_reset operation which avoids resetting the qubit and just flip, might not be something to add in this PR.

I think this could be nicer to use in examples than the current inout usage.

benefits:
- importing qubits gets you all the methods
- with an LSP you get auto complete on `qubit.`
- Extends nicely to other qubit types that might have different interfaces
@ss2165 ss2165 marked this pull request as ready for review October 18, 2024 17:28
@ss2165 ss2165 requested a review from a team as a code owner October 18, 2024 17:28
@ss2165 ss2165 requested review from qartik and mark-koch and removed request for qartik October 18, 2024 17:28
@codecov-commenter
Copy link

codecov-commenter commented Oct 18, 2024

Codecov Report

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

Project coverage is 91.58%. Comparing base (73bb94a) to head (2808e60).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
guppylang/prelude/quantum.py 83.33% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #580      +/-   ##
==========================================
- Coverage   91.64%   91.58%   -0.06%     
==========================================
  Files          59       59              
  Lines        6269     6311      +42     
==========================================
+ Hits         5745     5780      +35     
- Misses        524      531       +7     

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

@@ -17,7 +17,7 @@ def test_basic(validate):
def foo(q: qubit) -> None: ...

@guppy(module)
def test(q: qubit @owned) -> qubit:
def test(q: qubit @ owned) -> qubit:
Copy link
Member Author

Choose a reason for hiding this comment

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

it appears my formatter has been at all the decorators. I can undo this if necessary


@guppy
@no_type_check
def cx(self: "qubit", target: "qubit") -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would suggesttarget.cx(control) instead,
so the n-controlled cases keep the same structure.

target.toffoli(control0, control1)
target.ncx(*controls)

Copy link
Contributor

Choose a reason for hiding this comment

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

Whichever way round it is, I see a lot of potential for bugs caused by people getting it the wrong way round.
In general I'm not so keen on forcing multi-qubit operations to have a "distinguished" qubit in this way: in general there's no natural way to select which qubit it should be.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that's very valid. How about we restrict it a specific set of special single qubit operations: alloc (already the case), discard, measure (non destructive), reset, and any variants of those above (e.g. measure_reset, destructive measure). These special set can be implemented in terms of the existing inout functions as in this PR currently.

Copy link
Contributor

Choose a reason for hiding this comment

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

Happy with that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@ss2165 ss2165 changed the title feat: add quantum functions as qubit methods feat: add qubit discard/measure methods Oct 23, 2024
@ss2165 ss2165 added this pull request to the merge queue Oct 23, 2024
Merged via the queue into main with commit 242fa44 Oct 23, 2024
3 checks passed
@ss2165 ss2165 deleted the ss/self-qubit branch October 23, 2024 15:05
github-merge-queue bot pushed a commit that referenced this pull request Nov 12, 2024
🤖 I have created a release *beep* *boop*
---


## [0.13.0](v0.12.2...v0.13.0)
(2024-11-12)


### ⚠ BREAKING CHANGES

* `prelude` module renamed to `std`

### Features

* add `qubit` discard/measure methods
([#580](#580))
([242fa44](242fa44))
* Add `SizedIter` wrapper type
([#611](#611))
([2e9da6b](2e9da6b))
* conventional results post processing
([#593](#593))
([db96224](db96224))
* Improve compiler diagnostics
([#547](#547))
([90d465d](90d465d)),
closes [#551](#551)
[#553](#553)
[#586](#586)
[#588](#588)
[#587](#587)
[#590](#590)
[#600](#600)
[#601](#601)
[#606](#606)
* restrict result tag sizes to 256 bytes
([#596](#596))
([4e8e00f](4e8e00f)),
closes [#595](#595)


### Bug Fixes

* Mock guppy decorator during sphinx builds
([#622](#622))
([1cccc04](1cccc04))


### Documentation

* Add DEVELOPMENT.md
([#584](#584))
([1d29d39](1d29d39))
* Fix docs build ([#639](#639))
([bd6011c](bd6011c))


### Miscellaneous Chores

* Manually set last release commit
([#643](#643))
([b2d569b](b2d569b))


### Code Refactoring

* rename prelude to std
([#642](#642))
([1a68e8e](1a68e8e))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: Agustín Borgna <agustin.borgna@quantinuum.com>
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.

5 participants