Skip to content

Adding reset after measure if qubit is to be reused#3450

Merged
1tnguyen merged 33 commits intoNVIDIA:mainfrom
1tnguyen:tnguyen/reset-after-measure-before-reuse
Nov 4, 2025
Merged

Adding reset after measure if qubit is to be reused#3450
1tnguyen merged 33 commits intoNVIDIA:mainfrom
1tnguyen:tnguyen/reset-after-measure-before-reuse

Conversation

@1tnguyen
Copy link
Collaborator

@1tnguyen 1tnguyen commented Sep 19, 2025

Description

  • A pass to detect if qubit is to be reused after measurement. If so, insert a reset and conditional x gate based on measurement result in order to bring the qubit into the |0> or |1> state consistent with the measurement.

  • Add the pass to quantinuum target pipeline config.

  • Add tests.

  • Modify the resource counting pre-process pass: move it down the JIT pipeline as the removal of gates in that pass may interfere with the program flow detection (i.e., whether a qubit is reused or not).

Signed-off-by: Thien Nguyen <thiennguyen@nvidia.com>
Signed-off-by: Thien Nguyen <thiennguyen@nvidia.com>
Signed-off-by: Thien Nguyen <thiennguyen@nvidia.com>
Signed-off-by: Thien Nguyen <thiennguyen@nvidia.com>
Signed-off-by: Thien Nguyen <thiennguyen@nvidia.com>
@1tnguyen 1tnguyen changed the title [WIP [WIP] Adding reset after measure if qubit is to be reused Sep 19, 2025
github-actions bot pushed a commit that referenced this pull request Sep 19, 2025
@github-actions
Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

Copy link
Collaborator

@schweitzpgi schweitzpgi left a comment

Choose a reason for hiding this comment

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

Will look at this more...

1tnguyen and others added 5 commits September 22, 2025 14:19
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Signed-off-by: Thien Nguyen <58006629+1tnguyen@users.noreply.github.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Signed-off-by: Thien Nguyen <58006629+1tnguyen@users.noreply.github.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Signed-off-by: Thien Nguyen <58006629+1tnguyen@users.noreply.github.com>
Signed-off-by: Thien Nguyen <thiennguyen@nvidia.com>
Signed-off-by: Thien Nguyen <thiennguyen@nvidia.com>
github-actions bot pushed a commit that referenced this pull request Sep 22, 2025
@github-actions
Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

github-actions bot pushed a commit that referenced this pull request Sep 22, 2025
@github-actions
Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

github-actions bot pushed a commit that referenced this pull request Sep 24, 2025
@github-actions
Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

github-actions bot pushed a commit that referenced this pull request Sep 29, 2025
@github-actions
Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

Signed-off-by: Thien Nguyen <thiennguyen@nvidia.com>
github-actions bot pushed a commit that referenced this pull request Sep 29, 2025
github-actions bot pushed a commit that referenced this pull request Oct 14, 2025
@github-actions
Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

github-actions bot pushed a commit that referenced this pull request Oct 23, 2025
@github-actions
Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

github-actions bot pushed a commit that referenced this pull request Oct 28, 2025
@github-actions
Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

github-actions bot pushed a commit that referenced this pull request Oct 29, 2025
@github-actions
Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

github-actions bot pushed a commit that referenced this pull request Oct 31, 2025
@github-actions
Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

@1tnguyen
Copy link
Collaborator Author

This pass should be written when the IR is in explicit linear use form (aka, value semantics), as it will be much simpler to understand, write, etc.

It actually becomes trivial. A measurement op must produce 1 or more wires. If those wires are used by anything that is not a sink operation, they are reused. In those case, if the reuse is not a reset operation, then insert a reset operation. Done.

I posted #3565 to implement this pass in the linear SSA form.
In the linear form, we would also need to find a good solution for potential qubit wire aliasing, e.g., from qubit vector slicing.

Hence, it might be better to do it as a follow-on task.

Copy link
Collaborator

@schweitzpgi schweitzpgi left a comment

Choose a reason for hiding this comment

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

Giving temporary approval. This ought to be re-done using the wire types.

@github-actions
Copy link

github-actions bot commented Nov 3, 2025

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

github-actions bot pushed a commit that referenced this pull request Nov 3, 2025
github-actions bot pushed a commit that referenced this pull request Nov 4, 2025
@github-actions
Copy link

github-actions bot commented Nov 4, 2025

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

@1tnguyen 1tnguyen closed this Nov 4, 2025
github-actions bot pushed a commit that referenced this pull request Nov 4, 2025
khalatepradnya pushed a commit to khalatepradnya/cuda-quantum that referenced this pull request Nov 17, 2025
* Add reset after measurement

Signed-off-by: Thien Nguyen <thiennguyen@nvidia.com>

* Add test

Signed-off-by: Thien Nguyen <thiennguyen@nvidia.com>

* Handle reg

Signed-off-by: Thien Nguyen <thiennguyen@nvidia.com>

* Add test for register

Signed-off-by: Thien Nguyen <thiennguyen@nvidia.com>

* Add test

Signed-off-by: Thien Nguyen <thiennguyen@nvidia.com>

* Update lib/Optimizer/Transforms/ResetBeforeReuse.cpp

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Signed-off-by: Thien Nguyen <58006629+1tnguyen@users.noreply.github.com>

* Update include/cudaq/Optimizer/Transforms/Passes.td

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Signed-off-by: Thien Nguyen <58006629+1tnguyen@users.noreply.github.com>

* Update include/cudaq/Optimizer/Transforms/Passes.h

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Signed-off-by: Thien Nguyen <58006629+1tnguyen@users.noreply.github.com>

* Use new MLIR pass util

Signed-off-by: Thien Nguyen <thiennguyen@nvidia.com>

* Tidy up the code

Signed-off-by: Thien Nguyen <thiennguyen@nvidia.com>

* Add execution test

Signed-off-by: Thien Nguyen <thiennguyen@nvidia.com>

* Fix CI tests

Signed-off-by: Thien Nguyen <thiennguyen@nvidia.com>

* Fix a test

Signed-off-by: Thien Nguyen <thiennguyen@nvidia.com>

* Some tidy up

Signed-off-by: Thien Nguyen <thiennguyen@nvidia.com>

* Code review: tidy up the code

Signed-off-by: Thien Nguyen <thiennguyen@nvidia.com>

* Code review: Rename test files following convention

Signed-off-by: Thien Nguyen <thiennguyen@nvidia.com>

* Code review: order filename

Signed-off-by: Thien Nguyen <thiennguyen@nvidia.com>

* Code review: refactor test files

Signed-off-by: Thien Nguyen <thiennguyen@nvidia.com>

* Add more tests, especially targeting aliasing

Signed-off-by: Thien Nguyen <thiennguyen@nvidia.com>

* Code review: more comprehensive checks

Signed-off-by: Thien Nguyen <thiennguyen@nvidia.com>

---------

Signed-off-by: Thien Nguyen <thiennguyen@nvidia.com>
Signed-off-by: Thien Nguyen <58006629+1tnguyen@users.noreply.github.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
@bettinaheim bettinaheim added the release notes Changes need to be captured in the release notes label Nov 25, 2025
@bettinaheim bettinaheim added this to the release 0.13.0 milestone Nov 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release notes Changes need to be captured in the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants