Fix sample_async noise model lifetime and isolation#3857
Fix sample_async noise model lifetime and isolation#38571tnguyen merged 10 commits intoNVIDIA:mainfrom
sample_async noise model lifetime and isolation#3857Conversation
4d27d4d to
3bad7eb
Compare
Capture the noise model by value in async sampling tasks and set/reset it within that task to avoid dangling pointers and state pollution. Also ensure noise is applied/reset per-qpu and add Python regression tests covering async noise and isolation. Signed-off-by: huaweil <huaweil@nvidia.com>
3bad7eb to
dc99583
Compare
sacpis
left a comment
There was a problem hiding this comment.
Overall LGTM. Thanks @huaweil-nv. Let's wait for Thien's review especially for the remote platform part.
Command Bot: Processing... |
|
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
|
Does this address #843? |
Relax the DepolarizationChannel(p=1.0) expectation to match the theoretical P(|0>) = 2/3 after an X gate and avoid finite-shot sampling flakiness. Signed-off-by: huaweil <huaweil@nvidia.com>
in Python, cudaq.sample_async(..., noise_model=...) already accepts noise_model, but prior to this change it was not reliable (noise could be ignored and there was a lifetime/UB risk due to a dangling pointer). This PR makes async noise application correct and isolated by capturing the noise model in the async task and setting/resetting it within the task. |
…e-model Signed-off-by: huaweil <huaweil@nvidia.com> # Conflicts: # python/tests/builder/test_NoiseModel.py
…weil-nv/cuda-quantum into fix/sample-async-noise-model
Command Bot: Processing... |
|
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
Command Bot: Processing... |
Command Bot: Processing... |
Keep our fix: noise model is passed to runSamplingAsync and set/reset within the async task, rather than setting it on the main thread which would cause race conditions and state pollution.
Command Bot: Processing... |
|
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
sample_async noise model lifetime and isolation
Description
Summary
This PR fixes
cudaq.sample_async(..., noise_model=...)for local simulators by ensuring the noise model is applied correctly during asynchronous execution and does not leak into subsequent calls.Root cause
qpu_id).Fix
details::runSamplingAsyncto accept an optional noise model and capture it by value inside the async task.qpu_id.qpu_id.Tests
Added regression tests in
python/tests/builder/test_NoiseModel.py:test_sample_async_with_noisetest_sample_async_noise_isolationHow to repro
does not always occur