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

Allow implicit discard of qubits at the end of main #781

Open
ss2165 opened this issue Jan 27, 2025 · 4 comments
Open

Allow implicit discard of qubits at the end of main #781

ss2165 opened this issue Jan 27, 2025 · 4 comments

Comments

@ss2165
Copy link
Member

ss2165 commented Jan 27, 2025

Qubits leftover at the end of main are being discarded anyway, users shouldn't have to do it manually just to satisfy the type checker. This should significantly reduce the need for discard calls - in programs that don't use ancillas.

@mark-koch
Copy link
Collaborator

Note that we still need to generate Hugr discards which is not entirely trivial when considering nested structs, arrays, and lists.

Also, would this be a special case for the qubit type only?

@cqc-alec
Copy link
Contributor

Note that we still need to generate Hugr discards which is not entirely trivial when considering nested structs, arrays, and lists.

Also, would this be a special case for the qubit type only?

I think it should apply to all linear types. An executable should be allowed to exit without having to clean up after itself.

But this makes me wonder if we should change the type checker rather than guppy (so it would need to understand the concept of a main program).

@aborgna-q
Copy link
Collaborator

  • If we are doing all linear types, should we have a __drop__/__leak__ implementation that gets called automatically in these cases? (For qubit it would be a noop).

  • Seyon mentioned elsewhere to add a @guppy.entrypoint marker that would trigger this behaviour.

@cqc-alec
Copy link
Contributor

cqc-alec commented Jan 29, 2025

  • If we are doing all linear types, should we have a __drop__/__leak__ implementation that gets called automatically in these cases? (For qubit it would be a noop).

Seems a good idea -- for example, an output stream would want to flush itself when dropped. Not sure if we have any non-trivial examples in guppy at the moment?

  • Seyon mentioned elsewhere to add a @guppy.entrypoint marker that would trigger this behaviour.

Yes, better than relying on a function name.

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

No branches or pull requests

4 participants