TacticalMetaphysics / LiSE

Rules-based engine for life sims, with time travel
GNU Affero General Public License v3.0
116 stars 9 forks source link

with Engine(clear=True) as eng: not clearing all data #88

Closed lathomas64 closed 2 years ago

lathomas64 commented 2 years ago

OS: Windows the second time i run a file with the line phys = eng.new_character('physical', nx.grid_2d_graph(20, 20)) inside of it I get errors despite clear=True being set on Engine creation:

F:\Ursina\lise_test>python3 sim.py
<class 'LiSE.engine.Engine'>
Traceback (most recent call last):
  File "F:\Ursina\lise_test\sim.py", line 6, in <module>
    phys = eng.new_character('physical', nx.grid_2d_graph(20, 20))
  File "C:\Users\redacted\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\LiSE\engine.py", line 1557, in new_character
    self.add_character(name, data, **kwargs)
  File "C:\Users\redacted\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\LiSE\engine.py", line 1572, in add_character
    self._init_graph(name, 'DiGraph', data)
  File "C:\Users\redacted\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\LiSE\allegedb\__init__.py", line 1624, in _init_graph
    raise GraphNameError("Already have a graph by that name")
LiSE.allegedb.GraphNameError: 'Already have a graph by that name'

sample code producing the issue:

from LiSE import Engine
import networkx as nx

with Engine(clear=True) as eng:
    print(type(eng))
    phys = eng.new_character('physical', nx.grid_2d_graph(20, 20))
    tri = eng.new_character('triangle')
    sq = eng.new_character('square')

    empty = list(phys.place.values())
    eng.shuffle(empty)
    # distribute 30 of each shape randomly among the empty places
    for i in range(1, 31):
        place = empty.pop()
        square = place.new_thing('square%i' % i, _image_paths=['atlas://polygons/meh_square'])
        sq.add_unit(square)
    for i in range(1, 31):
        place = empty.pop()
        triangle = place.new_thing('triangle%i' % i, _image_paths=['atlas://polygons/meh_triangle'])
        tri.add_unit(triangle)

python version: Python 3.9.10

installed modules:

Package            Version
------------------ ---------
activitypub        0.0.3
astunparse         1.6.3
blinker            1.4
cachetools         5.0.0
certifi            2021.10.8
charset-normalizer 2.0.12
click              8.0.1
colorama           0.4.4
decorator          4.4.2
dnspython          2.0.0
docutils           0.18.1
ELiDE              0.12.1
Flask              2.0.1
Flask-Cors         3.0.10
future             0.18.2
idna               3.3
itsdangerous       2.0.1
Jinja2             3.0.1
Kivy               2.0.0
kivy-deps.angle    0.3.1
kivy-deps.glew     0.3.0
kivy-deps.sdl2     0.3.1
Kivy-Garden        0.1.4
LiSE               0.12.1
lz4                4.0.0
MarkupSafe         2.0.1
msgpack            1.0.3
networkx           2.5.1
numpy              1.22.2
Panda3D            1.10.10
panda3d-gltf       0.13
panda3d-simplepbr  0.9
pefile             2021.9.3
Pillow             8.4.0
pip                22.0.3
py2exe             0.11.0.1
pygame             2.0.1
Pygments           2.11.2
pymongo            3.11.2
pyperclip          1.8.2
pypiwin32          223
python2            1.2
pywin32            303
requests           2.27.1
screeninfo         0.8
selenium           3.141.0
setuptools         60.9.0
six                1.16.0
urllib3            1.26.2
ursina             4.1.1
Werkzeug           2.0.1
wheel              0.37.1
clayote commented 2 years ago

Fixed in 2b1001b2a5e871c7ba2afad89125c08b5a64f7de