Torch integrators fail with "maximum not implemented for complex tensors" when the RHS is zero at t0
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 60/100
Research direction
Start in cuda_torchdiffeq_integrator.py, where the adaptive integrator sets up the solver and calls torchdiffeq's _select_initial_step, which fails for complex y0 when f0 is zero. Run the minimal repro from the issue and the TestBug3326 case in test_evolve_dynamics_torch_integrators.py to reproduce the "maximum not implemented for complex tensors" error. Done means the repro completes with the expected occupation and the tests in tests/dynamics/integrators pass.
Written by the indexing model from the issue text.
Description
Required prerequisites
- Consult the security policy. If reporting a security vulnerability, do not report the bug using this form. Use the process described in the policy to report the issue.
- Make sure you've read the documentation. Your issue may be addressed there.
- Search the issue tracker to verify that this hasn't already been reported. +1 or comment there if it has.
- If possible, make a PR with a failing test to give us a starting point to work on!
Describe the bug
Summary
CUDATorchDiffEqIntegrator with an adaptive solver (e.g. dopri5) raises RuntimeError: maximum not implemented for complex tensors when the RHS is exactly zero at the initial time. This fails test_evolve_dynamics_torch_integrators.py::test_all_models_default_solver[TestBug3326] in the Python metapackage validation, conda environment jobs (CUDA 12.6 and 13.0.2) on every Validation run since #5562 landed.
- Failing run: https://github.com/NVIDIA/cuda-quantum/actions/runs/37833749927
- Last green Validation run: 37580302912 (same torch 2.14.1 and torchdiffeq 0.2.5, so this is not a dependency drift)
Cause
If the initial state commutes with the Hamiltonian, f0 = 0 exactly. torchdiffeq's _select_initial_step then takes the d1 <= 1e-15 and d2 <= 1e-15 branch and calls torch.max(torch.tensor(1e-6, dtype=y0.dtype), ...). With a complex y0 that dtype is complex, and torch.max does not support it. This is a latent torchdiffeq bug (unchanged upstream in 0.2.5).
TestBug3326.case2 uses a diagonal Hamiltonian and a Fock-state density matrix, so it hits this branch. It likely started failing after the operator fusion change (#5562), which probably makes the RHS exactly zero instead of ~1e-16 roundoff. I did not confirm that link.
Minimal repro (no fusion needed)
import cupy as cp, numpy as np, cudaq
from cudaq import Schedule, boson
from cudaq.dynamics.integrators import CUDATorchDiffEqDopri5Integrator
cudaq.set_target("dynamics")
d = 3
rho0 = cudaq.State.from_data(cp.eye(d, dtype=cp.complex128) / d) # commutes with H
cudaq.evolve(5 * boson.number(0), {0: d}, Schedule(np.linspace(0, 1, 11), ["t"]), rho0,
observables=[boson.number(0)], collapse_operators=[],
integrator=CUDATorchDiffEqDopri5Integrator())
Fails on the released cuda-quantum-cu13 0.16 wheel with the same traceback as CI.
Proposed fix
In cuda_torchdiffeq_integrator.py, add a copy of _select_initial_step that uses the real time dtype for step sizes, and set solver.first_step from it on the first integrate call. _before_integrate skips the broken selection when first_step is set. In the non-degenerate case the result is identical to upstream. With the patch the repro completes (mean occupation 1.0) and all 29 tests in tests/dynamics/integrators pass.
- Dominant language
- C++
- Stars
- 1.2k
- Forks
- 508
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 100
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from NVIDIA/cuda-quantum
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
NVIDIA/cuda-quantum#6035 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 1-3 hours Newbie friendliness 77/100
NVIDIA/cuda-quantum#6034 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
NVIDIA/cuda-quantum#6033 ·
Maintainers usually reply within 1 day
-
Point the CUDA-Q Pulse research preview docs to the released cudaq-pulse packagePossibly taken @fedonman claimed this 2 days ago. Open
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
NVIDIA/cuda-quantum#6031 ·
Maintainers usually reply within 1 day
-
Realtime fnv1a_hash sign-extends char, so a non-ASCII handler name gets a platform-dependent function idPossibly taken @fedonman claimed this 2 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
NVIDIA/cuda-quantum#6029 ·
Maintainers usually reply within 1 day
All issues in NVIDIA/cuda-quantum
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
Maintainers usually reply within 2 days
-
bug data-types
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
ClickHouse/clickhouse-cpp#645 ·
Maintainers usually reply within 1 day
-
bug compatibility difficulty:easy prio:normal
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
NatronGitHub/openfx-misc#524 ·
Maintainers usually reply within 1 day
-
documentation enhancement help wanted P0
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Awesome-Embedded-Learning-Studio/Tutorial_AwesomeModernCPP#359 ·
Maintainers usually reply within 1 day
-
Type: Bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
openscad/openscad#7360 · 2 comments ·
Maintainers usually reply within 1 day