epignatelli / navix

Accelerated minigrid environments with JAX
Apache License 2.0
116 stars 10 forks source link

Refactoring the rendering engine #31

Closed epignatelli closed 1 year ago

epignatelli commented 1 year ago

This is a done tick on the biggest foundational step for the library.

There are still some issues I'd like to sort, for example, #26, #21 and #15, but the framework is now in a state where it can be expanded further, for example, #10, #20.

The development of these two branches can be parallelised, should anyone decide to join the development.

github-actions[bot] commented 1 year ago
************* Module navix._version
navix/_version.py:1:0: C0114: Missing module docstring (missing-module-docstring)
************* Module navix.actions
navix/actions.py:121:0: C0301: Line too long (109/100) (line-too-long)
navix/actions.py:146:0: C0301: Line too long (111/100) (line-too-long)
navix/actions.py:1:0: C0114: Missing module docstring (missing-module-docstring)
navix/actions.py:126:0: W0622: Redefining built-in 'open' (redefined-builtin)
navix/actions.py:64:0: C0116: Missing function or method docstring (missing-function-docstring)
navix/actions.py:75:0: C0116: Missing function or method docstring (missing-function-docstring)
navix/actions.py:79:0: C0116: Missing function or method docstring (missing-function-docstring)
navix/actions.py:83:0: C0116: Missing function or method docstring (missing-function-docstring)
navix/actions.py:87:0: C0116: Missing function or method docstring (missing-function-docstring)
navix/actions.py:91:0: C0116: Missing function or method docstring (missing-function-docstring)
navix/actions.py:95:0: C0116: Missing function or method docstring (missing-function-docstring)
navix/actions.py:99:0: C0116: Missing function or method docstring (missing-function-docstring)
navix/actions.py:103:29: C0103: Argument name "a" doesn't conform to snake_case naming style (invalid-name)
navix/actions.py:103:39: C0103: Argument name "b" doesn't conform to snake_case naming style (invalid-name)
navix/actions.py:110:0: C0116: Missing function or method docstring (missing-function-docstring)
navix/actions.py:126:0: C0116: Missing function or method docstring (missing-function-docstring)
navix/actions.py:21:0: W0611: Unused Tuple imported from typing (unused-import)
navix/actions.py:27:0: W0611: Unused Door imported from components (unused-import)
navix/actions.py:27:0: W0611: Unused Key imported from components (unused-import)
************* Module navix.components
navix/components.py:45:0: C0301: Line too long (101/100) (line-too-long)
navix/components.py:50:0: C0301: Line too long (109/100) (line-too-long)
navix/components.py:51:0: C0301: Line too long (118/100) (line-too-long)
navix/components.py:64:0: C0301: Line too long (101/100) (line-too-long)
navix/components.py:66:0: C0301: Line too long (109/100) (line-too-long)
navix/components.py:76:0: C0301: Line too long (101/100) (line-too-long)
navix/components.py:88:0: C0301: Line too long (105/100) (line-too-long)
navix/components.py:89:0: C0301: Line too long (112/100) (line-too-long)
navix/components.py:95:0: C0301: Line too long (101/100) (line-too-long)
navix/components.py:1:0: C0114: Missing module docstring (missing-module-docstring)
navix/components.py:37:0: R0903: Too few public methods (0/2) (too-few-public-methods)
navix/components.py:41:0: R0903: Too few public methods (0/2) (too-few-public-methods)
navix/components.py:60:0: R0903: Too few public methods (0/2) (too-few-public-methods)
navix/components.py:81:4: C0116: Missing function or method docstring (missing-function-docstring)
navix/components.py:71:0: R0903: Too few public methods (1/2) (too-few-public-methods)
navix/components.py:102:4: C0116: Missing function or method docstring (missing-function-docstring)
navix/components.py:85:0: R0903: Too few public methods (1/2) (too-few-public-methods)
navix/components.py:124:4: C0116: Missing function or method docstring (missing-function-docstring)
navix/components.py:135:4: C0116: Missing function or method docstring (missing-function-docstring)
navix/components.py:146:4: C0116: Missing function or method docstring (missing-function-docstring)
navix/components.py:26:0: C0412: Imports from package jax are not grouped (ungrouped-imports)
************* Module navix.environments.environment
navix/environments/environment.py:54:0: C0301: Line too long (105/100) (line-too-long)
navix/environments/environment.py:1:0: C0114: Missing module docstring (missing-module-docstring)
navix/environments/environment.py:39:0: C0115: Missing class docstring (missing-class-docstring)
navix/environments/environment.py:48:0: C0115: Missing class docstring (missing-class-docstring)
navix/environments/environment.py:48:0: R0903: Too few public methods (0/2) (too-few-public-methods)
navix/environments/environment.py:65:0: C0115: Missing class docstring (missing-class-docstring)
navix/environments/environment.py:81:4: C0116: Missing function or method docstring (missing-function-docstring)
navix/environments/environment.py:84:4: W0102: Dangerous default value ACTIONS (builtins.dict) as argument (dangerous-default-value)
navix/environments/environment.py:98:4: C0116: Missing function or method docstring (missing-function-docstring)
navix/environments/environment.py:98:4: W0102: Dangerous default value ACTIONS (builtins.dict) as argument (dangerous-default-value)
navix/environments/environment.py:108:4: C0116: Missing function or method docstring (missing-function-docstring)
navix/environments/environment.py:111:4: C0116: Missing function or method docstring (missing-function-docstring)
navix/environments/environment.py:114:4: C0116: Missing function or method docstring (missing-function-docstring)
navix/environments/environment.py:115:62: C0103: Argument name "t" doesn't conform to snake_case naming style (invalid-name)
navix/environments/environment.py:25:0: W0611: Unused Tuple imported from typing (unused-import)
navix/environments/environment.py:33:0: W0611: Unused import graphics (unused-import)
navix/environments/environment.py:34:0: W0611: Unused RenderingCache imported from graphics (unused-import)
************* Module navix.environments.keydoor
navix/environments/keydoor.py:1:0: C0114: Missing module docstring (missing-module-docstring)
navix/environments/keydoor.py:17:0: C0115: Missing class docstring (missing-class-docstring)
navix/environments/keydoor.py:18:4: R0914: Too many local variables (22/15) (too-many-locals)
navix/environments/keydoor.py:19:13: C0103: Variable name "k1" doesn't conform to snake_case naming style (invalid-name)
navix/environments/keydoor.py:19:17: C0103: Variable name "k2" doesn't conform to snake_case naming style (invalid-name)
navix/environments/keydoor.py:19:21: C0103: Variable name "k3" doesn't conform to snake_case naming style (invalid-name)
navix/environments/keydoor.py:19:25: C0103: Variable name "k4" doesn't conform to snake_case naming style (invalid-name)
************* Module navix.environments.room
navix/environments/room.py:1:0: C0114: Missing module docstring (missing-module-docstring)
navix/environments/room.py:35:0: C0115: Missing class docstring (missing-class-docstring)
navix/environments/room.py:37:13: C0103: Variable name "k1" doesn't conform to snake_case naming style (invalid-name)
navix/environments/room.py:37:17: C0103: Variable name "k2" doesn't conform to snake_case naming style (invalid-name)
navix/environments/room.py:22:0: W0611: Unused Callable imported from typing (unused-import)
************* Module navix.graphics
navix/graphics.py:122:0: C0301: Line too long (122/100) (line-too-long)
navix/graphics.py:294:0: C0301: Line too long (123/100) (line-too-long)
navix/graphics.py:1:0: C0114: Missing module docstring (missing-module-docstring)
navix/graphics.py:53:0: C0116: Missing function or method docstring (missing-function-docstring)
navix/graphics.py:101:0: C0115: Missing class docstring (missing-class-docstring)
navix/graphics.py:106:4: C0116: Missing function or method docstring (missing-function-docstring)
navix/graphics.py:101:0: R0903: Too few public methods (1/2) (too-few-public-methods)
navix/graphics.py:121:0: C0116: Missing function or method docstring (missing-function-docstring)
navix/graphics.py:122:49: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
navix/graphics.py:128:0: C0116: Missing function or method docstring (missing-function-docstring)
navix/graphics.py:134:0: C0116: Missing function or method docstring (missing-function-docstring)
navix/graphics.py:143:0: C0116: Missing function or method docstring (missing-function-docstring)
navix/graphics.py:149:0: C0116: Missing function or method docstring (missing-function-docstring)
navix/graphics.py:155:0: C0116: Missing function or method docstring (missing-function-docstring)
navix/graphics.py:161:0: C0116: Missing function or method docstring (missing-function-docstring)
navix/graphics.py:173:0: C0116: Missing function or method docstring (missing-function-docstring)
navix/graphics.py:173:16: W0613: Unused argument 'size' (unused-argument)
navix/graphics.py:189:0: C0116: Missing function or method docstring (missing-function-docstring)
navix/graphics.py:189:0: R0914: Too many local variables (17/15) (too-many-locals)
navix/graphics.py:195:4: C0103: Variable name "y" doesn't conform to snake_case naming style (invalid-name)
navix/graphics.py:195:7: C0103: Variable name "x" doesn't conform to snake_case naming style (invalid-name)
navix/graphics.py:225:0: C0116: Missing function or method docstring (missing-function-docstring)
navix/graphics.py:231:0: C0116: Missing function or method docstring (missing-function-docstring)
navix/graphics.py:236:0: C0116: Missing function or method docstring (missing-function-docstring)
navix/graphics.py:251:0: C0116: Missing function or method docstring (missing-function-docstring)
navix/graphics.py:251:0: W0102: Dangerous default value TILES_REGISTRY (builtins.dict) as argument (dangerous-default-value)
navix/graphics.py:270:0: C0116: Missing function or method docstring (missing-function-docstring)
navix/graphics.py:286:0: C0116: Missing function or method docstring (missing-function-docstring)
************* Module navix.grid
navix/grid.py:1:0: C0114: Missing module docstring (missing-module-docstring)
navix/grid.py:34:0: C0116: Missing function or method docstring (missing-function-docstring)
navix/grid.py:38:38: W0621: Redefining name 'coordinates' from outer scope (line 34) (redefined-outer-name)
navix/grid.py:71:0: C0116: Missing function or method docstring (missing-function-docstring)
navix/grid.py:83:0: C0116: Missing function or method docstring (missing-function-docstring)
navix/grid.py:87:0: C0116: Missing function or method docstring (missing-function-docstring)
navix/grid.py:91:0: C0116: Missing function or method docstring (missing-function-docstring)
navix/grid.py:95:0: C0116: Missing function or method docstring (missing-function-docstring)
navix/grid.py:99:0: C0116: Missing function or method docstring (missing-function-docstring)
navix/grid.py:100:32: C0103: Argument name "n" doesn't conform to snake_case naming style (invalid-name)
navix/grid.py:110:0: C0116: Missing function or method docstring (missing-function-docstring)
navix/grid.py:110:37: C0103: Argument name "n" doesn't conform to snake_case naming style (invalid-name)
navix/grid.py:137:0: C0116: Missing function or method docstring (missing-function-docstring)
navix/grid.py:137:0: W0102: Dangerous default value {} as argument (dangerous-default-value)
************* Module navix.observations
navix/observations.py:101:0: C0301: Line too long (101/100) (line-too-long)
navix/observations.py:1:0: C0114: Missing module docstring (missing-module-docstring)
navix/observations.py:60:0: C0116: Missing function or method docstring (missing-function-docstring)
navix/observations.py:60:0: W0102: Dangerous default value graphics.TILES_REGISTRY (builtins.dict) as argument (dangerous-default-value)
navix/observations.py:61:4: W0613: Unused argument 'state' (unused-argument)
navix/observations.py:63:4: W0613: Unused argument 'tiles_registry' (unused-argument)
navix/observations.py:68:0: C0116: Missing function or method docstring (missing-function-docstring)
navix/observations.py:68:0: W0102: Dangerous default value graphics.TILES_REGISTRY (builtins.dict) as argument (dangerous-default-value)
navix/observations.py:71:4: W0613: Unused argument 'tiles_registry' (unused-argument)
navix/observations.py:84:0: C0116: Missing function or method docstring (missing-function-docstring)
navix/observations.py:84:0: W0102: Dangerous default value graphics.TILES_REGISTRY (builtins.dict) as argument (dangerous-default-value)
navix/observations.py:22:0: W0611: Unused Tuple imported from typing (unused-import)
navix/observations.py:24:0: W0611: Unused import jax (unused-import)
************* Module grid
tests/performance/grid.py:1:0: C0114: Missing module docstring (missing-module-docstring)
tests/performance/grid.py:15:0: C0116: Missing function or method docstring (missing-function-docstring)
tests/performance/grid.py:29:8: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
tests/performance/grid.py:39:10: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
tests/performance/grid.py:43:8: W0108: Lambda may not be necessary (unnecessary-lambda)
************* Module minigrid
tests/performance/minigrid.py:1:0: C0114: Missing module docstring (missing-module-docstring)
tests/performance/minigrid.py:17:0: C0116: Missing function or method docstring (missing-function-docstring)
tests/performance/minigrid.py:17:23: W0613: Unused argument 'seed' (unused-argument)
tests/performance/minigrid.py:32:0: C0116: Missing function or method docstring (missing-function-docstring)
tests/performance/minigrid.py:32:21: W0613: Unused argument 'seed' (unused-argument)
tests/performance/minigrid.py:34:17: W0612: Unused variable 'info' (unused-variable)
tests/performance/minigrid.py:37:21: W0612: Unused variable 'reward' (unused-variable)
tests/performance/minigrid.py:48:8: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
tests/performance/minigrid.py:57:10: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
tests/performance/minigrid.py:61:8: W0108: Lambda may not be necessary (unnecessary-lambda)
tests/performance/minigrid.py:69:10: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
tests/performance/minigrid.py:5:0: C0411: third party import "import gymnasium" should be placed before "import navix as nx" (wrong-import-order)
tests/performance/minigrid.py:6:0: C0411: standard import "import random" should be placed before "import jax" (wrong-import-order)
tests/performance/minigrid.py:7:0: C0411: standard import "import time" should be placed before "import jax" (wrong-import-order)
tests/performance/minigrid.py:9:0: C0411: standard import "from timeit import repeat" should be placed before "import jax" (wrong-import-order)
************* Module observations
tests/performance/observations.py:1:0: C0114: Missing module docstring (missing-module-docstring)
tests/performance/observations.py:15:0: C0116: Missing function or method docstring (missing-function-docstring)
tests/performance/observations.py:29:8: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
tests/performance/observations.py:39:10: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
tests/performance/observations.py:43:8: W0108: Lambda may not be necessary (unnecessary-lambda)
************* Module profiling
tests/performance/profiling.py:1:0: C0114: Missing module docstring (missing-module-docstring)
tests/performance/profiling.py:9:0: C0116: Missing function or method docstring (missing-function-docstring)
tests/performance/profiling.py:9:0: C0103: Function name "f" doesn't conform to snake_case naming style (invalid-name)
tests/performance/profiling.py:13:4: W0621: Redefining name 'timestep' from outer scope (line 50) (redefined-outer-name)
tests/performance/profiling.py:24:0: C0116: Missing function or method docstring (missing-function-docstring)
tests/performance/profiling.py:28:4: W0621: Redefining name 'timestep' from outer scope (line 50) (redefined-outer-name)
tests/performance/profiling.py:30:24: C0103: Argument name "x" doesn't conform to snake_case naming style (invalid-name)
tests/performance/profiling.py:31:8: W0621: Redefining name 'timestep' from outer scope (line 50) (redefined-outer-name)
tests/performance/profiling.py:30:4: W0612: Unused variable 'body_fun' (unused-variable)
************* Module test_actions
tests/test_actions.py:77:0: C0301: Line too long (107/100) (line-too-long)
tests/test_actions.py:1:0: C0114: Missing module docstring (missing-module-docstring)
tests/test_actions.py:8:0: C0116: Missing function or method docstring (missing-function-docstring)
tests/test_actions.py:24:12: W0212: Access to a protected member _rotate of a client class (protected-access)
tests/test_actions.py:29:12: W0212: Access to a protected member _rotate of a client class (protected-access)
tests/test_actions.py:34:12: W0212: Access to a protected member _rotate of a client class (protected-access)
tests/test_actions.py:39:12: W0212: Access to a protected member _rotate of a client class (protected-access)
tests/test_actions.py:8:0: R1711: Useless return at end of function or method (useless-return)
tests/test_actions.py:46:0: C0116: Missing function or method docstring (missing-function-docstring)
tests/test_actions.py:76:19: W0212: Access to a protected member _walkable of a client class (protected-access)
tests/test_actions.py:77:12: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
tests/test_actions.py:108:0: C0116: Missing function or method docstring (missing-function-docstring)
tests/test_actions.py:120:4: W0105: String statement has no effect (pointless-string-statement)
tests/test_actions.py:139:8: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
tests/test_actions.py:148:8: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
tests/test_actions.py:153:8: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
tests/test_actions.py:157:0: C0116: Missing function or method docstring (missing-function-docstring)
tests/test_actions.py:188:8: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
tests/test_actions.py:198:8: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
tests/test_actions.py:201:8: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
tests/test_actions.py:210:8: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
tests/test_actions.py:214:8: C0209: Formatting a regular string which could be a f-string (consider-using-f-string)
************* Module test_environments
tests/test_environments.py:1:0: C0114: Missing module docstring (missing-module-docstring)
tests/test_environments.py:6:0: C0116: Missing function or method docstring (missing-function-docstring)
tests/test_environments.py:7:4: C0103: Function name "f" doesn't conform to snake_case naming style (invalid-name)
tests/test_environments.py:36:0: C0116: Missing function or method docstring (missing-function-docstring)
tests/test_environments.py:37:4: C0103: Function name "f" doesn't conform to snake_case naming style (invalid-name)
************* Module test_grid
tests/test_grid.py:1:0: C0114: Missing module docstring (missing-module-docstring)
tests/test_grid.py:6:0: C0116: Missing function or method docstring (missing-function-docstring)
tests/test_grid.py:31:0: C0116: Missing function or method docstring (missing-function-docstring)
tests/test_grid.py:44:0: C0116: Missing function or method docstring (missing-function-docstring)
************* Module test_observations
tests/test_observations.py:1:0: C0114: Missing module docstring (missing-module-docstring)
tests/test_observations.py:7:0: C0116: Missing function or method docstring (missing-function-docstring)
tests/test_observations.py:37:8: C0103: Variable name "x" doesn't conform to snake_case naming style (invalid-name)
tests/test_observations.py:38:8: C0103: Variable name "y" doesn't conform to snake_case naming style (invalid-name)
tests/test_observations.py:7:0: R1711: Useless return at end of function or method (useless-return)
tests/test_observations.py:1:0: R0801: Similar lines in 2 files
==grid:[36:51]
==observations:[36:51]
    start = time.time()
    test_jit = jax.jit(jax.vmap(test)).lower(seeds).compile()
    print("\tCompiled in {:.2f}s".format(time.time() - start))

    print("\tRunning ...")
    res = repeat(
        lambda: test_jit(seeds).observation.block_until_ready(),
        number=N_TIMEIT_LOOPS,
        repeat=N_REPEAT,
    )
    res = jnp.asarray(res)
    print(f"\t {jnp.mean(res)} ± {jnp.std(res)}")

if __name__ == "__main__": (duplicate-code)
tests/test_observations.py:1:0: R0801: Similar lines in 2 files
==grid:[18:28]
==observations:[18:28]
        )
        key = jax.random.PRNGKey(seed)
        timestep = env.reset(key)

        actions = jax.random.randint(key, (100,), 0, 6)
        timestep = jax.lax.scan(lambda c, x: (env.step(c, x), ()), timestep, actions)[0]
        return timestep

    # profile navix scanned
    print( (duplicate-code)
tests/test_observations.py:1:0: R0801: Similar lines in 2 files
==navix.environments.keydoor:[46:51]
==test_actions:[63:68]
        grid=grid,
        player=player,
        goals=goals,
        keys=keys,
        doors=doors, (duplicate-code)

Report
======
831 statements analysed.

Statistics by type
------------------

+---------+-------+-----------+-----------+------------+---------+
|type     |number |old number |difference |%documented |%badname |
+=========+=======+===========+===========+============+=========+
|module   |17     |NC         |NC         |0.00        |0.00     |
+---------+-------+-----------+-----------+------------+---------+
|class    |12     |NC         |NC         |50.00       |0.00     |
+---------+-------+-----------+-----------+------------+---------+
|method   |14     |NC         |NC         |21.43       |0.00     |
+---------+-------+-----------+-----------+------------+---------+
|function |71     |NC         |NC         |23.94       |4.23     |
+---------+-------+-----------+-----------+------------+---------+

1828 lines have been analyzed

Raw metrics
-----------

+----------+-------+------+---------+-----------+
|type      |number |%     |previous |difference |
+==========+=======+======+=========+===========+
|code      |1139   |62.31 |NC       |NC         |
+----------+-------+------+---------+-----------+
|docstring |84     |4.60  |NC       |NC         |
+----------+-------+------+---------+-----------+
|comment   |228    |12.47 |NC       |NC         |
+----------+-------+------+---------+-----------+
|empty     |377    |20.62 |NC       |NC         |
+----------+-------+------+---------+-----------+

Duplication
-----------

+-------------------------+------+---------+-----------+
|                         |now   |previous |difference |
+=========================+======+=========+===========+
|nb duplicated lines      |0     |NC       |NC         |
+-------------------------+------+---------+-----------+
|percent duplicated lines |0.000 |NC       |NC         |
+-------------------------+------+---------+-----------+

Messages by category
--------------------

+-----------+-------+---------+-----------+
|type       |number |previous |difference |
+===========+=======+=========+===========+
|convention |145    |NC       |NC         |
+-----------+-------+---------+-----------+
|refactor   |14     |NC       |NC         |
+-----------+-------+---------+-----------+
|warning    |39     |NC       |NC         |
+-----------+-------+---------+-----------+
|error      |0      |NC       |NC         |
+-----------+-------+---------+-----------+

Messages
--------

+---------------------------+------------+
|message id                 |occurrences |
+===========================+============+
|missing-function-docstring |65          |
+---------------------------+------------+
|invalid-name               |19          |
+---------------------------+------------+
|missing-module-docstring   |17          |
+---------------------------+------------+
|consider-using-f-string    |17          |
+---------------------------+------------+
|line-too-long              |16          |
+---------------------------+------------+
|unused-import              |9           |
+---------------------------+------------+
|too-few-public-methods     |7           |
+---------------------------+------------+
|dangerous-default-value    |7           |
+---------------------------+------------+
|unused-argument            |6           |
+---------------------------+------------+
|missing-class-docstring    |6           |
+---------------------------+------------+
|protected-access           |5           |
+---------------------------+------------+
|wrong-import-order         |4           |
+---------------------------+------------+
|redefined-outer-name       |4           |
+---------------------------+------------+
|unused-variable            |3           |
+---------------------------+------------+
|unnecessary-lambda         |3           |
+---------------------------+------------+
|duplicate-code             |3           |
+---------------------------+------------+
|useless-return             |2           |
+---------------------------+------------+
|too-many-locals            |2           |
+---------------------------+------------+
|ungrouped-imports          |1           |
+---------------------------+------------+
|redefined-builtin          |1           |
+---------------------------+------------+
|pointless-string-statement |1           |
+---------------------------+------------+

-----------------------------------
Your code has been rated at 7.62/10