anras5 / hasse-diagram

Plot Finite Partially Ordered Sets in Python
https://pypi.org/project/hasse-diagram/
1 stars 0 forks source link

Code hangs: Memory leak #5

Open LordRatte opened 3 hours ago

LordRatte commented 3 hours ago

This code hangs. Could there be an infinite loop somewhere? (Edit: eventually the memory usage grows until the OS kills the process)

from hassediagram import plot_hasse
import numpy as np
matrix = np.array([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                    1, 1, 1],
                   [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                    1, 1, 1],
                   [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                    1, 1, 1],
                   [0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1,
                    1, 1, 1],
                   [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0],
                   [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                    1, 1, 1],
                   [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                    1, 1, 1],
                   [0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1,
                    1, 1, 1],
                   [0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1,
                    1, 1, 1],
                   [0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1,
                    1, 1, 1],
                   [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                    1, 1, 1],
                   [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                    1, 1, 1],
                   [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                    1, 1, 1],
                   [0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1,
                    1, 1, 1],
                   [0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1,
                    1, 1, 1],
                   [0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1,
                    1, 1, 1],
                   [0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1,
                    1, 1, 1],
                   [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                    1, 1, 1],
                   [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                    1, 1, 1],
                   [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                    1, 1, 1],
                   [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                    1, 1, 1],
                   [0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1,
                    1, 1, 1],
                   [0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1,
                    1, 1, 1],
                   [0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1,
                    1, 1, 1],
                   [0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1,
                    1, 1, 1]])

keys = list(map(str, range(25)))

plot_hasse(matrix, keys)

When I send an interrupt, this is what I get. Perhaps it will help:

Traceback (most recent call last):
  File "/Users/user/sources/project_____________/hasse.py", line 68, in <module>
    plot_hasse(matrix, keys)
  File "/Users/user/sources/project_____________/venv/lib/python3.12/site-packages/hassediagram/hasse_diagram.py", line 67, in plot_hasse
    data, labels_dict, ranks = _hasse_matrix(data, labels, transitive_reduction)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/sources/project_____________/venv/lib/python3.12/site-packages/hassediagram/hasse_diagram.py", line 39, in _hasse_matrix
    data, labels_dict = _find_and_merge_cycles(data, labels_dict)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/sources/project_____________/venv/lib/python3.12/site-packages/hassediagram/cycles.py", line 25, in _find_and_merge_cycles
    all_cycles = list(nx.simple_cycles(G))
                 ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/sources/project_____________/venv/lib/python3.12/site-packages/networkx/algorithms/cycles.py", line 235, in simple_cycles
    yield from _directed_cycle_search(G, length_bound)
  File "/Users/user/sources/project_____________/venv/lib/python3.12/site-packages/networkx/algorithms/cycles.py", line 282, in _directed_cycle_search
    yield from _johnson_cycle_search(Gc, [v])
  File "/Users/user/sources/project_____________/venv/lib/python3.12/site-packages/networkx/algorithms/cycles.py", line 406, in _johnson_cycle_search
    u = unblock_stack.pop()
        ^^^^^^^^^^^^^^^^^^^
KeyboardInterrupt
LordRatte commented 3 hours ago

I can verify that it works with a smaller example.