gr-libs 0.1.5__py3-none-any.whl → 0.1.7.post0__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.
- gr_libs/__init__.py +5 -1
- gr_libs/_version.py +21 -0
- gr_libs/environment/__init__.py +2 -2
- gr_libs/environment/environment.py +1 -1
- gr_libs/metrics/metrics.py +1 -2
- gr_libs/ml/tabular/tabular_q_learner.py +1 -1
- gr_libs/ml/utils/storage.py +7 -0
- gr_libs/problems/__init__.py +0 -0
- gr_libs/problems/consts.py +1244 -0
- gr_libs/recognizer/graml/graml_recognizer.py +21 -12
- gr_libs/recognizer/recognizer.py +0 -1
- {gr_libs-0.1.5.dist-info → gr_libs-0.1.7.post0.dist-info}/METADATA +22 -1
- {gr_libs-0.1.5.dist-info → gr_libs-0.1.7.post0.dist-info}/RECORD +22 -18
- {gr_libs-0.1.5.dist-info → gr_libs-0.1.7.post0.dist-info}/WHEEL +1 -1
- {gr_libs-0.1.5.dist-info → gr_libs-0.1.7.post0.dist-info}/top_level.txt +1 -0
- tests/test_graml.py +16 -0
- tests/test_graql.py +4 -0
- tutorials/graml_minigrid_tutorial.py +25 -21
- tutorials/graml_panda_tutorial.py +29 -25
- tutorials/graml_parking_tutorial.py +29 -24
- tutorials/graml_point_maze_tutorial.py +27 -23
- tutorials/graql_minigrid_tutorial.py +25 -20
- gr_libs/recognizer/recognizer_doc.md +0 -61
gr_libs/__init__.py
CHANGED
@@ -1,2 +1,6 @@
|
|
1
1
|
from gr_libs.recognizer.graml.graml_recognizer import ExpertBasedGraml, GCGraml
|
2
|
-
from gr_libs.recognizer.gr_as_rl.gr_as_rl_recognizer import Graql
|
2
|
+
from gr_libs.recognizer.gr_as_rl.gr_as_rl_recognizer import Graql
|
3
|
+
try:
|
4
|
+
from ._version import version as __version__
|
5
|
+
except ImportError:
|
6
|
+
__version__ = "0.0.0" # fallback if file isn't present
|
gr_libs/_version.py
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# file generated by setuptools-scm
|
2
|
+
# don't change, don't track in version control
|
3
|
+
|
4
|
+
__all__ = ["__version__", "__version_tuple__", "version", "version_tuple"]
|
5
|
+
|
6
|
+
TYPE_CHECKING = False
|
7
|
+
if TYPE_CHECKING:
|
8
|
+
from typing import Tuple
|
9
|
+
from typing import Union
|
10
|
+
|
11
|
+
VERSION_TUPLE = Tuple[Union[int, str], ...]
|
12
|
+
else:
|
13
|
+
VERSION_TUPLE = object
|
14
|
+
|
15
|
+
version: str
|
16
|
+
__version__: str
|
17
|
+
__version_tuple__: VERSION_TUPLE
|
18
|
+
version_tuple: VERSION_TUPLE
|
19
|
+
|
20
|
+
__version__ = version = '0.1.7.post0'
|
21
|
+
__version_tuple__ = version_tuple = (0, 1, 7, 'post0')
|
gr_libs/environment/__init__.py
CHANGED
@@ -12,11 +12,11 @@ def is_extra_installed(package: str, extra: str) -> bool:
|
|
12
12
|
return False # The package is not installed
|
13
13
|
|
14
14
|
# Check if `gr_libs[minigrid]` was installed
|
15
|
-
for env in ["minigrid", "panda", "
|
15
|
+
for env in ["minigrid", "panda", "highway", "maze"]:
|
16
16
|
if is_extra_installed("gr_libs", f"gr_envs[{env}]"):
|
17
17
|
try:
|
18
18
|
importlib.import_module(f"gr_envs.{env}_scripts.envs")
|
19
19
|
except ImportError:
|
20
|
-
raise ImportError(f"
|
20
|
+
raise ImportError(f"gr_envs[{env}] was not installed, but gr_libs[{env}] requires it! if you messed with gr_envs installation, you can reinstall gr_libs.")
|
21
21
|
else:
|
22
22
|
warnings.warn(f"gr_libs[{env}] was not installed, skipping {env} imports.", RuntimeWarning)
|
@@ -105,7 +105,7 @@ class MinigridProperty(EnvProperty):
|
|
105
105
|
env_id = problem_name.split("-DynamicGoal-")[0] + "-DynamicGoal-" + problem_name.split("-DynamicGoal-")[1]
|
106
106
|
result = register(
|
107
107
|
id=env_id,
|
108
|
-
entry_point="
|
108
|
+
entry_point="gr_envs.minigrid_scripts.envs:CustomColorEnv",
|
109
109
|
kwargs={"size": 13 if 'Simple' in problem_name else 9,
|
110
110
|
"num_crossings": 4 if 'Simple' in problem_name else 3,
|
111
111
|
"goal_pos": self.str_to_goal(problem_name),
|
gr_libs/metrics/metrics.py
CHANGED
@@ -5,7 +5,6 @@ import numpy as np
|
|
5
5
|
|
6
6
|
from typing import Callable, Generator, List, Dict, Tuple, Any
|
7
7
|
from math import log2
|
8
|
-
from numpy.core.fromnumeric import mean
|
9
8
|
from scipy.stats import wasserstein_distance
|
10
9
|
from gymnasium.spaces.discrete import Discrete
|
11
10
|
# import torch
|
@@ -43,7 +42,7 @@ def kl_divergence_norm_softmax(observations: List[Tuple[State, Any]], agent, act
|
|
43
42
|
qp2_flatten_distribution_list: List[float] = agent.get_actions_probabilities(
|
44
43
|
observation=(observation, agent_pos))
|
45
44
|
distances.append(kl_divergence(qp1, qp2_flatten_distribution_list))
|
46
|
-
return mean(distances)
|
45
|
+
return np.mean(distances)
|
47
46
|
|
48
47
|
|
49
48
|
def amplify(values, alpha=1.0):
|
@@ -351,7 +351,7 @@ class TabularQLearner(TabularRLAgent):
|
|
351
351
|
def simplify_observation(self, observation):
|
352
352
|
return [(obs['direction'], agent_pos_x, agent_pos_y, action) for ((obs, (agent_pos_x, agent_pos_y)), action) in observation] # list of tuples, each tuple the sample
|
353
353
|
|
354
|
-
def generate_observation(self, action_selection_method: MethodType, random_optimalism, save_fig
|
354
|
+
def generate_observation(self, action_selection_method: MethodType, random_optimalism, save_fig=False, fig_path: str=None, env_prop=None):
|
355
355
|
"""
|
356
356
|
Generate a single observation given a list of agents
|
357
357
|
|
gr_libs/ml/utils/storage.py
CHANGED
@@ -15,6 +15,13 @@ def get_storage_framework_dir(recognizer: str):
|
|
15
15
|
return os.path.join(get_storage_dir(),recognizer)
|
16
16
|
|
17
17
|
def get_storage_dir():
|
18
|
+
# Prefer local directory if it exists (e.g., in GitHub workspace)
|
19
|
+
if os.path.exists("dataset"):
|
20
|
+
return "dataset"
|
21
|
+
# Fall back to pre-mounted directory (e.g., in Docker container)
|
22
|
+
if os.path.exists("/preloaded_data"):
|
23
|
+
return "/preloaded_data"
|
24
|
+
# Default to "dataset" even if it doesn't exist (e.g., will be created)
|
18
25
|
return "dataset"
|
19
26
|
|
20
27
|
def _get_models_directory_name():
|
File without changes
|