Skip to content

Dynamics operator batching - #3129

Merged
bettinaheim merged 47 commits into
NVIDIA:mainfrom
1tnguyen:tnguyen/operator-batching
Jul 10, 2025
Merged

bettinaheim merged 47 commits into
NVIDIA:mainfrom
1tnguyen:tnguyen/operator-batching

Conversation

@1tnguyen

@1tnguyen 1tnguyen commented Jun 30, 2025 •

Copy link
Copy Markdown
Collaborator

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.

1tnguyen added 9 commits June 26, 2025 01:33
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 1tnguyen changed the title [WIP [WIP] Dynamics operator batching Jun 30, 2025
@1tnguyen
1tnguyen marked this pull request as draft June 30, 2025 08:05
1tnguyen and others added 19 commits June 30, 2025 18: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>
1tnguyen added 3 commits July 9, 2025 00:10
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>
github-actions Bot pushed a commit that referenced this pull request Jul 9, 2025
@github-actions

github-actions Bot commented Jul 9, 2025

Copy link
Copy Markdown

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

1 similar comment
@github-actions

github-actions Bot commented Jul 9, 2025

Copy link
Copy Markdown

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

github-actions Bot pushed a commit that referenced this pull request Jul 9, 2025
github-actions Bot pushed a commit that referenced this pull request Jul 9, 2025
@github-actions

github-actions Bot commented Jul 9, 2025

Copy link
Copy Markdown

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

Comment thread python/cudaq/dynamics/cudm_solver.py Resolved
github-actions Bot pushed a commit that referenced this pull request Jul 10, 2025
@github-actions

Copy link
Copy Markdown

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

1tnguyen and others added 2 commits July 10, 2025 07:36
@github-actions

Copy link
Copy Markdown

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

github-actions Bot pushed a commit that referenced this pull request Jul 10, 2025
@bettinaheim
bettinaheim merged commit 995dac1 into NVIDIA:main Jul 10, 2025
github-actions Bot pushed a commit that referenced this pull request Jul 10, 2025
github-actions Bot pushed a commit that referenced this pull request Jul 10, 2025
@github-actions

Copy link
Copy Markdown

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

@bettinaheim bettinaheim added the enhancement New feature or request label Jul 22, 2025
@bettinaheim bettinaheim added this to the release 0.12.0 milestone Jul 22, 2025
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>
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants