gr-libs 0.1.4__py3-none-any.whl → 0.1.6.post1__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.
- CI/README.md +12 -0
- CI/docker_build_context/Dockerfile +15 -0
- gr_libs/_version.py +21 -0
- gr_libs/environment/__init__.py +22 -0
- gr_libs/environment/environment.py +1 -3
- gr_libs/metrics/metrics.py +1 -2
- gr_libs/ml/neural/deep_rl_learner.py +10 -12
- gr_libs/problems/__init__.py +0 -0
- gr_libs/problems/consts.py +1244 -0
- gr_libs/recognizer/graml/graml_recognizer.py +1 -2
- gr_libs/recognizer/recognizer.py +3 -4
- {gr_libs-0.1.4.dist-info → gr_libs-0.1.6.post1.dist-info}/METADATA +22 -1
- {gr_libs-0.1.4.dist-info → gr_libs-0.1.6.post1.dist-info}/RECORD +22 -15
- {gr_libs-0.1.4.dist-info → gr_libs-0.1.6.post1.dist-info}/top_level.txt +2 -0
- tests/test_graml.py +16 -0
- tests/test_graql.py +4 -0
- tutorials/graml_minigrid_tutorial.py +26 -22
- tutorials/graml_panda_tutorial.py +31 -22
- tutorials/graml_parking_tutorial.py +30 -30
- tutorials/graml_point_maze_tutorial.py +31 -35
- tutorials/graql_minigrid_tutorial.py +25 -20
- {gr_libs-0.1.4.dist-info → gr_libs-0.1.6.post1.dist-info}/WHEEL +0 -0
CI/README.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
## How to build a new docker image including new trained agents:
|
2
|
+
1. Install docker
|
3
|
+
2. Make sure you have a dataset.zip at your repo root
|
4
|
+
3. Make sure you have a classic token in github: https://github.com/settings/tokens . If you don't, create one with package write, read and delete permissions and copy it somewhere safe.
|
5
|
+
4. Authenticate to ghcr with docker by running:
|
6
|
+
```sh
|
7
|
+
echo ghp_REST_OF_TOKEN | docker login ghcr.io -u MatanShamir1 --password-stdin
|
8
|
+
```
|
9
|
+
3. docker build -t ghcr.io/<your-username>/gr_test_base:latest -f CI/Dockerfile .
|
10
|
+
(the -f Dockerfile tells docker which Dockerfile to use and the '.' tells docker what's the build context, or where the dataset.zip should live)
|
11
|
+
4. docker push ghcr.io/<your-username>/gr_test_base:latest
|
12
|
+
docker push ghcr.io/MatanShamir1/gr_test_base:latest
|
@@ -0,0 +1,15 @@
|
|
1
|
+
FROM python:3.11-slim
|
2
|
+
|
3
|
+
# Set workdir
|
4
|
+
WORKDIR /app
|
5
|
+
|
6
|
+
# Install unzip
|
7
|
+
RUN apt-get update && apt-get install -y unzip && rm -rf /var/lib/apt/lists/*
|
8
|
+
|
9
|
+
# Copy and unzip the dataset
|
10
|
+
COPY dataset.zip .
|
11
|
+
RUN unzip dataset.zip && rm dataset.zip
|
12
|
+
RUN mv dataset_new dataset
|
13
|
+
|
14
|
+
# Just start with bash by default
|
15
|
+
CMD [ "bash" ]
|
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.6.post1'
|
21
|
+
__version_tuple__ = version_tuple = (0, 1, 6)
|
gr_libs/environment/__init__.py
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
import importlib.metadata
|
2
|
+
import warnings
|
3
|
+
|
4
|
+
def is_extra_installed(package: str, extra: str) -> bool:
|
5
|
+
"""Check if an extra was installed for a given package."""
|
6
|
+
try:
|
7
|
+
# Get metadata for the installed package
|
8
|
+
dist = importlib.metadata.metadata(package)
|
9
|
+
requires = dist.get_all("Requires-Dist", []) # Dependencies listed in the package metadata
|
10
|
+
return any(extra in req for req in requires)
|
11
|
+
except importlib.metadata.PackageNotFoundError:
|
12
|
+
return False # The package is not installed
|
13
|
+
|
14
|
+
# Check if `gr_libs[minigrid]` was installed
|
15
|
+
for env in ["minigrid", "panda", "highway", "point_maze"]:
|
16
|
+
if is_extra_installed("gr_libs", f"gr_envs[{env}]"):
|
17
|
+
try:
|
18
|
+
importlib.import_module(f"gr_envs.{env}_scripts.envs")
|
19
|
+
except ImportError:
|
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
|
+
else:
|
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),
|
@@ -168,8 +168,6 @@ class PandaProperty(GCEnvProperty):
|
|
168
168
|
|
169
169
|
|
170
170
|
class ParkingProperty(GCEnvProperty):
|
171
|
-
# def str_to_goal(self): # TODO not use it, goal is not a part of the env property anymore.
|
172
|
-
# return self.name.split("-")[-2]
|
173
171
|
|
174
172
|
def __init__(self, name):
|
175
173
|
super().__init__(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):
|
@@ -13,11 +13,6 @@ if __name__ != "__main__":
|
|
13
13
|
from gr_libs.ml.utils.format import random_subset_with_order
|
14
14
|
from stable_baselines3 import SAC, PPO
|
15
15
|
from stable_baselines3.common.vec_env import DummyVecEnv
|
16
|
-
from gr_envs.custom_env_wrappers.flat_obs_wrapper import CombineAchievedGoalAndObservationWrapper
|
17
|
-
|
18
|
-
# important for registration of envs! do not remove lad
|
19
|
-
import gr_envs.maze_scripts.envs.maze
|
20
|
-
import gr_envs.highway_env_scripts.envs.parking_env
|
21
16
|
from gr_libs.ml.utils import device
|
22
17
|
|
23
18
|
# built-in python modules
|
@@ -32,13 +27,15 @@ def create_vec_env(kwargs):
|
|
32
27
|
return DummyVecEnv([lambda: env])
|
33
28
|
|
34
29
|
def change_goal_to_specific_desired(obs, desired):
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
30
|
+
if desired is not None:
|
31
|
+
obs['desired_goal'] = desired
|
32
|
+
# try:
|
33
|
+
# if desired!=None: obs['desired_goal'] = desired
|
34
|
+
# except Exception as e:
|
35
|
+
# try:
|
36
|
+
# if all(desired!=None): obs['desired_goal'] = desired
|
37
|
+
# except Exception as e:
|
38
|
+
# if all([desiredy!=None for desiredish in desired for desiredy in desiredish]): obs['desired_goal'] = desired
|
42
39
|
|
43
40
|
|
44
41
|
NETWORK_SETUP = {
|
@@ -265,6 +262,7 @@ class DeepRLAgent():
|
|
265
262
|
assert fig_path == None, "You can't specify a vid path when you don't even save the figure."
|
266
263
|
else:
|
267
264
|
assert fig_path != None, "You need to specify a vid path when you save the figure."
|
265
|
+
# The try-except is a bug fix for the env not being reset properly in panda. If someone wants to check why and provide a robust solution they're welcome.
|
268
266
|
try:
|
269
267
|
obs = self.env.reset()
|
270
268
|
change_goal_to_specific_desired(obs, desired)
|
File without changes
|