gr-libs 0.1.8__py3-none-any.whl → 0.2.5__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 +3 -1
- gr_libs/_version.py +2 -2
- gr_libs/all_experiments.py +260 -0
- gr_libs/environment/__init__.py +14 -1
- gr_libs/environment/_utils/__init__.py +0 -0
- gr_libs/environment/{utils → _utils}/utils.py +1 -1
- gr_libs/environment/environment.py +278 -23
- gr_libs/evaluation/__init__.py +1 -0
- gr_libs/evaluation/generate_experiments_results.py +100 -0
- gr_libs/metrics/__init__.py +2 -0
- gr_libs/metrics/metrics.py +166 -31
- gr_libs/ml/__init__.py +1 -6
- gr_libs/ml/base/__init__.py +3 -1
- gr_libs/ml/base/rl_agent.py +68 -3
- gr_libs/ml/neural/__init__.py +1 -3
- gr_libs/ml/neural/deep_rl_learner.py +241 -84
- gr_libs/ml/neural/utils/__init__.py +1 -2
- gr_libs/ml/planner/mcts/{utils → _utils}/tree.py +1 -1
- gr_libs/ml/planner/mcts/mcts_model.py +71 -34
- gr_libs/ml/sequential/__init__.py +0 -1
- gr_libs/ml/sequential/{lstm_model.py → _lstm_model.py} +11 -14
- gr_libs/ml/tabular/__init__.py +1 -3
- gr_libs/ml/tabular/tabular_q_learner.py +27 -9
- gr_libs/ml/tabular/tabular_rl_agent.py +22 -9
- gr_libs/ml/utils/__init__.py +2 -9
- gr_libs/ml/utils/format.py +13 -90
- gr_libs/ml/utils/math.py +3 -2
- gr_libs/ml/utils/other.py +2 -2
- gr_libs/ml/utils/storage.py +41 -94
- gr_libs/odgr_executor.py +263 -0
- gr_libs/problems/consts.py +570 -292
- gr_libs/recognizer/{utils → _utils}/format.py +2 -2
- gr_libs/recognizer/gr_as_rl/gr_as_rl_recognizer.py +127 -36
- gr_libs/recognizer/graml/{gr_dataset.py → _gr_dataset.py} +11 -11
- gr_libs/recognizer/graml/graml_recognizer.py +186 -35
- gr_libs/recognizer/recognizer.py +59 -10
- gr_libs/tutorials/draco_panda_tutorial.py +58 -0
- gr_libs/tutorials/draco_parking_tutorial.py +56 -0
- {tutorials → gr_libs/tutorials}/gcdraco_panda_tutorial.py +11 -11
- {tutorials → gr_libs/tutorials}/gcdraco_parking_tutorial.py +6 -8
- {tutorials → gr_libs/tutorials}/graml_minigrid_tutorial.py +18 -14
- {tutorials → gr_libs/tutorials}/graml_panda_tutorial.py +11 -12
- {tutorials → gr_libs/tutorials}/graml_parking_tutorial.py +8 -10
- {tutorials → gr_libs/tutorials}/graml_point_maze_tutorial.py +17 -3
- {tutorials → gr_libs/tutorials}/graql_minigrid_tutorial.py +2 -2
- {gr_libs-0.1.8.dist-info → gr_libs-0.2.5.dist-info}/METADATA +95 -29
- gr_libs-0.2.5.dist-info/RECORD +72 -0
- {gr_libs-0.1.8.dist-info → gr_libs-0.2.5.dist-info}/WHEEL +1 -1
- gr_libs-0.2.5.dist-info/top_level.txt +2 -0
- tests/test_draco.py +14 -0
- tests/test_gcdraco.py +2 -2
- tests/test_graml.py +4 -4
- tests/test_graql.py +1 -1
- tests/test_odgr_executor_expertbasedgraml.py +14 -0
- tests/test_odgr_executor_gcdraco.py +14 -0
- tests/test_odgr_executor_gcgraml.py +14 -0
- tests/test_odgr_executor_graql.py +14 -0
- evaluation/analyze_results_cross_alg_cross_domain.py +0 -267
- evaluation/create_minigrid_map_image.py +0 -38
- evaluation/file_system.py +0 -53
- evaluation/generate_experiments_results.py +0 -141
- evaluation/generate_experiments_results_new_ver1.py +0 -238
- evaluation/generate_experiments_results_new_ver2.py +0 -331
- evaluation/generate_task_specific_statistics_plots.py +0 -500
- evaluation/get_plans_images.py +0 -62
- evaluation/increasing_and_decreasing_.py +0 -104
- gr_libs/ml/neural/utils/penv.py +0 -60
- gr_libs-0.1.8.dist-info/RECORD +0 -70
- gr_libs-0.1.8.dist-info/top_level.txt +0 -4
- /gr_libs/{environment/utils/__init__.py → _evaluation/_generate_experiments_results.py} +0 -0
- /gr_libs/ml/planner/mcts/{utils → _utils}/__init__.py +0 -0
- /gr_libs/ml/planner/mcts/{utils → _utils}/node.py +0 -0
- /gr_libs/recognizer/{utils → _utils}/__init__.py +0 -0
gr_libs/recognizer/recognizer.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
from abc import ABC, abstractmethod
|
2
|
-
|
3
|
-
from gr_libs.environment.
|
4
|
-
from gr_libs.environment.
|
2
|
+
|
3
|
+
from gr_libs.environment._utils.utils import domain_to_env_property
|
4
|
+
from gr_libs.environment.environment import SUPPORTED_DOMAINS
|
5
5
|
from gr_libs.ml.base.rl_agent import RLAgent
|
6
6
|
|
7
7
|
|
@@ -11,7 +11,7 @@ class Recognizer(ABC):
|
|
11
11
|
domain_name: str,
|
12
12
|
env_name: str,
|
13
13
|
collect_statistics=False,
|
14
|
-
rl_agent_type:
|
14
|
+
rl_agent_type: type[RLAgent] = None,
|
15
15
|
**kwargs,
|
16
16
|
):
|
17
17
|
assert domain_name in SUPPORTED_DOMAINS
|
@@ -27,30 +27,79 @@ class Recognizer(ABC):
|
|
27
27
|
|
28
28
|
|
29
29
|
class LearningRecognizer(Recognizer):
|
30
|
+
"""
|
31
|
+
A class that represents a learning recognizer.
|
32
|
+
|
33
|
+
Inherits from the Recognizer class.
|
34
|
+
"""
|
35
|
+
|
30
36
|
def __init__(self, *args, **kwargs):
|
31
37
|
super().__init__(*args, **kwargs)
|
32
38
|
|
33
|
-
def domain_learning_phase(self, base_goals:
|
39
|
+
def domain_learning_phase(self, base_goals: list[str], train_configs: list):
|
40
|
+
"""
|
41
|
+
Perform the domain learning phase.
|
42
|
+
|
43
|
+
Args:
|
44
|
+
base_goals (List[str]): The base goals for the learning phase.
|
45
|
+
train_configs (List): The training configurations.
|
46
|
+
|
47
|
+
"""
|
34
48
|
self.original_train_configs = train_configs
|
35
49
|
|
36
50
|
|
37
51
|
# a recognizer that needs to train agents for every new goal as part of the goal adaptation phase (that's why it needs dynamic train configs)
|
38
52
|
class GaAgentTrainerRecognizer(Recognizer):
|
53
|
+
"""
|
54
|
+
A class representing a recognizer for GaAgentTrainer.
|
55
|
+
"""
|
56
|
+
|
39
57
|
def __init__(self, *args, **kwargs):
|
40
58
|
super().__init__(*args, **kwargs)
|
41
59
|
|
42
60
|
@abstractmethod
|
43
|
-
def goals_adaptation_phase(self, dynamic_goals:
|
44
|
-
|
61
|
+
def goals_adaptation_phase(self, dynamic_goals: list[str], dynamic_train_configs):
|
62
|
+
"""
|
63
|
+
Perform the goals adaptation phase.
|
64
|
+
|
65
|
+
Args:
|
66
|
+
dynamic_goals (List[str]): The list of dynamic goals.
|
67
|
+
dynamic_train_configs: The dynamic training configurations.
|
45
68
|
|
46
|
-
|
69
|
+
Returns:
|
70
|
+
None
|
71
|
+
"""
|
72
|
+
|
73
|
+
def domain_learning_phase(self, base_goals: list[str], train_configs: list):
|
74
|
+
"""
|
75
|
+
Perform the domain learning phase.
|
76
|
+
|
77
|
+
Args:
|
78
|
+
base_goals (List[str]): List of base goals.
|
79
|
+
train_configs (List): List of training configurations.
|
80
|
+
|
81
|
+
Returns:
|
82
|
+
None
|
83
|
+
"""
|
47
84
|
super().domain_learning_phase(base_goals, train_configs)
|
48
85
|
|
49
86
|
|
50
87
|
class GaAdaptingRecognizer(Recognizer):
|
88
|
+
"""
|
89
|
+
A recognizer that doesn't require more training given a set of new goals, hence it doesn't receive train configs in the goal adaptation phase.
|
90
|
+
"""
|
91
|
+
|
51
92
|
def __init__(self, *args, **kwargs):
|
52
93
|
super().__init__(*args, **kwargs)
|
53
94
|
|
54
95
|
@abstractmethod
|
55
|
-
def goals_adaptation_phase(self, dynamic_goals:
|
56
|
-
|
96
|
+
def goals_adaptation_phase(self, dynamic_goals: list[str]):
|
97
|
+
"""
|
98
|
+
Perform the goals adaptation phase.
|
99
|
+
|
100
|
+
Args:
|
101
|
+
dynamic_goals (List[str]): A list of dynamic goals to be adapted.
|
102
|
+
|
103
|
+
Returns:
|
104
|
+
None
|
105
|
+
"""
|
@@ -0,0 +1,58 @@
|
|
1
|
+
import numpy as np
|
2
|
+
from stable_baselines3 import PPO
|
3
|
+
|
4
|
+
from gr_libs import Draco
|
5
|
+
from gr_libs.environment._utils.utils import domain_to_env_property
|
6
|
+
from gr_libs.environment.environment import PANDA
|
7
|
+
from gr_libs.metrics import mean_wasserstein_distance
|
8
|
+
from gr_libs.metrics.metrics import stochastic_amplified_selection
|
9
|
+
from gr_libs.ml.neural.deep_rl_learner import DeepRLAgent
|
10
|
+
from gr_libs.ml.utils.format import random_subset_with_order
|
11
|
+
|
12
|
+
|
13
|
+
def run_draco_panda_tutorial():
|
14
|
+
recognizer = Draco(
|
15
|
+
domain_name=PANDA,
|
16
|
+
env_name="PandaMyReachDense",
|
17
|
+
evaluation_function=mean_wasserstein_distance, # or mean_p_value
|
18
|
+
)
|
19
|
+
|
20
|
+
recognizer.goals_adaptation_phase(
|
21
|
+
dynamic_goals=[
|
22
|
+
np.array([[-0.1, -0.1, 0.1]]),
|
23
|
+
np.array([[-0.1, 0.1, 0.1]]),
|
24
|
+
np.array([[0.2, 0.2, 0.1]]),
|
25
|
+
],
|
26
|
+
dynamic_train_configs=[(PPO, 200000), (PPO, 200000), (PPO, 200000)],
|
27
|
+
)
|
28
|
+
# TD3 is different from recognizer and expert algorithms, which are SAC #
|
29
|
+
property_type = domain_to_env_property(PANDA)
|
30
|
+
env_property = property_type("PandaMyReachDense")
|
31
|
+
problem_name = env_property.goal_to_problem_str(np.array([[-0.1, -0.1, 0.1]]))
|
32
|
+
actor = DeepRLAgent(
|
33
|
+
domain_name=PANDA,
|
34
|
+
problem_name=problem_name,
|
35
|
+
env_prop=env_property,
|
36
|
+
algorithm=PPO,
|
37
|
+
num_timesteps=400000,
|
38
|
+
)
|
39
|
+
actor.learn()
|
40
|
+
# sample is generated stochastically to simulate suboptimal behavior, noise is added to the actions values #
|
41
|
+
full_sequence = actor.generate_observation(
|
42
|
+
action_selection_method=stochastic_amplified_selection,
|
43
|
+
random_optimalism=True, # the noise that's added to the actions
|
44
|
+
with_dict=True,
|
45
|
+
)
|
46
|
+
partial_sequence = random_subset_with_order(
|
47
|
+
full_sequence, (int)(0.5 * len(full_sequence)), is_consecutive=False
|
48
|
+
)
|
49
|
+
closest_goal = recognizer.inference_phase(
|
50
|
+
partial_sequence, np.array([[-0.1, -0.1, 0.1]]), 0.5
|
51
|
+
)
|
52
|
+
print(
|
53
|
+
f"closest_goal returned by DRACO: {closest_goal}\nactual goal actor aimed towards: [-0.1, -0.1, 0.1]"
|
54
|
+
)
|
55
|
+
|
56
|
+
|
57
|
+
if __name__ == "__main__":
|
58
|
+
run_draco_panda_tutorial()
|
@@ -0,0 +1,56 @@
|
|
1
|
+
from stable_baselines3 import SAC, TD3
|
2
|
+
|
3
|
+
from gr_libs import Draco
|
4
|
+
from gr_libs.environment._utils.utils import domain_to_env_property
|
5
|
+
from gr_libs.environment.environment import PARKING, ParkingProperty
|
6
|
+
from gr_libs.metrics import mean_wasserstein_distance
|
7
|
+
from gr_libs.metrics.metrics import stochastic_amplified_selection
|
8
|
+
from gr_libs.ml.neural.deep_rl_learner import DeepRLAgent
|
9
|
+
from gr_libs.ml.utils.format import random_subset_with_order
|
10
|
+
|
11
|
+
|
12
|
+
def run_draco_parking_tutorial():
|
13
|
+
recognizer = Draco(
|
14
|
+
domain_name=PARKING,
|
15
|
+
env_name="Parking-S-14-PC-",
|
16
|
+
evaluation_function=mean_wasserstein_distance, # or mean_p_value
|
17
|
+
)
|
18
|
+
|
19
|
+
recognizer.goals_adaptation_phase(
|
20
|
+
dynamic_goals=["1", "11", "21"],
|
21
|
+
dynamic_train_configs=[(SAC, 200000), (SAC, 200000), (SAC, 200000)],
|
22
|
+
)
|
23
|
+
|
24
|
+
property_type = domain_to_env_property(PARKING)
|
25
|
+
env_property = property_type("Parking-S-14-PC-")
|
26
|
+
# TD3 is different from recognizer and expert algorithms, which are SAC #
|
27
|
+
actor = DeepRLAgent(
|
28
|
+
domain_name="parking",
|
29
|
+
problem_name="Parking-S-14-PC--GI-11-v0",
|
30
|
+
env_prop=env_property,
|
31
|
+
algorithm=TD3,
|
32
|
+
num_timesteps=400000,
|
33
|
+
)
|
34
|
+
actor.learn()
|
35
|
+
|
36
|
+
full_sequence = actor.generate_observation(
|
37
|
+
action_selection_method=stochastic_amplified_selection,
|
38
|
+
random_optimalism=True, # the noise that's added to the actions
|
39
|
+
with_dict=True,
|
40
|
+
)
|
41
|
+
|
42
|
+
partial_sequence = random_subset_with_order(
|
43
|
+
full_sequence, (int)(0.5 * len(full_sequence)), is_consecutive=False
|
44
|
+
)
|
45
|
+
closest_goal = recognizer.inference_phase(
|
46
|
+
partial_sequence,
|
47
|
+
ParkingProperty("Parking-S-14-PC--GI-11-v0").str_to_goal(),
|
48
|
+
0.5,
|
49
|
+
)
|
50
|
+
print(
|
51
|
+
f"closest_goal returned by GCDRACO: {closest_goal}\nactual goal actor aimed towards: 11"
|
52
|
+
)
|
53
|
+
|
54
|
+
|
55
|
+
if __name__ == "__main__":
|
56
|
+
run_draco_parking_tutorial()
|
@@ -1,16 +1,12 @@
|
|
1
|
+
import numpy as np
|
1
2
|
from stable_baselines3 import PPO, SAC
|
2
|
-
|
3
|
-
stochastic_amplified_selection,
|
4
|
-
mean_p_value,
|
5
|
-
mean_wasserstein_distance,
|
6
|
-
)
|
3
|
+
|
7
4
|
from gr_libs import GCDraco
|
8
|
-
from gr_libs.environment.
|
9
|
-
import numpy as np
|
5
|
+
from gr_libs.environment._utils.utils import domain_to_env_property
|
10
6
|
from gr_libs.environment.environment import PANDA, PandaProperty
|
7
|
+
from gr_libs.metrics import mean_wasserstein_distance, stochastic_amplified_selection
|
11
8
|
from gr_libs.ml.neural.deep_rl_learner import DeepRLAgent
|
12
9
|
from gr_libs.ml.utils.format import random_subset_with_order
|
13
|
-
import gr_envs.panda_scripts
|
14
10
|
|
15
11
|
|
16
12
|
def run_gcdraco_panda_tutorial():
|
@@ -21,8 +17,12 @@ def run_gcdraco_panda_tutorial():
|
|
21
17
|
)
|
22
18
|
|
23
19
|
recognizer.domain_learning_phase(
|
24
|
-
|
25
|
-
|
20
|
+
{
|
21
|
+
"gc": {
|
22
|
+
"goals": [np.array([PandaProperty.sample_goal()]) for _ in range(30)],
|
23
|
+
"train_configs": [(SAC, 800000)],
|
24
|
+
}
|
25
|
+
}
|
26
26
|
)
|
27
27
|
|
28
28
|
recognizer.goals_adaptation_phase(
|
@@ -30,7 +30,7 @@ def run_gcdraco_panda_tutorial():
|
|
30
30
|
np.array([[-0.1, -0.1, 0.1]]),
|
31
31
|
np.array([[-0.1, 0.1, 0.1]]),
|
32
32
|
np.array([[0.2, 0.2, 0.1]]),
|
33
|
-
]
|
33
|
+
],
|
34
34
|
)
|
35
35
|
|
36
36
|
# TD3 is different from recognizer and expert algorithms, which are SAC #
|
@@ -1,15 +1,11 @@
|
|
1
1
|
from stable_baselines3 import PPO, TD3
|
2
|
-
|
3
|
-
stochastic_amplified_selection,
|
4
|
-
mean_p_value,
|
5
|
-
mean_wasserstein_distance,
|
6
|
-
)
|
2
|
+
|
7
3
|
from gr_libs import GCDraco
|
8
|
-
from gr_libs.environment.
|
4
|
+
from gr_libs.environment._utils.utils import domain_to_env_property
|
9
5
|
from gr_libs.environment.environment import PARKING, ParkingProperty
|
6
|
+
from gr_libs.metrics import mean_wasserstein_distance, stochastic_amplified_selection
|
10
7
|
from gr_libs.ml.neural.deep_rl_learner import DeepRLAgent
|
11
8
|
from gr_libs.ml.utils.format import random_subset_with_order
|
12
|
-
import gr_envs
|
13
9
|
|
14
10
|
|
15
11
|
def run_gcdraco_parking_tutorial():
|
@@ -19,7 +15,9 @@ def run_gcdraco_parking_tutorial():
|
|
19
15
|
evaluation_function=mean_wasserstein_distance, # or mean_p_value
|
20
16
|
)
|
21
17
|
|
22
|
-
recognizer.domain_learning_phase(
|
18
|
+
recognizer.domain_learning_phase(
|
19
|
+
{"gc": {"goals": [i for i in range(1, 21)], "train_configs": [(PPO, 200000)]}}
|
20
|
+
)
|
23
21
|
recognizer.goals_adaptation_phase(
|
24
22
|
dynamic_goals=["1", "11", "21"]
|
25
23
|
# no need for expert sequence generation since GCRL is used
|
@@ -1,9 +1,9 @@
|
|
1
|
+
from gr_libs import ExpertBasedGraml
|
2
|
+
from gr_libs.environment._utils.utils import domain_to_env_property
|
1
3
|
from gr_libs.environment.environment import MINIGRID, QLEARNING
|
2
|
-
from gr_libs.environment.utils.utils import domain_to_env_property
|
3
4
|
from gr_libs.metrics.metrics import stochastic_amplified_selection
|
4
5
|
from gr_libs.ml.tabular.tabular_q_learner import TabularQLearner
|
5
6
|
from gr_libs.ml.utils.format import random_subset_with_order
|
6
|
-
from gr_libs import ExpertBasedGraml
|
7
7
|
|
8
8
|
|
9
9
|
def run_graml_minigrid_tutorial():
|
@@ -12,18 +12,22 @@ def run_graml_minigrid_tutorial():
|
|
12
12
|
)
|
13
13
|
|
14
14
|
recognizer.domain_learning_phase(
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
15
|
+
{
|
16
|
+
"bg": {
|
17
|
+
"goals": [
|
18
|
+
(11, 1),
|
19
|
+
(11, 11),
|
20
|
+
(1, 11),
|
21
|
+
(7, 11),
|
22
|
+
(8, 1),
|
23
|
+
(10, 6),
|
24
|
+
(6, 9),
|
25
|
+
(11, 3),
|
26
|
+
(11, 5),
|
27
|
+
],
|
28
|
+
"train_configs": [(QLEARNING, 100000) for _ in range(9)],
|
29
|
+
}
|
30
|
+
}
|
27
31
|
)
|
28
32
|
|
29
33
|
recognizer.goals_adaptation_phase(
|
@@ -1,17 +1,12 @@
|
|
1
1
|
import numpy as np
|
2
2
|
from stable_baselines3 import PPO, SAC
|
3
|
-
|
4
|
-
from gr_libs
|
5
|
-
|
6
|
-
|
7
|
-
GCEnvProperty,
|
8
|
-
PandaProperty,
|
9
|
-
)
|
10
|
-
from gr_libs.environment.utils.utils import domain_to_env_property
|
3
|
+
|
4
|
+
from gr_libs import GCGraml
|
5
|
+
from gr_libs.environment._utils.utils import domain_to_env_property
|
6
|
+
from gr_libs.environment.environment import PANDA, PandaProperty
|
11
7
|
from gr_libs.metrics.metrics import stochastic_amplified_selection
|
12
|
-
from gr_libs.ml.neural.deep_rl_learner import DeepRLAgent
|
8
|
+
from gr_libs.ml.neural.deep_rl_learner import DeepRLAgent
|
13
9
|
from gr_libs.ml.utils.format import random_subset_with_order
|
14
|
-
from gr_libs import GCGraml
|
15
10
|
|
16
11
|
|
17
12
|
def run_graml_panda_tutorial():
|
@@ -19,8 +14,12 @@ def run_graml_panda_tutorial():
|
|
19
14
|
domain_name=PANDA, env_name="PandaMyReachDense"
|
20
15
|
)
|
21
16
|
recognizer.domain_learning_phase(
|
22
|
-
|
23
|
-
|
17
|
+
{
|
18
|
+
"gc": {
|
19
|
+
"goals": [np.array([PandaProperty.sample_goal()]) for _ in range(30)],
|
20
|
+
"train_configs": [(SAC, 800000)],
|
21
|
+
}
|
22
|
+
}
|
24
23
|
)
|
25
24
|
recognizer.goals_adaptation_phase(
|
26
25
|
dynamic_goals=[
|
@@ -1,21 +1,19 @@
|
|
1
|
-
from stable_baselines3 import PPO,
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
GCEnvProperty,
|
6
|
-
ParkingProperty,
|
7
|
-
)
|
8
|
-
from gr_libs.environment.utils.utils import domain_to_env_property
|
1
|
+
from stable_baselines3 import PPO, TD3
|
2
|
+
|
3
|
+
from gr_libs.environment._utils.utils import domain_to_env_property
|
4
|
+
from gr_libs.environment.environment import PARKING, ParkingProperty
|
9
5
|
from gr_libs.metrics.metrics import stochastic_amplified_selection
|
10
6
|
from gr_libs.ml.neural.deep_rl_learner import DeepRLAgent
|
11
7
|
from gr_libs.ml.utils.format import random_subset_with_order
|
12
|
-
from gr_libs.recognizer.graml.graml_recognizer import
|
8
|
+
from gr_libs.recognizer.graml.graml_recognizer import GCGraml
|
13
9
|
|
14
10
|
|
15
11
|
def run_graml_parking_tutorial():
|
16
12
|
recognizer = GCGraml(domain_name=PARKING, env_name="Parking-S-14-PC-")
|
17
13
|
|
18
|
-
recognizer.domain_learning_phase(
|
14
|
+
recognizer.domain_learning_phase(
|
15
|
+
{"gc": {"goals": [i for i in range(1, 21)], "train_configs": [(PPO, 200000)]}}
|
16
|
+
)
|
19
17
|
recognizer.goals_adaptation_phase(
|
20
18
|
dynamic_goals=["1", "11", "21"]
|
21
19
|
# no need for expert sequence generation since GCRL is used
|
@@ -1,6 +1,7 @@
|
|
1
1
|
from stable_baselines3 import SAC, TD3
|
2
|
+
|
3
|
+
from gr_libs.environment._utils.utils import domain_to_env_property
|
2
4
|
from gr_libs.environment.environment import POINT_MAZE, PointMazeProperty
|
3
|
-
from gr_libs.environment.utils.utils import domain_to_env_property
|
4
5
|
from gr_libs.metrics.metrics import stochastic_amplified_selection
|
5
6
|
from gr_libs.ml.neural.deep_rl_learner import DeepRLAgent
|
6
7
|
from gr_libs.ml.utils.format import random_subset_with_order
|
@@ -13,8 +14,21 @@ def run_graml_point_maze_tutorial():
|
|
13
14
|
)
|
14
15
|
|
15
16
|
recognizer.domain_learning_phase(
|
16
|
-
|
17
|
-
|
17
|
+
{
|
18
|
+
"bg": {
|
19
|
+
"goals": [
|
20
|
+
(9, 1),
|
21
|
+
(9, 9),
|
22
|
+
(1, 9),
|
23
|
+
(3, 3),
|
24
|
+
(3, 4),
|
25
|
+
(8, 2),
|
26
|
+
(3, 7),
|
27
|
+
(2, 8),
|
28
|
+
],
|
29
|
+
"train_configs": [(SAC, 200000) for _ in range(8)],
|
30
|
+
}
|
31
|
+
}
|
18
32
|
)
|
19
33
|
|
20
34
|
recognizer.goals_adaptation_phase(
|
@@ -1,9 +1,9 @@
|
|
1
|
+
from gr_libs import Graql
|
2
|
+
from gr_libs.environment._utils.utils import domain_to_env_property
|
1
3
|
from gr_libs.environment.environment import MINIGRID, QLEARNING
|
2
|
-
from gr_libs.environment.utils.utils import domain_to_env_property
|
3
4
|
from gr_libs.metrics.metrics import stochastic_amplified_selection
|
4
5
|
from gr_libs.ml.tabular.tabular_q_learner import TabularQLearner
|
5
6
|
from gr_libs.ml.utils.format import random_subset_with_order
|
6
|
-
from gr_libs import Graql
|
7
7
|
|
8
8
|
|
9
9
|
def run_graql_minigrid_tutorial():
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: gr_libs
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.2.5
|
4
4
|
Summary: Package with goal recognition frameworks baselines
|
5
5
|
Author: Ben Nageris
|
6
6
|
Author-email: Matan Shamir <matan.shamir@live.biu.ac.il>, Osher Elhadad <osher.elhadad@live.biu.ac.il>
|
@@ -106,6 +106,28 @@ If you prefer using Conda, follow these steps:
|
|
106
106
|
|
107
107
|
For any issues or troubleshooting, please refer to the repository's issue tracker.
|
108
108
|
|
109
|
+
## Supported Algorithms
|
110
|
+
|
111
|
+
Successors of algorithms that don't differ in their specifics are added in parentheses after the algorithm name. For example, since GC-DRACO and DRACO share the same column values, they're written on one line as DRACO (GC).
|
112
|
+
|
113
|
+
| **Algorithm** | **Supervised** | **Reinforcement Learning** | **Discrete States** | **Continuous States** | **Discrete Actions** | **Continuous Actions** | **Model-Based** | **Model-Free** | **Action-Only** | **Supported Environments** |
|
114
|
+
|---------------------|----------------|---------------------------|---------------------|----------------------|----------------------|-----------------------|------------------|----------------|----------------|--------------------------------------------|
|
115
|
+
| Graql | ❌ | ✅ | ✅ | ❌ | ✅ | ❌ | ❌ | ✅ | ❌ | Minigrid |
|
116
|
+
| Draco | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ❌ | PointMaze, Panda Reach, Parking |
|
117
|
+
| GCDraco | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ❌ | Panda Reach, Parking |
|
118
|
+
| ExpertBasedGraml | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | Panda Reach, Parking |
|
119
|
+
| BGGraml | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | Minigrid, PointMaze |
|
120
|
+
| GCGraml | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | Panda Reach, Parking |
|
121
|
+
|
122
|
+
## Supported Domains
|
123
|
+
|
124
|
+
| **Domain** | **Action Space** | **State Space** |
|
125
|
+
|------------|----------------|----------------|
|
126
|
+
| Minigrid | Discrete | Discrete |
|
127
|
+
| PointMaze | Continuous | Continuous |
|
128
|
+
| Parking | Continuous | Continuous |
|
129
|
+
| Panda | Continuous | Continuous |
|
130
|
+
|
109
131
|
## Usage Guide
|
110
132
|
|
111
133
|
After installing GRLib, you will have access to custom Gym environments, allowing you to set up and execute an Online Dynamic Goal Recognition (ODGR) scenario with the algorithm of your choice.
|
@@ -116,9 +138,10 @@ Tutorials demonstrating basic ODGR scenarios is available in the sub-package `tu
|
|
116
138
|
gr_libs also includes a library of trained agents for the various supported environments within the package.
|
117
139
|
To get the dataset of trained agents, you can run:
|
118
140
|
```sh
|
141
|
+
pip install gdown
|
119
142
|
python download_dataset.py
|
120
143
|
```
|
121
|
-
|
144
|
+
Alternatively, you can visit the google-drive links where download_dataset.py points to and manually download the zipped folders, and unzip them into the project directory.
|
122
145
|
An alternative is to use our docker image, which includes the dataset in it.
|
123
146
|
You can:
|
124
147
|
1. pull the image:
|
@@ -191,42 +214,85 @@ docker run -it ghcr.io/MatanShamir1/gr_test_base:latest bash
|
|
191
214
|
|
192
215
|
The `consts.py` file contains predefined ODGR problem configurations. You can use existing configurations or define new ones.
|
193
216
|
|
194
|
-
To execute
|
217
|
+
To execute an ODGR problem using the configuration file, you specify a recognizer, a domain, a gym environment within that domain and the task:
|
195
218
|
```sh
|
196
|
-
python odgr_executor.py --recognizer
|
219
|
+
python odgr_executor.py --recognizer ExpertBasedGraml --domain minigrid --task L1 --env_name MiniGrid-SimpleCrossingS13N4
|
197
220
|
```
|
198
221
|
|
199
|
-
|
222
|
+
If you also add the flag:
|
223
|
+
```sh
|
224
|
+
--collect_stats
|
225
|
+
```
|
226
|
+
to the cmd, 3 kinds of outputs will be generated from the ODGR problem's execution:
|
227
|
+
a. Into:
|
228
|
+
```sh
|
229
|
+
outputs\\minigrid\MiniGrid-SimpleCrossingS13N4\MiniGrid-SimpleCrossingS13N4\L1\experiment_results
|
230
|
+
```
|
231
|
+
a .pkl and a .txt summary in a dictionary format will be generated, including the summary of all ODGR executions, including runtime and overall accuracies for all lengths and types of input sequences.
|
200
232
|
|
201
|
-
|
233
|
+
b. Into:
|
234
|
+
```sh
|
235
|
+
outputs\ExpertBasedGraml\minigrid\MiniGrid-SimpleCrossingS13N4\policy_sequences\MiniGrid-SimpleCrossingS13N4-DynamicGoal-1x11-v0_inference_seq/plan_image.png
|
236
|
+
```
|
237
|
+
a visulzation of the sequence the agent generated will be dumped, either in a png or an mp4 format, depending on the domain, for debugability.
|
202
238
|
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
239
|
+
c. Into:
|
240
|
+
either:
|
241
|
+
```sh
|
242
|
+
outputs\ExpertBasedGraml\minigrid\MiniGrid-SimpleCrossingS13N4\goal_embeddings
|
243
|
+
```
|
244
|
+
In Graml algorithms, or:
|
245
|
+
```sh
|
246
|
+
outputs\Graql\minigrid\MiniGrid-SimpleCrossingS13N4\confidence
|
247
|
+
```
|
248
|
+
In GRAsRL algorithms,
|
249
|
+
pickled results from which confidence of the results can be obtained, for offline analysis.
|
208
250
|
|
209
|
-
|
251
|
+
For GRAsRL outputs, for every possible goal, the likelihood of it being the true goal from the input sequence, based on the policy distance metric.
|
210
252
|
|
211
|
-
|
212
|
-
|------------|----------------|----------------|
|
213
|
-
| Minigrid | Discrete | Discrete |
|
214
|
-
| PointMaze | Continuous | Continuous |
|
215
|
-
| Parking | Continuous | Continuous |
|
216
|
-
| Panda | Continuous | Continuous |
|
253
|
+
For GRAML outputs, the embeddings of the sequences are pickled for every goal-directed sequence. Offline, since, since in the embdding space of GRAML's metric model- sequences towards the same sequences are close and vice versa, one could reproduce the most likely goal by measuring the elementwise vector distance of the embeddings, and retrieve a confidence of it.
|
217
254
|
|
218
255
|
## Running Experiments
|
219
256
|
|
220
|
-
|
257
|
+
In light of the previous section, the user should already know how to scale the experiments using odgr_executor, and they should also understand how to use the 3 types of outputs for offline analysis of the algorithms.
|
258
|
+
gr_libs also provides another scaling method to run odgr_executor on multiple domains and environments, for many ODGR problems, as well as python scripts for analysis of these results, to create plots and statistics over the executions.
|
221
259
|
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
260
|
+
### Scaling odgr_executor runs
|
261
|
+
A part of the contribution of this package is standardizing the evaluations of MDP-based GR frameworks.
|
262
|
+
consts.py provides a set of ODGR problems on which the framework can be evaluated.
|
263
|
+
The 'evaluations' sub-package provides scripts to analyze the results of the all_experiments.py execution, done over the ODGR the problems defined at consts.py.
|
226
264
|
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
265
|
+
#### Running all_experiments.py
|
266
|
+
|
267
|
+
You can now run `all_experiments.py` with your desired combination of domains, environments, tasks, and recognizers directly from the command line, without editing the script:
|
268
|
+
|
269
|
+
```sh
|
270
|
+
python gr_libs/all_experiments.py \
|
271
|
+
--domains minigrid parking \
|
272
|
+
--envs MiniGrid-SimpleCrossingS13N4 Parking-S-14-PC- \
|
273
|
+
--tasks L1 L2 L3 L4 L5 \
|
274
|
+
--recognizers ExpertBasedGraml Graql \
|
275
|
+
--n 5
|
276
|
+
```
|
277
|
+
|
278
|
+
- `--domains`: List of domains to run experiments on.
|
279
|
+
- `--envs`: List of environments (must be in the same order as domains).
|
280
|
+
- `--tasks`: List of tasks (applied to all domain/env pairs).
|
281
|
+
- `--recognizers`: List of recognizers/algorithms to evaluate.
|
282
|
+
- `--n`: Number of times to execute each task (default: 5).
|
283
|
+
|
284
|
+
This script uses multiprocessing to simultaneously execute many `odgr_executor.py` runs as child processes. It logs failures and successful executions for debugability.
|
285
|
+
|
286
|
+
After execution, summary files are generated in `outputs/summaries/` for further analysis and plotting.
|
287
|
+
|
288
|
+
### Using analysis scripts
|
289
|
+
The repository provides benchmark domains and scripts for analyzing experimental results. The `evaluation` directory contains tools for processing and visualizing the results from odgr_executor.py and all_experiments.py.
|
290
|
+
Please follow the README.md file in the 'evaluation' directory for more details.
|
291
|
+
|
292
|
+
## For Developers
|
293
|
+
Developers will need to work slightly different: instead of installing the packages, they need to clone the repos and either install them as editables or add their paths to PYTHONPATH so they will function as packages effectively.
|
294
|
+
Additional packages to install as a developer:
|
295
|
+
```sh
|
296
|
+
pip install pre-commit
|
297
|
+
pre-commit install
|
298
|
+
```
|