Skip to content

Fix memory leak in custatevec#146

Merged
ciaranra merged 1 commit into
PECOS-packages:devfrom
dlucchetti:custatevec-fix
Jul 8, 2025
Merged

Fix memory leak in custatevec#146
ciaranra merged 1 commit into
PECOS-packages:devfrom
dlucchetti:custatevec-fix

Conversation

@dlucchetti

@dlucchetti dlucchetti commented Jul 2, 2025

Copy link
Copy Markdown
Contributor

Example stack-trace:

multiprocessing.pool.RemoteTraceback:
"""
Traceback (most recent call last):
File "/usr/lib/python3.12/multiprocessing/pool.py", line 125, in worker
result = (True, func(*args, **kwds))
^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/multiprocessing/pool.py", line 48, in mapstar
return list(map(*args))
^^^^^^^^^^^^^^^^
File "/gpu/lib/python3.12/site-packages/qemulator/job_wrappers/run_multisim.py", line 108, in multiproc_sim_wrapper
return run_sim(kwargs), run_info
^^^^^^^^^^^^^^^^^
File "/gpu/lib/python3.12/site-packages/qemulator/job_wrappers/run_sim.py", line 307, in run_sim
state = state.reset()
^^^^^^^^^^^^^
File "/gpu/lib/python3.12/site-packages/pecos/simulators/custatevec/state.py", line 103, in reset
self.cupy_vector = cp.zeros(shape=2
self.num_qubits, dtype=self.cp_type)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/gpu/lib/python3.12/site-packages/cupy/_creation/basic.py", line 250, in zeros
a = cupy.ndarray(shape, dtype, order=order)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "cupy/_core/core.pyx", line 151, in cupy._core.core.ndarray.new
File "cupy/_core/core.pyx", line 239, in cupy._core.core._ndarray_base._init
File "cupy/cuda/memory.pyx", line 738, in cupy.cuda.memory.alloc
File "cupy/cuda/memory.pyx", line 1424, in cupy.cuda.memory.MemoryPool.malloc
File "cupy/cuda/memory.pyx", line 1445, in cupy.cuda.memory.MemoryPool.malloc
File "cupy/cuda/memory.pyx", line 1116, in cupy.cuda.memory.SingleDeviceMemoryPool.malloc
File "cupy/cuda/memory.pyx", line 1137, in cupy.cuda.memory.SingleDeviceMemoryPool._malloc
File "cupy/cuda/memory.pyx", line 1382, in cupy.cuda.memory.SingleDeviceMemoryPool._try_malloc
File "cupy/cuda/memory.pyx", line 1385, in cupy.cuda.memory.SingleDeviceMemoryPool._try_malloc
cupy.cuda.memory.OutOfMemoryError: Out of memory allocating 68,719,476,736 bytes (allocated so far: 68,719,476,736 bytes).
"""

@dlucchetti
dlucchetti requested a review from ciaranra as a code owner July 2, 2025 22:01

@ciaranra ciaranra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ciaranra
ciaranra merged commit a37facd into PECOS-packages:dev Jul 8, 2025
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants