question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Memory use is increasing as the times of call in function scipy.stats._sobol._categorize

See original GitHub issue

My issue is about memory leak in function scipy.stats._sobol._categorize. As the below code shows, if I input illegal input to the function, the memory use is increasing as the number of calls.

Reproducing code example:

import sys
import tracemalloc
import numpy
import scipy.stats._sobol

arg_list = []
arg_list.append(-87.11965751389266)
arg_list.append(17.04812581438513)
arg_list.append(-3)
arg_list.append(-87)
arg_list.append(-14)
arg_list.append(37)
arg_list.append(-63)
arg_list.append(-73)
arg_list.append(-83)
arg_list.append(-14)
arg_list.append(96)
arg_list.append(70)

memory_recorder = []
tracemalloc.start()
start_snapshot = tracemalloc.take_snapshot()
for i in range(0, 100):
  try:
    scipy.stats._sobol._categorize(numpy.array([arg_list[0], arg_list[1]]),
                                   numpy.array([arg_list[2], arg_list[3], arg_list[4], arg_list[5], arg_list[6]]),
                                   numpy.array([arg_list[7], arg_list[8], arg_list[9], arg_list[10], arg_list[11]]))
  except:
    pass
  if i % 10 == 0:
    one_snapshot = tracemalloc.take_snapshot()
    memory_recorder.append(one_snapshot.compare_to(start_snapshot, 'lineno')[0])

for i in range(2, len(memory_recorder)):
  if str(memory_recorder[i].traceback) == str(memory_recorder[1].traceback):
    print(memory_recorder[i].traceback)
    print(memory_recorder[i].size)

tracemalloc.stop()

Error message:

test.py:32
9594
test.py:32
13690
test.py:32
17482
test.py:32
21482
test.py:32
25274
test.py:32
29322
test.py:32
33114
test.py:32
37210

Scipy/Numpy/Python version information:

scipy 1.7.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
peterbell10commented, Jul 19, 2021

I’ve reported the leak to cython (cython/cython#4296) but agree this particular function shouldn’t cause any issues. The issue @tupui points out with base_draws doesn’t matter because it’s the first argument so no other memory views will have been constructed yet.

0reactions
tupuicommented, Jul 19, 2021

Thanks for having a deeper look @peterbell10

Read more comments on GitHub >

github_iconTop Results From Across the Web

Clinging to memory: how Python function calls can increase ...
Solution #1: No local variable at all ... If there's no extra reference, the original array can be removed from memory as soon...
Read more >
scipy.stats.norm.pdf takes too much time and memory #14095
While using this, I observed that my RAM usage was increasing inexplicably. I decided to dig a little and found these two issues....
Read more >
Why does scipy.optimize.fmin_l_bfgs_b() memory usage ...
If memory is not deallocated in the minimization function, each call to the function will increase the memory allocation of your program.
Read more >
scipy.stats.qmc.Sobol — SciPy v1.9.3 Manual
Sobol ' sequences are low-discrepancy, quasi-random numbers. ... If seed is an int, a new Generator instance is used, seeded with seed.
Read more >
scikit-optimize Documentation
scikit-optimize Documentation, Release 0.8.1. Total running time of the script: ( 0 minutes 2.610 seconds). Estimated memory usage: 14 MB.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found