pdobsan / pynauty

Isomorphism testing and automorphisms of graphs
Other
56 stars 9 forks source link

autgrp leaks memory #32

Closed Viech closed 5 months ago

Viech commented 1 year ago

The following eats my RAM really fast (my laptop freezes within two minutes):

#!/usr/bin/env python3

import numpy as np
from pynauty import Graph, autgrp

def leak_memory(n=6):
    A = np.random.randint(0, 2, (n, n))
    adjacency = {i: list(np.nonzero(j)[0]) for i, j in enumerate(A)}
    G = Graph(n, True, adjacency)
    _ = autgrp(G)  # leaking here

if __name__ == "__main__":
    while True:
        leak_memory()

With the autgrp line commented, memory use is constant.

This is on Arch Linux Kernel 6.4.8, Python 3.11.3, nauty 2.8.6, and pynauty 2.8.6.

pdobsan commented 1 year ago

On Wed, Aug 09, 2023 at 12:28:17PM -0700, Maximilian Stahlberg wrote:

The following eats my RAM really fast (my laptop freezes within two minutes):


With the `autgrp` line commented, memory use is constant.

Yes it leaks memory, I look into it when got some time. Although computing millions of autgrp-s in one session does not seem to be a typical use.

Viech commented 1 year ago

Yes it leaks memory, I look into it when got some time.

Thanks!

Although computing millions of autgrp-s in one session does not seem to be a typical use.

My use case is reinforcement learning where the autgrp call on small digraphs is part of the scoring function. Here the memory leak is pretty noticeable as I score in parallel using multiple processes that all grow (my workaround is to respawn them at a performance cost). It's a few thousand calls per second over all processes.

MHRosenberg commented 1 year ago

I am currently unable to run the example usage code in either my local ubuntu 22.04 machine or in google colab. On colab it just tells me that the kernel crashed. On my local machine, it says "Illegal instruction (core dumped)." Do you think the memory leak could cause this behavior as well or should this be a separate github issue?

@Viech, have you arrived at workaround? Is there another alternative library?

pdobsan commented 1 year ago

On Thu, Sep 07, 2023 at 01:44:52PM -0700, Matthew Rosenberg wrote:

I am currently unable to run the example usage code in either my local ubuntu 22.04 machine or in google colab. On colab it just tells me that the kernel crashed. On my local machine, it says "Illegal instruction (core dumped)."

Most likely you have installed a binary wheel from pypi. Try to force a build from source, details in the Readme.

Do you think the memory leak could cause this behavior as well or should

No, I don't think so. It works but in certain cases leaks memory.

MHRosenberg commented 1 year ago

UPDATE:

My code now runs. In my case, I needed to install pynauty via the command below instead of the pip install method in the docs.

conda install -c conda-forge pynauty

Sounds like my input is in the wrong issue thread... Lmk if there's anything you'd like me to do to relocate it elsewhere.