Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Returning qubit allocated within operation should yield an error #1476

Open
adrianleh opened this issue Jun 23, 2022 · 0 comments
Open

Returning qubit allocated within operation should yield an error #1476

adrianleh opened this issue Jun 23, 2022 · 0 comments
Labels
area: language Changes to the Q# language enhancement New request or suggestion for an improvement

Comments

@adrianleh
Copy link

Is your feature request related to a problem? Please describe.

When returning qubits allocated within an operation, the compiler does not flag any issues, however the qubit will try to be deallocated. Currently this issue manifests by causing a ReleasedQubitsAreNotInZeroState exception.

A simple example program which causes this behavior can be found below:

operation OneState() : Qubit {
    use q = Qubit();
    X(q);
    return q;
}

Describe the solution you'd like
There is two solutions that I thought of for this issue:

  • A check to ensure that returned qubits are still alive and will not be deallocated. Such a check should yield a compiler error/warning
  • Create a system, similar to C++ unique pointers, to move a qubit's ownership to the function above the call when returning. This is of course a more extensive suggestion that would likely entail more changes than adding move semantics, as it would require ownership support across the board

Additional context
There is a related issue filed in the runtime: microsoft/qsharp-runtime#984

@adrianleh adrianleh added enhancement New request or suggestion for an improvement needs triage An initial review by a maintainer is needed labels Jun 23, 2022
@bettinaheim bettinaheim added area: language Changes to the Q# language and removed needs triage An initial review by a maintainer is needed labels Jul 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: language Changes to the Q# language enhancement New request or suggestion for an improvement
Projects
None yet
Development

No branches or pull requests

2 participants