microsoft / microsoft/qdk

In Jupyter notebook, if simulation ended with runtime exception, allocated qubits are not cleared up

Open
#1,265 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

design needed enhancement
Dominant language
Rust
Stars
1k
Forks
212
Avg merge
3d 8h
Merged PRs (30d)
65

Description

**Describe the bug**

In Jupyter notebook, if simulation ended with runtime exception, allocated qubits stay around. They show up in the next `DumpMachine` outputs, even though there's no way to access them or clear them up.

**To Reproduce**

```qsharp
open Microsoft.Quantum.Diagnostics;

operation Demo() : Unit {
use q = Qubit();
X(q);
DumpMachine();
}

Demo()
```

As you re-run this code, it throws an exception each time, and the number of allocated qubits grows by 1 each time, all of them in |1> state.

**Expected behavior**

I expect the allocated qubits to not show up in consecutive runs.

**System information**

- qsharp 1.2.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the supplied Demo operation repeatedly in the Jupyter notebook with qsharp 1.2.0 and compare consecutive DumpMachine outputs. Trace what happens to simulator state after the runtime exception; done when qubits from a failed run no longer appear in later outputs or remain inaccessible.

Written by the indexing model from the issue text.

Assessment

Tech stack
jupyter-notebook
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.