mettagrid 0.0.1__py3-none-any.whl → 0.0.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. README.md +75 -0
  2. build/lib.macosx-11.0-arm64-cpython-311/mettagrid/actions/actions.cpython-311-darwin.so +0 -0
  3. build/lib.macosx-11.0-arm64-cpython-311/mettagrid/actions/attack.cpython-311-darwin.so +0 -0
  4. build/lib.macosx-11.0-arm64-cpython-311/mettagrid/actions/gift.cpython-311-darwin.so +0 -0
  5. build/lib.macosx-11.0-arm64-cpython-311/mettagrid/actions/move.cpython-311-darwin.so +0 -0
  6. build/lib.macosx-11.0-arm64-cpython-311/mettagrid/actions/noop.cpython-311-darwin.so +0 -0
  7. build/lib.macosx-11.0-arm64-cpython-311/mettagrid/actions/rotate.cpython-311-darwin.so +0 -0
  8. build/lib.macosx-11.0-arm64-cpython-311/mettagrid/actions/shield.cpython-311-darwin.so +0 -0
  9. build/lib.macosx-11.0-arm64-cpython-311/mettagrid/actions/use.cpython-311-darwin.so +0 -0
  10. build/lib.macosx-11.0-arm64-cpython-311/mettagrid/mettagrid_c.cpython-311-darwin.so +0 -0
  11. build/lib.macosx-11.0-arm64-cpython-311/mettagrid/objects.cpython-311-darwin.so +0 -0
  12. build/mettagrid/actions/actions.cpp +33466 -0
  13. build/mettagrid/actions/attack.cpp +33253 -0
  14. build/mettagrid/actions/gift.cpp +32378 -0
  15. build/mettagrid/actions/move.cpp +32552 -0
  16. build/mettagrid/actions/noop.cpp +32376 -0
  17. build/mettagrid/actions/rotate.cpp +32394 -0
  18. build/mettagrid/actions/shield.cpp +32437 -0
  19. build/mettagrid/actions/use.cpp +32851 -0
  20. build/mettagrid/mettagrid.cpp +37718 -0
  21. build/mettagrid/objects.cpp +36083 -0
  22. mettagrid/actions/actions.cpython-311-darwin.so +0 -0
  23. mettagrid/actions/actions.pxd +2 -2
  24. mettagrid/actions/actions.pyx +19 -5
  25. mettagrid/actions/attack.cpython-311-darwin.so +0 -0
  26. mettagrid/actions/attack.pyx +12 -3
  27. mettagrid/actions/gift.cpython-311-darwin.so +0 -0
  28. mettagrid/actions/gift.pyx +4 -1
  29. mettagrid/actions/move.cpython-311-darwin.so +0 -0
  30. mettagrid/actions/move.pyx +16 -6
  31. mettagrid/actions/noop.cpython-311-darwin.so +0 -0
  32. mettagrid/actions/noop.pxd +4 -0
  33. mettagrid/actions/noop.pyx +25 -0
  34. mettagrid/actions/rotate.cpython-311-darwin.so +0 -0
  35. mettagrid/actions/rotate.pyx +5 -3
  36. mettagrid/actions/shield.cpython-311-darwin.so +0 -0
  37. mettagrid/actions/shield.pyx +10 -3
  38. mettagrid/actions/use.cpython-311-darwin.so +0 -0
  39. mettagrid/actions/use.pyx +9 -4
  40. mettagrid/mettagrid.pyx +35 -1
  41. mettagrid/mettagrid_c.cpython-311-darwin.so +0 -0
  42. mettagrid/mettagrid_env.py +44 -72
  43. mettagrid/objects.cpython-311-darwin.so +0 -0
  44. mettagrid/objects.pxd +25 -12
  45. mettagrid/objects.pyx +19 -21
  46. mettagrid/renderer/assets/agent.png +0 -0
  47. mettagrid/renderer/assets/altar.png +0 -0
  48. mettagrid/renderer/assets/arial.ttf +0 -0
  49. mettagrid/renderer/assets/converter.png +0 -0
  50. mettagrid/renderer/assets/generator.png +0 -0
  51. mettagrid/renderer/json_renderer.py +0 -0
  52. mettagrid/renderer/raylib_renderer.py +410 -0
  53. mettagrid/renderer/render_code_example.py +56 -0
  54. mettagrid-0.0.3.dist-info/LICENSE +21 -0
  55. mettagrid-0.0.3.dist-info/METADATA +96 -0
  56. mettagrid-0.0.3.dist-info/RECORD +81 -0
  57. setup.py +91 -0
  58. test_perf.py +107 -0
  59. mettagrid/renderer/raylib_client.py +0 -180
  60. mettagrid-0.0.1.dist-info/METADATA +0 -23
  61. mettagrid-0.0.1.dist-info/RECORD +0 -38
  62. /mettagrid-0.0.1.dist-info/LICENSE → /LICENSE +0 -0
  63. /mettagrid/renderer/assets/{tiny_galaxy_items.png → items.png} +0 -0
  64. /mettagrid/renderer/assets/{tiny_galaxy_monsters.png → monsters.png} +0 -0
  65. /mettagrid/renderer/assets/{wall1-0.png → wall.png} +0 -0
  66. {mettagrid-0.0.1.dist-info → mettagrid-0.0.3.dist-info}/WHEEL +0 -0
@@ -0,0 +1,81 @@
1
+ LICENSE,sha256=_0ZygdDOImEUQjXap6LgAetwhuvlOfOqcMDmNlAdjLo,1070
2
+ README.md,sha256=464FGzZirXWaYNrQe7SlyD2gmOHmJktRnNJ9Tro2Nek,4680
3
+ build/lib.macosx-11.0-arm64-cpython-311/mettagrid/actions/actions.cpython-311-darwin.so,sha256=ZSQxWXe3SlkA_QYOeBCzvrj4IivyWvDwjYEE_Q2osAE,218336
4
+ build/lib.macosx-11.0-arm64-cpython-311/mettagrid/actions/attack.cpython-311-darwin.so,sha256=LdsKoO8hdXrmtYXrV3ax_rnVljTQg5HEUM_bvH9EHB8,217696
5
+ build/lib.macosx-11.0-arm64-cpython-311/mettagrid/actions/gift.cpython-311-darwin.so,sha256=xwvpz-lM9z6_GIxrphR2TNXNEM10Y4kxw5-ZRppfPBs,217064
6
+ build/lib.macosx-11.0-arm64-cpython-311/mettagrid/actions/move.cpython-311-darwin.so,sha256=zLNYBMHescRTGANyqueyI7FoihpFRG2sSuVwCg6OIAg,217064
7
+ build/lib.macosx-11.0-arm64-cpython-311/mettagrid/actions/noop.cpython-311-darwin.so,sha256=YRWcWJ4s_841bPxvmKhb8C_Gx7xHTWY9GK_lnHe6KPA,217064
8
+ build/lib.macosx-11.0-arm64-cpython-311/mettagrid/actions/rotate.cpython-311-darwin.so,sha256=bXV286F_B1oGEl1qBB7x-uMaciZ4en_p97Gh5cjat7Y,217152
9
+ build/lib.macosx-11.0-arm64-cpython-311/mettagrid/actions/shield.cpython-311-darwin.so,sha256=sB9KwHQANcqozw6RFhzTz1MHsrs869TVa4SL5dPtcHY,217152
10
+ build/lib.macosx-11.0-arm64-cpython-311/mettagrid/actions/use.cpython-311-darwin.so,sha256=OLTTen8vVonsh7Z55SlmNt6wGQp-h6tbOd_NdVxvz88,217224
11
+ build/lib.macosx-11.0-arm64-cpython-311/mettagrid/mettagrid_c.cpython-311-darwin.so,sha256=qKkjft1j7TYrux1XKr29j17gtdsUJavqTy4V3ZqKyuk,277600
12
+ build/lib.macosx-11.0-arm64-cpython-311/mettagrid/objects.cpython-311-darwin.so,sha256=RFWTbLIn5QNIjxCVG6Z7jBYNbsecsXEOsyuxXnHGNk4,257136
13
+ build/mettagrid/actions/actions.cpp,sha256=o1Y5QWJNQdSVbUU5JYzEIm_QrY608gyjKzE2PwYwBuw,1277005
14
+ build/mettagrid/actions/attack.cpp,sha256=6VNZJxBwxj7B2_5hhaAX3FZWMbv0Up-EhCkVgbcoFb8,1274448
15
+ build/mettagrid/actions/gift.cpp,sha256=jWvdEHgX5NVLXjtRg4t6-qJBvuloT3jzUqXVD7tisY4,1226668
16
+ build/mettagrid/actions/move.cpp,sha256=xzlDbe5TMSNULthlE4H2oQXr7uVD1-NEtrwiNimnrB8,1233507
17
+ build/mettagrid/actions/noop.cpp,sha256=WDCzGjmi7VnBFO6Z4aix6YQYBiq8eDX_BCFoqvUTNcc,1226691
18
+ build/mettagrid/actions/rotate.cpp,sha256=O6QSCSn5POQxYP-73d0f7iWj6vkeKJIK0-FbBYYtmY0,1227751
19
+ build/mettagrid/actions/shield.cpp,sha256=kT7DNr4LqUNhNC5UnNvIOYhXhmG8EW6prVMhAyNIM84,1228950
20
+ build/mettagrid/actions/use.cpp,sha256=KRV2sE00e4m-rPOgfhfe8hkZijL-WG18TiJ_o16tK8I,1247620
21
+ build/mettagrid/mettagrid.cpp,sha256=fBtYYDaJbdZp6uKO_gNWxdAIA2etMiKAIZT87cKc1Wg,1464344
22
+ build/mettagrid/objects.cpp,sha256=H0FZERGFMfDZuTbU43Y_YvcpgAqhMJRBihreXBNC0jI,1395699
23
+ mettagrid/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
24
+ mettagrid/actions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
+ mettagrid/actions/actions.cpython-311-darwin.so,sha256=ZSQxWXe3SlkA_QYOeBCzvrj4IivyWvDwjYEE_Q2osAE,218336
26
+ mettagrid/actions/actions.pxd,sha256=R7F4wL8T8EMcmsNgUvUE_YHhSCQoC2RwzDDzmT7tSXE,765
27
+ mettagrid/actions/actions.pyx,sha256=EUOWA7UZ78e0IwRyvIWVqxyVLp1C6RHAuB-w2SGgDzU,2182
28
+ mettagrid/actions/attack.cpython-311-darwin.so,sha256=LdsKoO8hdXrmtYXrV3ax_rnVljTQg5HEUM_bvH9EHB8,217696
29
+ mettagrid/actions/attack.pxd,sha256=2VQADMYLj7-EhzVoK1_4w_rJFTnj7l7-5fMHseBqGP8,135
30
+ mettagrid/actions/attack.pyx,sha256=dFbQkpyemfKAAVf7eMuMTAz9EmrJo4CTKHJU29iy8vw,3090
31
+ mettagrid/actions/gift.cpython-311-darwin.so,sha256=xwvpz-lM9z6_GIxrphR2TNXNEM10Y4kxw5-ZRppfPBs,217064
32
+ mettagrid/actions/gift.pxd,sha256=f4Y8mQtBhBlD0z_auZQrRs3StYO54TV2fUw5WSDFnG4,105
33
+ mettagrid/actions/gift.pyx,sha256=7s-nQPpuMxBvG5rrcReB9eho7_3FxebBUEhb26tXpRM,804
34
+ mettagrid/actions/move.cpython-311-darwin.so,sha256=zLNYBMHescRTGANyqueyI7FoihpFRG2sSuVwCg6OIAg,217064
35
+ mettagrid/actions/move.pxd,sha256=GN_4ieZrI6RoY92igO4PmayRIS9O-zQl1oeOfImneeE,105
36
+ mettagrid/actions/move.pyx,sha256=Ucq05-gUooU4zia6a5C_4qrlirbPQYxTAVmfkuhZbV0,1595
37
+ mettagrid/actions/noop.cpython-311-darwin.so,sha256=YRWcWJ4s_841bPxvmKhb8C_Gx7xHTWY9GK_lnHe6KPA,217064
38
+ mettagrid/actions/noop.pxd,sha256=KiEvVu-SsvTa3WZ6guNCWvFf12tJEb3GnjzmmpZJB-o,105
39
+ mettagrid/actions/noop.pyx,sha256=6uy8lsnMl7k_sNwJfA10eXcYy9BcGOBeVZ2KSLSv9z0,798
40
+ mettagrid/actions/rotate.cpython-311-darwin.so,sha256=bXV286F_B1oGEl1qBB7x-uMaciZ4en_p97Gh5cjat7Y,217152
41
+ mettagrid/actions/rotate.pxd,sha256=z2D17nFORP9lw2eZLZB96KE18sy_d914x0pe854O7MU,107
42
+ mettagrid/actions/rotate.pyx,sha256=nHwovy43-n-LTq5lTm3a2Aa7LQmo5rMHwwoSc5JeWHs,894
43
+ mettagrid/actions/shield.cpython-311-darwin.so,sha256=sB9KwHQANcqozw6RFhzTz1MHsrs869TVa4SL5dPtcHY,217152
44
+ mettagrid/actions/shield.pxd,sha256=9lf9UOWml8koteofGGTTUyLR20dhE8YTFtZZlMAI7hA,107
45
+ mettagrid/actions/shield.pyx,sha256=YX_oLCrP2rF_nQZSslNbAwq8pGLK1BPkWDmiUg6IAyU,949
46
+ mettagrid/actions/use.cpython-311-darwin.so,sha256=OLTTen8vVonsh7Z55SlmNt6wGQp-h6tbOd_NdVxvz88,217224
47
+ mettagrid/actions/use.pxd,sha256=bFx5IlWzX8mZemv1A5tAg6h97Vt6ev9SSJXewqK33CQ,104
48
+ mettagrid/actions/use.pyx,sha256=LbQKaEkNChFE9Y8KDXKfRygWGRLb49xQL4x-19TEyEw,2786
49
+ mettagrid/config/game_builder.py,sha256=f9fS38WaXepiwL9qlWqMBI4aMRjKN11P18Q6mFl2yAM,3360
50
+ mettagrid/config/sample_config.py,sha256=BbRqT5hrPY5VKGIC7bVbEjwd_G59defru573KxvCtEA,822
51
+ mettagrid/mettagrid.pyx,sha256=kobCT-gjBhRjyzy0Lq9ss7M3wCA4JdIw0TFZw2ep8jM,3971
52
+ mettagrid/mettagrid_c.cpython-311-darwin.so,sha256=qKkjft1j7TYrux1XKr29j17gtdsUJavqTy4V3ZqKyuk,277600
53
+ mettagrid/mettagrid_env.py,sha256=hJ2lRkGl2dztLAQlZqgW9xOBYLrz1_KflIvT-BZ6gn8,5192
54
+ mettagrid/objects.cpython-311-darwin.so,sha256=RFWTbLIn5QNIjxCVG6Z7jBYNbsecsXEOsyuxXnHGNk4,257136
55
+ mettagrid/objects.pxd,sha256=wt53DlwO2TqjJrdjcp9JA8b_-LZRzpU40jlSVrUDI7w,6464
56
+ mettagrid/objects.pyx,sha256=ZjaanEUZ9vfc9i5uVrRj-HqYWQkRO2o_j4LW4lZAhgg,2319
57
+ mettagrid/renderer/assets/agent.png,sha256=-Lt-cyIxZMDX_I7vG6w20MInah8CEorE5WGN0rmVP_k,427
58
+ mettagrid/renderer/assets/altar.png,sha256=Nhn_6IEmPuq9t0rDaCvyPCvpdzX3vZB-X1EoMSpvNvc,425
59
+ mettagrid/renderer/assets/arial.ttf,sha256=NcDzVZ2NtWnjbDEJW4pg1EFkPZX1kTneQOI_ragZuDM,275572
60
+ mettagrid/renderer/assets/converter.png,sha256=HT--nGPU05Wdk1JKNP1rmBYttPbOkWKOI6J-VDs3jwk,384
61
+ mettagrid/renderer/assets/generator.png,sha256=_vHlTbCy_NZYzYnkLxdRwF-zp1D2H4Md3yI8-ZX8QGA,376
62
+ mettagrid/renderer/assets/items.png,sha256=zRfEkwGZ-BnzzCqyse6wyWIGTcteVt_eJVRkTlS4XBA,24116
63
+ mettagrid/renderer/assets/monsters.png,sha256=Aw2Ktj-1BtugmjMI9Wnyb4xxAxq6rzD0mgk9IBdkCyM,32763
64
+ mettagrid/renderer/assets/ore-0.png,sha256=_vHlTbCy_NZYzYnkLxdRwF-zp1D2H4Md3yI8-ZX8QGA,376
65
+ mettagrid/renderer/assets/ore-1.png,sha256=HT--nGPU05Wdk1JKNP1rmBYttPbOkWKOI6J-VDs3jwk,384
66
+ mettagrid/renderer/assets/ore-2.png,sha256=Nhn_6IEmPuq9t0rDaCvyPCvpdzX3vZB-X1EoMSpvNvc,425
67
+ mettagrid/renderer/assets/ore-3.png,sha256=-Lt-cyIxZMDX_I7vG6w20MInah8CEorE5WGN0rmVP_k,427
68
+ mettagrid/renderer/assets/ore-4.png,sha256=vySYN37jPtFeTXXmpyJCCalkR0K2RfutIHp8CXgImjg,410
69
+ mettagrid/renderer/assets/ore-5.png,sha256=KSvduI7HnGD4ky3Cq27FwbwHe9pO4-WY1yFoh7mAzCM,410
70
+ mettagrid/renderer/assets/ore-6.png,sha256=6GWdbQJ4P5WLsTz8rWpGtXbc6P7JJ-bO7ze3qHQ4bH0,418
71
+ mettagrid/renderer/assets/puffer_chars.png,sha256=6FaTd_z6JkMldwlYAW94BajgaaGz30ScWBTmUggxu78,71193
72
+ mettagrid/renderer/assets/wall.png,sha256=MONt_xbscHfODf9T9hiy8poHX_TkMXbk_dC6T0ora7I,1155
73
+ mettagrid/renderer/json_renderer.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
74
+ mettagrid/renderer/raylib_renderer.py,sha256=MaCT7R_9IG8zPcQkWjdO0-2QFFguTwt60o6iwanx79M,14977
75
+ mettagrid/renderer/render_code_example.py,sha256=eQJyOK9j-hBiIfQnmyPRSw1n9sDZ2dIQNGzV3m_j_WY,2350
76
+ setup.py,sha256=KBVLqjWKFh_5AiG8GNbn7oXBSGA2cCXQqc_nTStNnPY,2527
77
+ test_perf.py,sha256=GiLNt7eyM3NNyXdx2DZ9CI0LrwRAS_cKU8aV3bt7yiA,3221
78
+ mettagrid-0.0.3.dist-info/LICENSE,sha256=_0ZygdDOImEUQjXap6LgAetwhuvlOfOqcMDmNlAdjLo,1070
79
+ mettagrid-0.0.3.dist-info/METADATA,sha256=8pFkU72N4n3B6qUXA-Hq4YwXrIy8OSihPOrYQvzoBoc,5437
80
+ mettagrid-0.0.3.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
81
+ mettagrid-0.0.3.dist-info/RECORD,,
setup.py ADDED
@@ -0,0 +1,91 @@
1
+ from sympy import li
2
+ from setuptools import Extension, setup, find_packages, Command
3
+ import subprocess
4
+ from Cython.Build import cythonize
5
+ import numpy
6
+ import os
7
+
8
+
9
+ def build_ext(srcs, module_name=None):
10
+ if module_name is None:
11
+ module_name = srcs[0].replace("/", ".").replace(".pyx", "").replace(".cpp", "")
12
+ return Extension(
13
+ module_name,
14
+ srcs,
15
+ # include_dirs=["third_party/puffergrid"],
16
+ define_macros=[('NPY_NO_DEPRECATED_API', 'NPY_1_7_API_VERSION')],
17
+ )
18
+
19
+ ext_modules = [
20
+ build_ext(["mettagrid/objects.pyx"]),
21
+ build_ext(["mettagrid/actions/actions.pyx"]),
22
+ build_ext(["mettagrid/actions/attack.pyx"]),
23
+ build_ext(["mettagrid/actions/gift.pyx"]),
24
+ build_ext(["mettagrid/actions/move.pyx"]),
25
+ build_ext(["mettagrid/actions/noop.pyx"]),
26
+ build_ext(["mettagrid/actions/rotate.pyx"]),
27
+ build_ext(["mettagrid/actions/shield.pyx"]),
28
+ build_ext(["mettagrid/actions/use.pyx"]),
29
+ build_ext(["mettagrid/mettagrid.pyx"], "mettagrid.mettagrid_c"),
30
+ ]
31
+
32
+ debug = os.getenv('DEBUG', '0') == '1'
33
+ annotate = os.getenv('ANNOTATE', '0') == '1'
34
+
35
+ build_dir = 'build'
36
+ if debug:
37
+ build_dir = 'build_debug'
38
+
39
+ os.makedirs(build_dir, exist_ok=True)
40
+
41
+ setup(
42
+ name='metta',
43
+ version='0.1',
44
+ packages=find_packages(),
45
+ install_requires=[
46
+ "hydra-core",
47
+ "jmespath",
48
+ "matplotlib",
49
+ # "numpy==2.0.0",
50
+ "pettingzoo",
51
+ "pufferlib",
52
+ "puffergrid",
53
+ "pynvml",
54
+ "pytest",
55
+ "PyYAML",
56
+ "raylib",
57
+ "rich",
58
+ "scipy",
59
+ "tabulate",
60
+ "tensordict",
61
+ "torchrl",
62
+ ],
63
+ entry_points={
64
+ 'console_scripts': [
65
+ # If you want to create any executable scripts in your package
66
+ # For example: 'script_name = module:function'
67
+ ]
68
+ },
69
+ include_dirs=[numpy.get_include()],
70
+ ext_modules=cythonize(
71
+ ext_modules,
72
+ build_dir='build',
73
+ compiler_directives={
74
+ "language_level": "3",
75
+ "embedsignature": debug,
76
+ "annotation_typing": debug,
77
+ "cdivision": debug,
78
+ "boundscheck": debug,
79
+ "wraparound": debug,
80
+ "initializedcheck": debug,
81
+ "nonecheck": debug,
82
+ "overflowcheck": debug,
83
+ "overflowcheck.fold": debug,
84
+ "profile": debug,
85
+ "linetrace": debug,
86
+ "c_string_encoding": "utf-8",
87
+ "c_string_type": "str",
88
+ },
89
+ annotate=debug or annotate,
90
+ ),
91
+ )
test_perf.py ADDED
@@ -0,0 +1,107 @@
1
+ import time
2
+
3
+ import hydra
4
+ import numpy as np
5
+ from tqdm import tqdm
6
+ import pandas as pd
7
+
8
+ global actions
9
+ global env
10
+
11
+ def test_performance(env, actions, duration):
12
+ tick = 0
13
+ num_actions = actions.shape[0]
14
+ start = time.time()
15
+ with tqdm(total=duration, desc="Running performance test") as pbar:
16
+ while time.time() - start < duration:
17
+ atns = actions[tick % num_actions]
18
+ obs, rewards, terminated, truncated, infos = env.step(atns)
19
+ tick += 1
20
+ if tick % 100 == 0:
21
+ pbar.update(time.time() - start - pbar.n)
22
+
23
+ print_stats(env._c_env.get_episode_stats())
24
+ print(f'SPS: {atns.shape[0] * tick / (time.time() - start):.2f}')
25
+
26
+ actions = {}
27
+ env = {}
28
+ @hydra.main(version_base=None, config_path="configs", config_name="a20_40x40")
29
+ def main(cfg):
30
+ # Run with c profile
31
+ from cProfile import run
32
+ global env
33
+
34
+ cfg.env.game.max_steps = 999999999
35
+ env = hydra.utils.instantiate(cfg.env, render_mode="human")
36
+ env.reset()
37
+ global actions
38
+ num_agents = cfg.env.game.num_agents
39
+ actions = np.random.randint(0, env.action_space.nvec, (1024, num_agents, 2), dtype=np.uint32)
40
+
41
+ env._c_env.render()
42
+ test_performance(env, actions, 5)
43
+ # env._c_env.render()
44
+ exit(0)
45
+
46
+ run("test_performance(env, actions, 10)", 'stats.profile')
47
+ import pstats
48
+ from pstats import SortKey
49
+ p = pstats.Stats('stats.profile')
50
+ p.sort_stats(SortKey.TIME).print_stats(25)
51
+ exit(0)
52
+
53
+
54
+ def print_stats(stats):
55
+ # Extract game_stats
56
+ game_stats = stats["game"]
57
+
58
+ # Extract agent_stats
59
+ agent_stats = stats["agent"]
60
+
61
+ # Calculate total, average, min, and max for each agent stat
62
+ total_agent_stats = {}
63
+ avg_agent_stats = {}
64
+ min_agent_stats = {}
65
+ max_agent_stats = {}
66
+ num_agents = len(agent_stats)
67
+
68
+ for agent_stat in agent_stats:
69
+ for key, value in agent_stat.items():
70
+ if key not in total_agent_stats:
71
+ total_agent_stats[key] = 0
72
+ min_agent_stats[key] = float('inf')
73
+ max_agent_stats[key] = float('-inf')
74
+ total_agent_stats[key] += value
75
+ if value < min_agent_stats[key]:
76
+ min_agent_stats[key] = value
77
+ if value > max_agent_stats[key]:
78
+ max_agent_stats[key] = value
79
+
80
+ for key, value in total_agent_stats.items():
81
+ avg_agent_stats[key] = value / num_agents
82
+
83
+ # Sort the keys alphabetically
84
+ sorted_keys = sorted(total_agent_stats.keys())
85
+
86
+ # Create DataFrame for game_stats
87
+ game_stats_df = pd.DataFrame(sorted(game_stats.items()), columns=["Stat", "Value"])
88
+
89
+ # Create DataFrame for agent stats
90
+ agent_stats_df = pd.DataFrame({
91
+ "Stat": sorted_keys,
92
+ "Total": [total_agent_stats[key] for key in sorted_keys],
93
+ "Average": [avg_agent_stats[key] for key in sorted_keys],
94
+ "Min": [min_agent_stats[key] for key in sorted_keys],
95
+ "Max": [max_agent_stats[key] for key in sorted_keys]
96
+ })
97
+
98
+ # Print the DataFrames
99
+ print("\nGame Stats:")
100
+ print(game_stats_df.to_string(index=False))
101
+
102
+ print("\nAgent Stats:")
103
+ print(agent_stats_df.to_string(index=False))
104
+
105
+
106
+ if __name__ == "__main__":
107
+ main()
@@ -1,180 +0,0 @@
1
- from pdb import set_trace as T
2
- import numpy as np
3
- import os
4
-
5
- import pettingzoo
6
- import gymnasium
7
-
8
- import pufferlib
9
- from pufferlib.environments.ocean import render
10
-
11
- class MettaRaylibClient:
12
- def __init__(self, width, height, tile_size=32):
13
- self.width = width
14
- self.height = height
15
- self.tile_size = tile_size
16
-
17
-
18
- sprite_sheet_path = os.path.join(
19
- *self.__module__.split('.')[:-1], './puffer_chars.png')
20
- self.asset_map = {
21
- 1: (0, 0, 128, 128),
22
- 3: (128, 0, 128, 128),
23
- 4: (256, 0, 128, 128),
24
- # 5: (384, 0, 128, 128),
25
- 5: (512, 0, 128, 128), #star
26
- }
27
-
28
- from raylib import rl, colors
29
- rl.InitWindow(width*tile_size, height*tile_size,
30
- "PufferLib Ray Grid".encode())
31
- rl.SetTargetFPS(10)
32
- self.puffer = rl.LoadTexture(sprite_sheet_path.encode())
33
- self.rl = rl
34
- self.colors = colors
35
-
36
- import pyray as ray
37
- camera = ray.Camera2D()
38
- camera.target = ray.Vector2(0.0, 0.0)
39
- camera.rotation = 0.0
40
- camera.zoom = 1.0
41
- self.camera = camera
42
-
43
- from cffi import FFI
44
- self.ffi = FFI()
45
-
46
- def _cdata_to_numpy(self):
47
- image = self.rl.LoadImageFromScreen()
48
- width, height, channels = image.width, image.height, 4
49
- cdata = self.ffi.buffer(image.data, width*height*channels)
50
- return np.frombuffer(cdata, dtype=np.uint8
51
- ).reshape((height, width, channels))[:, :, :3]
52
-
53
- def render(self, grid):
54
- rl = self.rl
55
- colors = self.colors
56
- ay, ax = None, None
57
-
58
- ts = self.tile_size
59
-
60
- pos = rl.GetMousePosition()
61
- raw_mouse_x = pos.x
62
- raw_mouse_y = pos.y
63
- mouse_x = int(raw_mouse_x // ts)
64
- mouse_y = int(raw_mouse_y // ts)
65
- ay = int(np.clip((pos.y - ts*self.height//2) / 50, -3, 3)) + 3
66
- ax = int(np.clip((pos.x - ts*self.width//2) / 50, -3, 3)) + 3
67
-
68
- if rl.IsKeyDown(rl.KEY_ESCAPE):
69
- exit(0)
70
-
71
- action_id = 0
72
- action_arg = 0
73
-
74
- if rl.IsKeyDown(rl.KEY_E):
75
- action_id = 0
76
- action_arg = 0
77
- elif rl.IsKeyDown(rl.KEY_Q):
78
- action_id = 0
79
- action_arg = 1
80
-
81
- elif rl.IsKeyDown(rl.KEY_W):
82
- action_id = 1
83
- action_arg = 0
84
- elif rl.IsKeyDown(rl.KEY_S):
85
- action_id = 1
86
- action_arg = 1
87
- elif rl.IsKeyDown(rl.KEY_A):
88
- action_id = 1
89
- action_arg = 2
90
- elif rl.IsKeyDown(rl.KEY_R):
91
- action_id = 1
92
- action_arg = 3
93
-
94
- # if rl.IsKeyDown(rl.KEY_LEFT_SHIFT):
95
- # target_heros = 2
96
-
97
- action = (action_id, action_arg)
98
-
99
- rl.BeginDrawing()
100
- rl.BeginMode2D(self.camera)
101
- rl.ClearBackground([6, 24, 24, 255])
102
- for y in range(self.height):
103
- for x in range(self.width):
104
- tile = grid[y, x]
105
- tx = x*ts
106
- ty = y*ts
107
- if tile == 0:
108
- continue
109
- elif tile == 2:
110
- # Wall
111
- rl.DrawRectangle(x*ts, y*ts, ts, ts, [0, 0, 0, 255])
112
- continue
113
- else:
114
- # Player
115
- source_rect = self.asset_map[tile]
116
- dest_rect = (tx, ty, ts, ts)
117
- rl.DrawTexturePro(self.puffer, source_rect, dest_rect,
118
- (0, 0), 0, colors.WHITE)
119
-
120
- # Draw circle at mouse x, y
121
- rl.DrawCircle(ts*mouse_x + ts//2, ts*mouse_y + ts//8, ts//8, [255, 0, 0, 255])
122
-
123
- rl.EndMode2D()
124
-
125
- # Draw HUD
126
- # player = entities[0]
127
- # hud_y = self.height*ts - 2*ts
128
- # draw_bars(rl, player, 2*ts, hud_y, 10*ts, 24, draw_text=True)
129
-
130
- # off_color = [255, 255, 255, 255]
131
- # on_color = [0, 255, 0, 255]
132
-
133
- # q_color = on_color if skill_q else off_color
134
- # w_color = on_color if skill_w else off_color
135
- # e_color = on_color if skill_e else off_color
136
-
137
- # q_cd = player.q_timer
138
- # w_cd = player.w_timer
139
- # e_cd = player.e_timer
140
-
141
- # rl.DrawText(f'Q: {q_cd}'.encode(), 13*ts, hud_y - 20, 40, q_color)
142
- # rl.DrawText(f'W: {w_cd}'.encode(), 17*ts, hud_y - 20, 40, w_color)
143
- # rl.DrawText(f'E: {e_cd}'.encode(), 21*ts, hud_y - 20, 40, e_color)
144
- # rl.DrawText(f'Stun: {player.stun_timer}'.encode(), 25*ts, hud_y - 20, 20, e_color)
145
- # rl.DrawText(f'Move: {player.move_timer}'.encode(), 25*ts, hud_y, 20, e_color)
146
-
147
- rl.EndDrawing()
148
- return self._cdata_to_numpy(), action
149
-
150
- def draw_bars(rl, entity, x, y, width, height=4, draw_text=False):
151
- health_bar = entity.health / entity.max_health
152
- mana_bar = entity.mana / entity.max_mana
153
- if entity.max_health == 0:
154
- health_bar = 2
155
- if entity.max_mana == 0:
156
- mana_bar = 2
157
- rl.DrawRectangle(x, y, width, height, [255, 0, 0, 255])
158
- rl.DrawRectangle(x, y, int(width*health_bar), height, [0, 255, 0, 255])
159
-
160
- if entity.entity_type == 0:
161
- rl.DrawRectangle(x, y - height - 2, width, height, [255, 0, 0, 255])
162
- rl.DrawRectangle(x, y - height - 2, int(width*mana_bar), height, [0, 255, 255, 255])
163
-
164
- if draw_text:
165
- health = int(entity.health)
166
- mana = int(entity.mana)
167
- max_health = int(entity.max_health)
168
- max_mana = int(entity.max_mana)
169
- rl.DrawText(f'Health: {health}/{max_health}'.encode(),
170
- x+8, y+2, 20, [255, 255, 255, 255])
171
- rl.DrawText(f'Mana: {mana}/{max_mana}'.encode(),
172
- x+8, y+2 - height - 2, 20, [255, 255, 255, 255])
173
-
174
- #rl.DrawRectangle(x, y - 2*height - 4, int(width*mana_bar), height, [255, 255, 0, 255])
175
- rl.DrawText(f'Experience: {entity.xp}'.encode(),
176
- x+8, y - 2*height - 4, 20, [255, 255, 255, 255])
177
-
178
- elif entity.entity_type == 0:
179
- rl.DrawText(f'Level: {entity.level}'.encode(),
180
- x+4, y -2*height - 12, 12, [255, 255, 255, 255])
@@ -1,23 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: mettagrid
3
- Version: 0.0.1
4
- Summary: A fast grid-based open-ended MARL environment
5
- Home-page: https://daveey.github.io
6
- License: MIT
7
- Keywords: puffergrid,gridworld,minigrid,rl,reinforcement-learning,environment,gym
8
- Author: David Bloomin
9
- Author-email: daveey@gmail.com
10
- Requires-Python: >=3.10,<4.0
11
- Classifier: License :: OSI Approved :: MIT License
12
- Classifier: Programming Language :: Python :: 3
13
- Classifier: Programming Language :: Python :: 3.10
14
- Classifier: Programming Language :: Python :: 3.11
15
- Classifier: Programming Language :: Python :: 3.12
16
- Requires-Dist: cython (>=3.0.11,<4.0.0)
17
- Requires-Dist: numpy (>=1.21.0,<2.0.0)
18
- Project-URL: Repository, https://github.com/Metta-AI/mettagrid
19
- Description-Content-Type: text/markdown
20
-
21
- # mettagrid
22
- A fast grid-based open-ended MARL environment
23
-
@@ -1,38 +0,0 @@
1
- mettagrid/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- mettagrid/actions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- mettagrid/actions/actions.pxd,sha256=Zd9CpuIEWytp1z-KCcuAUoev7dgR16kgea92p8yodps,765
4
- mettagrid/actions/actions.pyx,sha256=wRg4-3lANoUAIWo6cIAB33AOiPNFg8-EfdCwn-riGP0,1622
5
- mettagrid/actions/attack.pxd,sha256=2VQADMYLj7-EhzVoK1_4w_rJFTnj7l7-5fMHseBqGP8,135
6
- mettagrid/actions/attack.pyx,sha256=dnYTMqNEDa5QX6Btz2shPzW3DBB6Y91Uehr_IbfNQP8,2561
7
- mettagrid/actions/gift.pxd,sha256=f4Y8mQtBhBlD0z_auZQrRs3StYO54TV2fUw5WSDFnG4,105
8
- mettagrid/actions/gift.pyx,sha256=YXRCP3dYATIWVYDroRjVip1wGyi4ZQx1f9Jfr9k6uZQ,748
9
- mettagrid/actions/move.pxd,sha256=GN_4ieZrI6RoY92igO4PmayRIS9O-zQl1oeOfImneeE,105
10
- mettagrid/actions/move.pyx,sha256=8onrsk0jplTOe6OykYw0OdQM9aWzffVyv3pw1Wb2HCg,1206
11
- mettagrid/actions/rotate.pxd,sha256=z2D17nFORP9lw2eZLZB96KE18sy_d914x0pe854O7MU,107
12
- mettagrid/actions/rotate.pyx,sha256=fUaWcLnw0s_utXGfmPWg-SzUDw27ma_tsUso23fpayQ,891
13
- mettagrid/actions/shield.pxd,sha256=9lf9UOWml8koteofGGTTUyLR20dhE8YTFtZZlMAI7hA,107
14
- mettagrid/actions/shield.pyx,sha256=D4h-vsbVNbG87n5eiIYs2BsXIKQIWgZe3geKEd7j-ZA,834
15
- mettagrid/actions/use.pxd,sha256=bFx5IlWzX8mZemv1A5tAg6h97Vt6ev9SSJXewqK33CQ,104
16
- mettagrid/actions/use.pyx,sha256=tHuNx4JdTf3-50_0S_A4Walgo2PZnRaEBuy9CTYA5YY,2623
17
- mettagrid/config/game_builder.py,sha256=f9fS38WaXepiwL9qlWqMBI4aMRjKN11P18Q6mFl2yAM,3360
18
- mettagrid/config/sample_config.py,sha256=BbRqT5hrPY5VKGIC7bVbEjwd_G59defru573KxvCtEA,822
19
- mettagrid/mettagrid.pyx,sha256=jgzXf6cO7IjHsDn2d_0Za9rgn_SngQNGmOwk7FzMyYE,2667
20
- mettagrid/mettagrid_env.py,sha256=NrP8ZuX75JDO-UMa_BOdNKvdz-lqPogEbICRO30Ru4Q,6677
21
- mettagrid/objects.pxd,sha256=_71dLM1W9K5WtwMZj35XpzzjDWZkMCiZep75EOAoXbc,5842
22
- mettagrid/objects.pyx,sha256=CTfc4CQ_NeXkO0LjH_OY8mC4FAluyThKfzn0wzmIHvQ,2197
23
- mettagrid/renderer/assets/ore-0.png,sha256=_vHlTbCy_NZYzYnkLxdRwF-zp1D2H4Md3yI8-ZX8QGA,376
24
- mettagrid/renderer/assets/ore-1.png,sha256=HT--nGPU05Wdk1JKNP1rmBYttPbOkWKOI6J-VDs3jwk,384
25
- mettagrid/renderer/assets/ore-2.png,sha256=Nhn_6IEmPuq9t0rDaCvyPCvpdzX3vZB-X1EoMSpvNvc,425
26
- mettagrid/renderer/assets/ore-3.png,sha256=-Lt-cyIxZMDX_I7vG6w20MInah8CEorE5WGN0rmVP_k,427
27
- mettagrid/renderer/assets/ore-4.png,sha256=vySYN37jPtFeTXXmpyJCCalkR0K2RfutIHp8CXgImjg,410
28
- mettagrid/renderer/assets/ore-5.png,sha256=KSvduI7HnGD4ky3Cq27FwbwHe9pO4-WY1yFoh7mAzCM,410
29
- mettagrid/renderer/assets/ore-6.png,sha256=6GWdbQJ4P5WLsTz8rWpGtXbc6P7JJ-bO7ze3qHQ4bH0,418
30
- mettagrid/renderer/assets/puffer_chars.png,sha256=6FaTd_z6JkMldwlYAW94BajgaaGz30ScWBTmUggxu78,71193
31
- mettagrid/renderer/assets/tiny_galaxy_items.png,sha256=zRfEkwGZ-BnzzCqyse6wyWIGTcteVt_eJVRkTlS4XBA,24116
32
- mettagrid/renderer/assets/tiny_galaxy_monsters.png,sha256=Aw2Ktj-1BtugmjMI9Wnyb4xxAxq6rzD0mgk9IBdkCyM,32763
33
- mettagrid/renderer/assets/wall1-0.png,sha256=MONt_xbscHfODf9T9hiy8poHX_TkMXbk_dC6T0ora7I,1155
34
- mettagrid/renderer/raylib_client.py,sha256=LVZVwHUFlFzDBty2FSWHe5RmR0FPFm-MqA49yTgx81M,6011
35
- mettagrid-0.0.1.dist-info/LICENSE,sha256=_0ZygdDOImEUQjXap6LgAetwhuvlOfOqcMDmNlAdjLo,1070
36
- mettagrid-0.0.1.dist-info/METADATA,sha256=ya2_hp-_kRW07IY0CXD5gvIiyK-l5OpzoaCwGIjJR5Q,815
37
- mettagrid-0.0.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
38
- mettagrid-0.0.1.dist-info/RECORD,,
File without changes
File without changes