[Python] [builder] Superfluous warning on code exection
When running a program in builder, mode, such as -
import cudaq
kernel = cudaq.make_kernel()
qubits = kernel.qalloc(2)
kernel.h(qubits[0])
kernel.cx(qubits[0], qubits[1])
counts = cudaq.sample(kernel)
counts.dump()
the program runs successfully, but warnings are displayed -
root@8559b45d42e6:/workspaces/cuda-quantum/build# python3 temp.py
{ 11:500 00:500 }
Exception ignored in: <function PyKernel.__del__ at 0x7f7b400520e0>
TypeError: 'NoneType' object is not callable
Exception ignored in: <function CapturedDataStorage.__del__ at 0x7f7b400555a0>
TypeError: 'NoneType' object is not callable
This was observed in dev image on main with commit id f8ee29139e3b7ffdae44307b1a21cc5f690684b3. However not reproducible on all development environments. (May occur when memory is constrained).
Once occurred in CI - https://github.com/NVIDIA/cuda-quantum/actions/runs/10155426211/job/28082475085#step:4:1799
@khalatepradnya I don't see any warnings locally after running the code above with the latest main.
root@e75e215879c9:/workspaces/cuda-quantum# python3 examples/python/test.py
{ 11:520 00:480 }
@khalatepradnya I don't see any warnings locally after running the code above with the latest main.
Yes, it may not be easily reproducible. I noted in the description that it may likely occur when memory is constrained, not sure though. Since it showed up in CI as well, we want to track it.
I encountered the same error when I use mgpu with multi nodes.
import cudaq
kernel = cudaq.make_kernel()
kernel.qalloc(35)
cudaq.sample(kernel)
I've observed this as well. Those warnings are from these lines: https://github.com/NVIDIA/cuda-quantum/blob/18c305b27196b68ec7b4a17920c06760385d5750/python/cudaq/kernel/captured_data.py#L45-L50
Specifically, cudaq_runtime.deletePointersToCudaqState became None. Perhaps the cudaq_runtime module is already gone at this point during the shutdown.
On my local build, explicitly import those 2 functions in captured_data.py seems to be enough to fix this shutdown order issue. Since this is a sporadic error, I'm not 100% sure if this is the fix.
I can confirm that when I got into a situation where I could reliably reproduce this, this change works for me, too.