Repository navigation
Dynamics operator batching - #3129
Merged
Merged
Conversation
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>
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
marked this pull request as draft
June 30, 2025 08:05
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>
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>
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>
Signed-off-by: Thien Nguyen <thiennguyen@nvidia.com>
Signed-off-by: Thien Nguyen <thiennguyen@nvidia.com>
- Refactor the batch size check for Python and C++. - Audit the C++ API: missing the vector-type observable list. Add unit tests to properly cover this case. - Add tests for large batch size value. We now handle it internally. Signed-off-by: Thien Nguyen <thiennguyen@nvidia.com>
Signed-off-by: Thien Nguyen <thiennguyen@nvidia.com>
|
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
1 similar comment
|
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
|
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
bettinaheim
approved these changes
Jul 9, 2025
|
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
…ion and add more tests Signed-off-by: Thien Nguyen <thiennguyen@nvidia.com>
|
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
|
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
atgeller
pushed a commit
to atgeller/cuda-quantum
that referenced
this pull request
Jul 31, 2025
Support batching multiple dynamics simulations (different system dynamics, i.e., Hamiltonian), provided that they are compatible (similar structures). If batching is not possible, run them sequentially. Specifically, - Major refactor of the operator converter (from CUDA-Q to cudensitymat) infrastructure, treating batched (vector) data as a first-class citizen: single op is simply a vector of size 1. - Split the op converter implementation into multiple source files for readability (it's getting big). - Implementation for both C++ and Python. - Unit tests and some examples. Notes: documentation is not included in this PR and will be added later. --------- Signed-off-by: Thien Nguyen <thiennguyen@nvidia.com> Co-authored-by: Sachin Pisal <spisal@nvidia.com> Co-authored-by: Bettina Heim <heimb@outlook.com>
This was referenced Sep 1, 2026
Closed
1tnguyen
added a commit
to 1tnguyen/cuda-quantum
that referenced
this pull request
Sep 29, 2026
…orce a mixed state (NVIDIA#5357) Fixes NVIDIA#5356 ### Bug `should_use_mixed_state` (`python/cudaq/dynamics/cudm_solver.py:23-61`) decides whether `cudaq.evolve()` on the `dynamics` target must promote the state to a density matrix. For a single super-operator it correctly checks for a right-apply (dissipator) term via `has_right_apply`, but for a *sequence* of super-operators an earlier, more permissive check returns `True` as soon as any element is merely a `SuperOperator`, regardless of whether it has a dissipator - making the correct, more specific `elif` branch a few lines below unreachable for every sequence input. A batch of pure left-multiply super-operators (ordinary Hamiltonian-only evolution, no dissipator) is therefore needlessly forced into a density-matrix representation, squaring the memory/compute cost of the simulation. The C++ side of the same feature (`CuDensityMatEvolution.cpp:794-795`) already gets this right by checking the dissipator condition on every batch element. ### Fix Remove the premature early return so the already-written, correct per-element check runs for sequence inputs too. ### Verification Not a regression from a deliberate choice: `should_use_mixed_state` was introduced whole-cloth in `995dac165` (NVIDIA#3129); the correct `elif` branch was written in the same commit, immediately below the unreachable `return` - an authoring oversight, not a decision. Confirmed via `git log -S` that only that one commit and two unrelated distributed-batching commits have ever touched this file. No existing test exercises a batched super-operator sequence with zero dissipators. This box has no GPU/local LLVM-MLIR build (see repo docs), so the negative control was run against the CUDA-Q 0.15.1 wheel (unchanged from `main` for this file) with the unrelated compiled `nvqir_dynamics_bindings` extension stubbed out in `sys.modules` before import - `should_use_mixed_state` never references that extension at all (only `isinstance`/iteration over `Operator`/`SuperOperator`/`Sequence`), so this is a benign substitution for an import-time dependency the code under test never touches, not a change to it: ``` without the fix: FAIL: test_should_use_mixed_state_batch_no_right_apply 0 passed, 1 failed with the fix: PASS: test_should_use_mixed_state_batch_no_right_apply 1 passed, 0 failed ``` Added `test_should_use_mixed_state_batch_no_right_apply` to `python/tests/dynamics/test_evolve_dynamics.py`, next to the existing `test_batching_bugs` batched-super-operator coverage. It needs no GPU/dynamics target itself (pure classification logic) but lives in this GPU-gated file since it exercises `cudaq.dynamics.cudm_solver`, matching the file's existing convention; it will run for real against the compiled extension in CI, where the stub above is unnecessary. Small diff (`-3/+22`, mostly the new test); touches only the batched-super-operator classification helper. Signed-off-by: Udaya Tejas <udayatejas2004@gmail.com> --------- Signed-off-by: Udaya Tejas <udayatejas2004@gmail.com> Co-authored-by: Thien Nguyen <58006629+1tnguyen@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Support batching multiple dynamics simulations (different system dynamics, i.e., Hamiltonian), provided that they are compatible (similar structures). If batching is not possible, run them sequentially.
Specifically,
Major refactor of the operator converter (from CUDA-Q to cudensitymat) infrastructure, treating batched (vector) data as a first-class citizen: single op is simply a vector of size 1.
Split the op converter implementation into multiple source files for readability (it's getting big).
Implementation for both C++ and Python.
Unit tests and some examples.
Notes: documentation is not included in this PR and will be added later.