Python: cudaq.set_noise keeps a dangling pointer to the NoiseModel (segfault, or silently noiseless sampling)
Maintainers usually reply within 1 day
@katepallewarprathmesh-sketch is already working on this.
Since Nov 20, 2026.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 68/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Domain
- backend, testing-qa
Research direction
Start by tracing the Python binding for cudaq.set_noise and how it stores the NoiseModel; the issue provides a minimal reproducer but names no source files or tests. Run the reproducer in both kept and temporary modes to confirm the lifetime failure. Done means the temporary model remains usable until unset_noise or the API raises a clear error, with a regression test covering the reported crash or incorrect sampling.
Written by the indexing model from the issue text.
Description
Versions
- CUDA-Q 0.16.0 (62fce8b862302158e0119c65e3ce57538f3af048), pip cuda-quantum-cu12 0.16.0.post1
- CUDA-Q 0.17.0 (1750574c92c613ff76c52fdbaa9289d864a3d640)
- Python 3.12.4, Linux x86_64
Targets: density-matrix-cpu (below) and nvidia with option fp64 on an A100 80GB. Same behaviour on both.
Summary. cudaq.set_noise(model) stores a reference to the noise model without keeping the
Python object alive. If the model goes out of scope, the next cudaq.sample reads freed memory.
In the minimal script below this is a segmentation fault inside the first sample call. In a larger
application we instead got noiseless results with no error at all, which we only caught by comparing
noisy trajectory sampling against an exact density-matrix reference. Keeping a reference to the model
avoids both.
Reproducer (repro_cpu.py, run as python -X faulthandler repro_cpu.py kept or ... temporary):
import sys, cudaq
cudaq.set_target("density-matrix-cpu")
@cudaq.kernel
def k():
q = cudaq.qubit()
x(q)
mz(q)
def install():
m = cudaq.NoiseModel()
m.add_all_qubit_channel("x", cudaq.BitFlipChannel(1.0))
cudaq.set_noise(m) # m goes out of scope here
print("cudaq", cudaq.__version__, flush=True)
if sys.argv[1] == "temporary":
install()
print("temporary model:", cudaq.sample(k, shots_count=1000), flush=True)
else:
keep = cudaq.NoiseModel()
keep.add_all_qubit_channel("x", cudaq.BitFlipChannel(1.0))
cudaq.set_noise(keep)
print("kept model:", cudaq.sample(k, shots_count=1000), flush=True)
Observed (identical on 0.16.0 and 0.17.0, warnings trimmed):
$ python -X faulthandler repro_cpu.py kept
kept model: { 0:1000 }
exit code: 0
$ python -X faulthandler repro_cpu.py temporary
DeprecationWarning: set_noise is deprecated; please use launch arguments or launch options.
Fatal Python error: Segmentation fault
exit code: 139
With bit-flip probability 1.0 on x, the correct result is all 0, as the kept model shows.
No gc.collect() is needed to trigger it.
Expected. set_noise keeps the model alive until unset_noise (or copies it), or raises an
error. set_noise is deprecated, but while it exists, the silent no-noise variant of this failure
can invalidate a noisy-simulation study without any visible error.
Workaround. Keep the model in a long-lived variable, or pass it as noise_model= to
cudaq.sample.
- 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