gr-libs 0.2.5__py3-none-any.whl → 0.2.6__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 +6 -1
- gr_libs/_version.py +2 -2
- gr_libs/environment/environment.py +104 -15
- gr_libs/ml/consts.py +1 -0
- gr_libs/ml/neural/deep_rl_learner.py +101 -14
- gr_libs/odgr_executor.py +7 -2
- gr_libs/recognizer/_utils/format.py +7 -1
- gr_libs/recognizer/gr_as_rl/gr_as_rl_recognizer.py +146 -1
- gr_libs/recognizer/graml/graml_recognizer.py +4 -4
- gr_libs/recognizer/recognizer.py +4 -4
- gr_libs/tutorials/gcaura_panda_tutorial.py +168 -0
- gr_libs/tutorials/gcaura_parking_tutorial.py +167 -0
- gr_libs/tutorials/gcaura_point_maze_tutorial.py +169 -0
- {gr_libs-0.2.5.dist-info → gr_libs-0.2.6.dist-info}/METADATA +16 -11
- {gr_libs-0.2.5.dist-info → gr_libs-0.2.6.dist-info}/RECORD +19 -14
- tests/test_gcaura.py +15 -0
- tests/test_odgr_executor_gcaura.py +14 -0
- {gr_libs-0.2.5.dist-info → gr_libs-0.2.6.dist-info}/WHEEL +0 -0
- {gr_libs-0.2.5.dist-info → gr_libs-0.2.6.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,168 @@
|
|
1
|
+
import numpy as np
|
2
|
+
from stable_baselines3 import PPO, SAC
|
3
|
+
|
4
|
+
from gr_libs import GCAura
|
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, 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_gcaura_panda_tutorial():
|
13
|
+
"""
|
14
|
+
Tutorial for GCAura on the Panda environment.
|
15
|
+
|
16
|
+
This tutorial demonstrates:
|
17
|
+
1. Training a goal-conditioned model on a registered goal subspace (center area)
|
18
|
+
2. Adapting to goals both inside and outside this subspace
|
19
|
+
3. Testing inference on multiple goal types
|
20
|
+
"""
|
21
|
+
print("Starting GCAura tutorial with Panda environment...")
|
22
|
+
|
23
|
+
print(f"Using training subspace with center-area goals")
|
24
|
+
|
25
|
+
# Initialize the recognizer with the center subspace environment
|
26
|
+
recognizer = GCAura(
|
27
|
+
domain_name=PANDA,
|
28
|
+
env_name="PandaMyReachDenseSubspaceCenterOnly-v3", # Use the subspace environment
|
29
|
+
evaluation_function=mean_wasserstein_distance,
|
30
|
+
finetune_timesteps=50000,
|
31
|
+
)
|
32
|
+
|
33
|
+
# Domain learning phase - train on the center goal subspace
|
34
|
+
print("\nStarting domain learning phase - training on registered goal subspace...")
|
35
|
+
recognizer.domain_learning_phase(
|
36
|
+
{
|
37
|
+
"gc": {
|
38
|
+
"train_configs": [(SAC, 500000)],
|
39
|
+
}
|
40
|
+
}
|
41
|
+
)
|
42
|
+
|
43
|
+
# Define adaptation goals - mix of in-subspace and out-of-subspace goals
|
44
|
+
# Use predefined goals from our environment registration
|
45
|
+
in_subspace_goal = np.array([[0.0, 0.0, 0.1]]) # Center goal (in subspace)
|
46
|
+
out_subspace_goal1 = np.array([[-0.3, -0.3, 0.1]]) # Far corner (out of subspace)
|
47
|
+
out_subspace_goal2 = np.array([[0.2, 0.2, 0.1]]) # Far corner (out of subspace)
|
48
|
+
|
49
|
+
print(
|
50
|
+
"\nStarting goal adaptation phase with both in-subspace and out-of-subspace goals..."
|
51
|
+
)
|
52
|
+
|
53
|
+
# Goals adaptation phase with mixed goals
|
54
|
+
recognizer.goals_adaptation_phase(
|
55
|
+
dynamic_goals=[
|
56
|
+
in_subspace_goal,
|
57
|
+
out_subspace_goal1,
|
58
|
+
out_subspace_goal2,
|
59
|
+
],
|
60
|
+
)
|
61
|
+
|
62
|
+
# Setup for testing
|
63
|
+
property_type = domain_to_env_property(PANDA)
|
64
|
+
env_property = property_type("PandaMyReachDense")
|
65
|
+
|
66
|
+
# Create test actor for in-subspace goal
|
67
|
+
print("\nCreating test actor for in-subspace goal...")
|
68
|
+
problem_name_in = env_property.goal_to_problem_str(in_subspace_goal)
|
69
|
+
actor_in = DeepRLAgent(
|
70
|
+
domain_name=PANDA,
|
71
|
+
problem_name=problem_name_in,
|
72
|
+
env_prop=env_property,
|
73
|
+
algorithm=PPO,
|
74
|
+
num_timesteps=250000,
|
75
|
+
)
|
76
|
+
actor_in.learn()
|
77
|
+
|
78
|
+
# Create test actor for out-of-subspace goal
|
79
|
+
print("\nCreating test actor for out-of-subspace goal...")
|
80
|
+
problem_name_out = env_property.goal_to_problem_str(out_subspace_goal1)
|
81
|
+
actor_out = DeepRLAgent(
|
82
|
+
domain_name=PANDA,
|
83
|
+
problem_name=problem_name_out,
|
84
|
+
env_prop=env_property,
|
85
|
+
algorithm=PPO,
|
86
|
+
num_timesteps=250000,
|
87
|
+
)
|
88
|
+
actor_out.learn()
|
89
|
+
|
90
|
+
# Test inference with in-subspace goal
|
91
|
+
print("\nTesting inference with in-subspace goal (should use base model)...")
|
92
|
+
full_sequence_in = actor_in.generate_observation(
|
93
|
+
action_selection_method=stochastic_amplified_selection,
|
94
|
+
random_optimalism=True,
|
95
|
+
with_dict=True,
|
96
|
+
)
|
97
|
+
partial_sequence_in = random_subset_with_order(
|
98
|
+
full_sequence_in, (int)(0.5 * len(full_sequence_in)), is_consecutive=False
|
99
|
+
)
|
100
|
+
recognized_goal_in = recognizer.inference_phase(
|
101
|
+
partial_sequence_in, in_subspace_goal, 0.5
|
102
|
+
)
|
103
|
+
print(f"Goal recognized for in-subspace sequence: {recognized_goal_in}")
|
104
|
+
print(f"Actual goal: {in_subspace_goal}")
|
105
|
+
|
106
|
+
assert str(recognized_goal_in) == str(
|
107
|
+
in_subspace_goal
|
108
|
+
), f"In-subspace goal recognition failed. Expected goal does not match recognized goal {recognized_goal_in}."
|
109
|
+
|
110
|
+
# Test inference with out-of-subspace goal
|
111
|
+
print(
|
112
|
+
"\nTesting inference with out-of-subspace goal (should use fine-tuned model)..."
|
113
|
+
)
|
114
|
+
full_sequence_out = actor_out.generate_observation(
|
115
|
+
action_selection_method=stochastic_amplified_selection,
|
116
|
+
random_optimalism=True,
|
117
|
+
with_dict=True,
|
118
|
+
)
|
119
|
+
partial_sequence_out = random_subset_with_order(
|
120
|
+
full_sequence_out, (int)(0.5 * len(full_sequence_out)), is_consecutive=False
|
121
|
+
)
|
122
|
+
recognized_goal_out = recognizer.inference_phase(
|
123
|
+
partial_sequence_out, out_subspace_goal1, 0.5
|
124
|
+
)
|
125
|
+
print(f"Goal recognized for out-of-subspace sequence: {recognized_goal_out}")
|
126
|
+
print(f"Actual goal: {out_subspace_goal1}")
|
127
|
+
|
128
|
+
assert str(recognized_goal_out) == str(
|
129
|
+
out_subspace_goal1
|
130
|
+
), f"Out-of-subspace goal recognition failed. Expected goal does not match recognized goal {recognized_goal_out}."
|
131
|
+
|
132
|
+
# Try another out-of-subspace goal
|
133
|
+
print("\nTesting inference with second out-of-subspace goal...")
|
134
|
+
problem_name_out2 = env_property.goal_to_problem_str(out_subspace_goal2)
|
135
|
+
actor_out2 = DeepRLAgent(
|
136
|
+
domain_name=PANDA,
|
137
|
+
problem_name=problem_name_out2,
|
138
|
+
env_prop=env_property,
|
139
|
+
algorithm=PPO,
|
140
|
+
num_timesteps=250000,
|
141
|
+
)
|
142
|
+
actor_out2.learn()
|
143
|
+
|
144
|
+
full_sequence_out2 = actor_out2.generate_observation(
|
145
|
+
action_selection_method=stochastic_amplified_selection,
|
146
|
+
random_optimalism=True,
|
147
|
+
with_dict=True,
|
148
|
+
)
|
149
|
+
partial_sequence_out2 = random_subset_with_order(
|
150
|
+
full_sequence_out2, (int)(0.5 * len(full_sequence_out2)), is_consecutive=False
|
151
|
+
)
|
152
|
+
recognized_goal_out2 = recognizer.inference_phase(
|
153
|
+
partial_sequence_out2, out_subspace_goal2, 0.5
|
154
|
+
)
|
155
|
+
print(
|
156
|
+
f"Goal recognized for second out-of-subspace sequence: {recognized_goal_out2}"
|
157
|
+
)
|
158
|
+
print(f"Actual goal: {out_subspace_goal2}")
|
159
|
+
|
160
|
+
assert str(recognized_goal_out2) == str(
|
161
|
+
out_subspace_goal2
|
162
|
+
), f"Out-of-subspace goal recognition failed. Expected goal does not match recognized goal {recognized_goal_out2}."
|
163
|
+
|
164
|
+
print("\nGCAura tutorial completed successfully!")
|
165
|
+
|
166
|
+
|
167
|
+
if __name__ == "__main__":
|
168
|
+
run_gcaura_panda_tutorial()
|
@@ -0,0 +1,167 @@
|
|
1
|
+
from stable_baselines3 import SAC, TD3
|
2
|
+
|
3
|
+
from gr_libs import GCAura
|
4
|
+
from gr_libs.environment._utils.utils import domain_to_env_property
|
5
|
+
from gr_libs.environment.environment import PARKING
|
6
|
+
from gr_libs.metrics import mean_wasserstein_distance, stochastic_amplified_selection
|
7
|
+
from gr_libs.ml.neural.deep_rl_learner import DeepRLAgent
|
8
|
+
from gr_libs.ml.utils.format import random_subset_with_order
|
9
|
+
|
10
|
+
|
11
|
+
def run_gcaura_parking_tutorial():
|
12
|
+
"""
|
13
|
+
Tutorial for GCAura on the Parking environment.
|
14
|
+
|
15
|
+
This tutorial demonstrates:
|
16
|
+
1. Training a goal-conditioned model on a goal subspace (parking spots 1-10)
|
17
|
+
2. Adapting to goals both inside and outside this subspace
|
18
|
+
3. Testing inference on multiple goal types
|
19
|
+
"""
|
20
|
+
print("Starting GCAura tutorial with Parking environment...")
|
21
|
+
|
22
|
+
print(f"Using training subspace with parking spots (1-10)")
|
23
|
+
|
24
|
+
# Initialize the recognizer with the standard parking environment
|
25
|
+
# We'll explicitly define the goal subspace in domain_learning_phase
|
26
|
+
recognizer = GCAura(
|
27
|
+
domain_name=PARKING,
|
28
|
+
env_name="Parking-S-14-PC--GI-8Y10Y13-v0",
|
29
|
+
evaluation_function=mean_wasserstein_distance,
|
30
|
+
finetune_timesteps=40000, # Fine-tuning timesteps for out-of-subspace goals
|
31
|
+
)
|
32
|
+
|
33
|
+
# Domain learning phase - train on the goal subspace
|
34
|
+
print("\nStarting domain learning phase - training on goal subspace...")
|
35
|
+
recognizer.domain_learning_phase(
|
36
|
+
{
|
37
|
+
"gc": {
|
38
|
+
"train_configs": [(SAC, 500000)],
|
39
|
+
}
|
40
|
+
}
|
41
|
+
)
|
42
|
+
|
43
|
+
# Define adaptation goals - mix of in-subspace and out-of-subspace goals
|
44
|
+
in_subspace_goal = "8" # Parking spot 8 (in subspace)
|
45
|
+
out_subspace_goal1 = "1" # Parking spot 1 (out of subspace)
|
46
|
+
out_subspace_goal2 = "18" # Parking spot 18 (out of subspace)
|
47
|
+
|
48
|
+
print(
|
49
|
+
"\nStarting goal adaptation phase with both in-subspace and out-of-subspace goals..."
|
50
|
+
)
|
51
|
+
|
52
|
+
# Goals adaptation phase with mixed goals
|
53
|
+
recognizer.goals_adaptation_phase(
|
54
|
+
dynamic_goals=[
|
55
|
+
in_subspace_goal, # In subspace - will use base model
|
56
|
+
out_subspace_goal1, # Out of subspace - will be fine-tuned
|
57
|
+
out_subspace_goal2, # Out of subspace - will be fine-tuned
|
58
|
+
],
|
59
|
+
)
|
60
|
+
|
61
|
+
# Setup for testing
|
62
|
+
property_type = domain_to_env_property(PARKING)
|
63
|
+
env_property = property_type("Parking-S-14-PC--v0")
|
64
|
+
|
65
|
+
# Create test actor for in-subspace goal
|
66
|
+
print("\nCreating test actor for in-subspace goal...")
|
67
|
+
problem_name_in = env_property.goal_to_problem_str(in_subspace_goal)
|
68
|
+
actor_in = DeepRLAgent(
|
69
|
+
domain_name=PARKING,
|
70
|
+
problem_name=problem_name_in,
|
71
|
+
env_prop=env_property,
|
72
|
+
algorithm=TD3,
|
73
|
+
num_timesteps=400000,
|
74
|
+
)
|
75
|
+
actor_in.learn()
|
76
|
+
|
77
|
+
# Create test actor for out-of-subspace goal
|
78
|
+
print("\nCreating test actor for out-of-subspace goal...")
|
79
|
+
problem_name_out = env_property.goal_to_problem_str(out_subspace_goal1)
|
80
|
+
actor_out = DeepRLAgent(
|
81
|
+
domain_name=PARKING,
|
82
|
+
problem_name=problem_name_out,
|
83
|
+
env_prop=env_property,
|
84
|
+
algorithm=TD3,
|
85
|
+
num_timesteps=400000,
|
86
|
+
)
|
87
|
+
actor_out.learn()
|
88
|
+
|
89
|
+
# Test inference with in-subspace goal
|
90
|
+
print("\nTesting inference with in-subspace goal (should use base model)...")
|
91
|
+
full_sequence_in = actor_in.generate_observation(
|
92
|
+
action_selection_method=stochastic_amplified_selection,
|
93
|
+
random_optimalism=True,
|
94
|
+
with_dict=True,
|
95
|
+
)
|
96
|
+
partial_sequence_in = random_subset_with_order(
|
97
|
+
full_sequence_in, (int)(0.5 * len(full_sequence_in)), is_consecutive=False
|
98
|
+
)
|
99
|
+
recognized_goal_in = recognizer.inference_phase(
|
100
|
+
partial_sequence_in, in_subspace_goal, 0.5
|
101
|
+
)
|
102
|
+
print(f"Goal recognized for in-subspace sequence: {recognized_goal_in}")
|
103
|
+
print(f"Actual goal: {in_subspace_goal}")
|
104
|
+
|
105
|
+
assert (
|
106
|
+
recognized_goal_in == in_subspace_goal
|
107
|
+
), f"In-subspace goal recognition failed, expected to recognize the parking spot {in_subspace_goal}."
|
108
|
+
|
109
|
+
# Test inference with out-of-subspace goal
|
110
|
+
print(
|
111
|
+
"\nTesting inference with out-of-subspace goal (should use fine-tuned model)..."
|
112
|
+
)
|
113
|
+
full_sequence_out = actor_out.generate_observation(
|
114
|
+
action_selection_method=stochastic_amplified_selection,
|
115
|
+
random_optimalism=True,
|
116
|
+
with_dict=True,
|
117
|
+
)
|
118
|
+
partial_sequence_out = random_subset_with_order(
|
119
|
+
full_sequence_out, (int)(0.5 * len(full_sequence_out)), is_consecutive=False
|
120
|
+
)
|
121
|
+
recognized_goal_out = recognizer.inference_phase(
|
122
|
+
partial_sequence_out, out_subspace_goal1, 0.5
|
123
|
+
)
|
124
|
+
print(f"Goal recognized for out-of-subspace sequence: {recognized_goal_out}")
|
125
|
+
print(f"Actual goal: {out_subspace_goal1}")
|
126
|
+
|
127
|
+
assert (
|
128
|
+
recognized_goal_out == out_subspace_goal1
|
129
|
+
), f"Out-of-subspace goal recognition failed, expected to recognize the parking spot {out_subspace_goal1}."
|
130
|
+
|
131
|
+
# Try another out-of-subspace goal
|
132
|
+
print("\nTesting inference with second out-of-subspace goal...")
|
133
|
+
problem_name_out2 = env_property.goal_to_problem_str(out_subspace_goal2)
|
134
|
+
actor_out2 = DeepRLAgent(
|
135
|
+
domain_name=PARKING,
|
136
|
+
problem_name=problem_name_out2,
|
137
|
+
env_prop=env_property,
|
138
|
+
algorithm=TD3,
|
139
|
+
num_timesteps=400000,
|
140
|
+
)
|
141
|
+
actor_out2.learn()
|
142
|
+
|
143
|
+
full_sequence_out2 = actor_out2.generate_observation(
|
144
|
+
action_selection_method=stochastic_amplified_selection,
|
145
|
+
random_optimalism=True,
|
146
|
+
with_dict=True,
|
147
|
+
)
|
148
|
+
partial_sequence_out2 = random_subset_with_order(
|
149
|
+
full_sequence_out2, (int)(0.5 * len(full_sequence_out2)), is_consecutive=False
|
150
|
+
)
|
151
|
+
recognized_goal_out2 = recognizer.inference_phase(
|
152
|
+
partial_sequence_out2, out_subspace_goal2, 0.5
|
153
|
+
)
|
154
|
+
print(
|
155
|
+
f"Goal recognized for second out-of-subspace sequence: {recognized_goal_out2}"
|
156
|
+
)
|
157
|
+
print(f"Actual goal: {out_subspace_goal2}")
|
158
|
+
|
159
|
+
assert (
|
160
|
+
recognized_goal_out2 == out_subspace_goal2
|
161
|
+
), f"Second out-of-subspace goal recognition failed, expected to recognize the parking spot {out_subspace_goal2}."
|
162
|
+
|
163
|
+
print("\nGCAura Parking tutorial completed successfully!")
|
164
|
+
|
165
|
+
|
166
|
+
if __name__ == "__main__":
|
167
|
+
run_gcaura_parking_tutorial()
|
@@ -0,0 +1,169 @@
|
|
1
|
+
from stable_baselines3 import SAC, PPO
|
2
|
+
|
3
|
+
from gr_libs import GCAura
|
4
|
+
from gr_libs.environment._utils.utils import domain_to_env_property
|
5
|
+
from gr_libs.environment.environment import POINT_MAZE
|
6
|
+
from gr_libs.metrics import mean_wasserstein_distance, stochastic_amplified_selection
|
7
|
+
from gr_libs.ml.neural.deep_rl_learner import DeepRLAgent
|
8
|
+
from gr_libs.ml.utils.format import random_subset_with_order
|
9
|
+
|
10
|
+
|
11
|
+
def run_gcaura_point_maze_tutorial():
|
12
|
+
"""
|
13
|
+
Tutorial for GCAura on the Point Maze environment with MultiGoals.
|
14
|
+
|
15
|
+
This tutorial demonstrates:
|
16
|
+
1. Training a goal-conditioned model on a goal subspace (center goal only)
|
17
|
+
2. Adapting to goals both inside and outside this subspace
|
18
|
+
3. Testing inference on all goals types
|
19
|
+
"""
|
20
|
+
print("Starting GCAura tutorial with Point Maze MultiGoals environment...")
|
21
|
+
|
22
|
+
# Use the registered multigoals environment with 3 goals: [(2, 2), (9, 9), (5, 5)]
|
23
|
+
# But define our goal subspace to include ONLY the center goal (5, 5)
|
24
|
+
# This lets us properly test the subspace functionality
|
25
|
+
|
26
|
+
# Initialize the recognizer with the multigoals empty maze environment
|
27
|
+
recognizer = GCAura(
|
28
|
+
domain_name=POINT_MAZE,
|
29
|
+
env_name="PointMaze-EmptyEnvDense-11x11-MultiGoals-2x2-9x9-5x5",
|
30
|
+
evaluation_function=mean_wasserstein_distance,
|
31
|
+
finetune_timesteps=70000, # Fine-tuning for out-of-subspace goals
|
32
|
+
)
|
33
|
+
|
34
|
+
# Domain learning phase - train on the center goal subspace only
|
35
|
+
print("\nStarting domain learning phase - training on center goal subspace...")
|
36
|
+
recognizer.domain_learning_phase(
|
37
|
+
{
|
38
|
+
"gc": {
|
39
|
+
"train_configs": [(SAC, 700000)],
|
40
|
+
}
|
41
|
+
}
|
42
|
+
)
|
43
|
+
|
44
|
+
# Define adaptation goals - one in-subspace (center) and two out-of-subspace (corners)
|
45
|
+
# These all exist in the registered environment
|
46
|
+
in_subspace_goal = (5, 5) # Center goal (in subspace)
|
47
|
+
out_subspace_goal1 = (9, 1) # Bottom left corner (out of subspace)
|
48
|
+
out_subspace_goal2 = (1, 9) # Top right corner (out of subspace)
|
49
|
+
|
50
|
+
print(
|
51
|
+
"\nStarting goal adaptation phase with both in-subspace and out-of-subspace goals..."
|
52
|
+
)
|
53
|
+
|
54
|
+
# Goals adaptation phase with mixed goals
|
55
|
+
recognizer.goals_adaptation_phase(
|
56
|
+
dynamic_goals=[
|
57
|
+
in_subspace_goal, # In subspace - will use base model
|
58
|
+
out_subspace_goal1, # Out of subspace - will be fine-tuned
|
59
|
+
out_subspace_goal2, # Out of subspace - will be fine-tuned
|
60
|
+
],
|
61
|
+
)
|
62
|
+
|
63
|
+
# Setup for testing
|
64
|
+
property_type = domain_to_env_property(POINT_MAZE)
|
65
|
+
env_property = property_type("PointMaze-EmptyEnvDense-11x11")
|
66
|
+
|
67
|
+
# Create test actor for in-subspace goal (center)
|
68
|
+
print("\nCreating test actor for in-subspace goal (center)...")
|
69
|
+
problem_name_in = env_property.goal_to_problem_str(in_subspace_goal)
|
70
|
+
actor_in = DeepRLAgent(
|
71
|
+
domain_name=POINT_MAZE,
|
72
|
+
problem_name=problem_name_in,
|
73
|
+
env_prop=env_property,
|
74
|
+
algorithm=PPO,
|
75
|
+
num_timesteps=700000,
|
76
|
+
)
|
77
|
+
actor_in.learn()
|
78
|
+
|
79
|
+
# Create test actor for out-of-subspace goal (bottom left corner)
|
80
|
+
print("\nCreating test actor for out-of-subspace goal (bottom left corner)...")
|
81
|
+
problem_name_out = env_property.goal_to_problem_str(out_subspace_goal1)
|
82
|
+
actor_out = DeepRLAgent(
|
83
|
+
domain_name=POINT_MAZE,
|
84
|
+
problem_name=problem_name_out,
|
85
|
+
env_prop=env_property,
|
86
|
+
algorithm=PPO,
|
87
|
+
num_timesteps=500000,
|
88
|
+
)
|
89
|
+
actor_out.learn()
|
90
|
+
|
91
|
+
# Test inference with in-subspace goal (center)
|
92
|
+
print("\nTesting inference with in-subspace goal (should use base model)...")
|
93
|
+
full_sequence_in = actor_in.generate_observation(
|
94
|
+
action_selection_method=stochastic_amplified_selection,
|
95
|
+
random_optimalism=True,
|
96
|
+
with_dict=True,
|
97
|
+
)
|
98
|
+
partial_sequence_in = random_subset_with_order(
|
99
|
+
full_sequence_in, (int)(0.5 * len(full_sequence_in)), is_consecutive=False
|
100
|
+
)
|
101
|
+
recognized_goal_in = recognizer.inference_phase(
|
102
|
+
partial_sequence_in, in_subspace_goal, 0.5
|
103
|
+
)
|
104
|
+
print(f"Goal recognized for in-subspace sequence: {recognized_goal_in}")
|
105
|
+
print(f"Actual goal: {in_subspace_goal}")
|
106
|
+
|
107
|
+
assert str(recognized_goal_in) == str(
|
108
|
+
in_subspace_goal
|
109
|
+
), "In-subspace goal recognition failed, expected to recognize the center goal."
|
110
|
+
|
111
|
+
# Test inference with out-of-subspace goal (bottom left corner)
|
112
|
+
print(
|
113
|
+
"\nTesting inference with out-of-subspace goal (should use fine-tuned model)..."
|
114
|
+
)
|
115
|
+
full_sequence_out = actor_out.generate_observation(
|
116
|
+
action_selection_method=stochastic_amplified_selection,
|
117
|
+
random_optimalism=True,
|
118
|
+
with_dict=True,
|
119
|
+
)
|
120
|
+
partial_sequence_out = random_subset_with_order(
|
121
|
+
full_sequence_out, (int)(0.5 * len(full_sequence_out)), is_consecutive=False
|
122
|
+
)
|
123
|
+
recognized_goal_out = recognizer.inference_phase(
|
124
|
+
partial_sequence_out, out_subspace_goal1, 0.5
|
125
|
+
)
|
126
|
+
print(f"Goal recognized for out-of-subspace sequence: {recognized_goal_out}")
|
127
|
+
print(f"Actual goal: {out_subspace_goal1}")
|
128
|
+
|
129
|
+
assert str(recognized_goal_out) == str(
|
130
|
+
out_subspace_goal1
|
131
|
+
), "Out-of-subspace goal recognition failed, expected to recognize the bottom left corner goal."
|
132
|
+
|
133
|
+
# Test with second out-of-subspace goal (top right corner)
|
134
|
+
print("\nTesting inference with second out-of-subspace goal (top right corner)...")
|
135
|
+
problem_name_out2 = env_property.goal_to_problem_str(out_subspace_goal2)
|
136
|
+
actor_out2 = DeepRLAgent(
|
137
|
+
domain_name=POINT_MAZE,
|
138
|
+
problem_name=problem_name_out2,
|
139
|
+
env_prop=env_property,
|
140
|
+
algorithm=PPO,
|
141
|
+
num_timesteps=500000,
|
142
|
+
)
|
143
|
+
actor_out2.learn()
|
144
|
+
|
145
|
+
full_sequence_out2 = actor_out2.generate_observation(
|
146
|
+
action_selection_method=stochastic_amplified_selection,
|
147
|
+
random_optimalism=True,
|
148
|
+
with_dict=True,
|
149
|
+
)
|
150
|
+
partial_sequence_out2 = random_subset_with_order(
|
151
|
+
full_sequence_out2, (int)(0.5 * len(full_sequence_out2)), is_consecutive=False
|
152
|
+
)
|
153
|
+
recognized_goal_out2 = recognizer.inference_phase(
|
154
|
+
partial_sequence_out2, out_subspace_goal2, 0.5
|
155
|
+
)
|
156
|
+
print(
|
157
|
+
f"Goal recognized for second out-of-subspace sequence: {recognized_goal_out2}"
|
158
|
+
)
|
159
|
+
print(f"Actual goal: {out_subspace_goal2}")
|
160
|
+
|
161
|
+
assert str(recognized_goal_out2) == str(
|
162
|
+
out_subspace_goal2
|
163
|
+
), "Second out-of-subspace goal recognition failed, expected to recognize the top right corner goal."
|
164
|
+
|
165
|
+
print("\nGCAura Point Maze tutorial completed successfully!")
|
166
|
+
|
167
|
+
|
168
|
+
if __name__ == "__main__":
|
169
|
+
run_gcaura_point_maze_tutorial()
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: gr_libs
|
3
|
-
Version: 0.2.
|
3
|
+
Version: 0.2.6
|
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>
|
@@ -108,16 +108,16 @@ For any issues or troubleshooting, please refer to the repository's issue tracke
|
|
108
108
|
|
109
109
|
## Supported Algorithms
|
110
110
|
|
111
|
-
|
111
|
+
| **Algorithm** | **Supervised** | **Reinforcement Learning** | **Discrete States** | **Continuous States** | **Discrete Actions** | **Continuous Actions** | **Model-Based** | **Model-Free** | **Action-Only** | **Goal Conditioned** | **Fine-Tuning** | **Supported Environments** |
|
112
|
+
|---------------------|----------------|---------------------------|---------------------|----------------------|----------------------|-----------------------|------------------|----------------|----------------|---------------------|-----------------|-------------------------------------------|
|
113
|
+
| Graql | ❌ | ✅ | ✅ | ❌ | ✅ | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | Minigrid |
|
114
|
+
| Draco | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ❌ | ❌ | ❌ | PointMaze, Panda Reach, Parking |
|
115
|
+
| GCDraco | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ❌ | ✅ | ❌ | Panda Reach, Parking |
|
116
|
+
| GCAura | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ❌ | ✅ | ✅ | PointMaze, Panda Reach, Parking |
|
117
|
+
| ExpertBasedGraml | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | ❌ | ❌ | Panda Reach, Parking |
|
118
|
+
| BGGraml | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | ❌ | ❌ | Minigrid, PointMaze |
|
119
|
+
| GCGraml | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ❌ | Panda Reach, Parking |
|
112
120
|
|
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
121
|
|
122
122
|
## Supported Domains
|
123
123
|
|
@@ -283,7 +283,12 @@ python gr_libs/all_experiments.py \
|
|
283
283
|
|
284
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
285
|
|
286
|
-
After execution
|
286
|
+
After execution summary files are generated in `outputs/summaries/` for further analysis and plotting.
|
287
|
+
|
288
|
+
another execution example:
|
289
|
+
```sh
|
290
|
+
python gr_libs/all_experiments.py --domains parking --envs Parking-S-14-PC- --tasks L1 L2 L3 L4 L5 --recognizers GCAura GCGraml GCDraco BGGraml Draco --n 5
|
291
|
+
```
|
287
292
|
|
288
293
|
### Using analysis scripts
|
289
294
|
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.
|
@@ -1,10 +1,10 @@
|
|
1
|
-
gr_libs/__init__.py,sha256=
|
2
|
-
gr_libs/_version.py,sha256=
|
1
|
+
gr_libs/__init__.py,sha256=3gXejmK_mOfmD9RmB2jMG1Xm7DUyCwAILB7h7sheYxQ,405
|
2
|
+
gr_libs/_version.py,sha256=nObnONsicQ3YX6SG5MVBxmIp5dmRacXDauSqZijWQbY,511
|
3
3
|
gr_libs/all_experiments.py,sha256=OTTMx5ddy7z3kJbElQcR5nwEtshPsoehNPwDuMzojcc,10006
|
4
|
-
gr_libs/odgr_executor.py,sha256=
|
4
|
+
gr_libs/odgr_executor.py,sha256=MKDK-8fNc4HHlwnZFTjyeS-UbYafdmVbe84gRNG7stI,10806
|
5
5
|
gr_libs/_evaluation/_generate_experiments_results.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
6
6
|
gr_libs/environment/__init__.py,sha256=xCCzTFDrj_ijdLoZ-PzGyyYDeU2aoW19X1da76_x9iM,1458
|
7
|
-
gr_libs/environment/environment.py,sha256=
|
7
|
+
gr_libs/environment/environment.py,sha256=neKNy0fkJK1i53LIh0JFP4tl0-4ntTM8F2wTkCvJtm4,19706
|
8
8
|
gr_libs/environment/_utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
9
9
|
gr_libs/environment/_utils/utils.py,sha256=dKuWoUpyuGSJL6qHQfvvJnFf4g-Rh1t2ykuRNrsIvP8,614
|
10
10
|
gr_libs/evaluation/__init__.py,sha256=trZ-4PyOhzEEK_TvQLfbnNFcqYuN6SdRjDkkAdW6MW8,78
|
@@ -13,11 +13,11 @@ gr_libs/metrics/__init__.py,sha256=dQo4cMqrOB2-VLDxTIGryCm14mUnmEXs4F8jqcgNsY4,1
|
|
13
13
|
gr_libs/metrics/metrics.py,sha256=tpjr4hKt5AGft5H2YxkbF0O8La5JZQaOmnkyjptD2M8,13430
|
14
14
|
gr_libs/ml/__init__.py,sha256=xX9InKnWhYm8e0Lhsnnm0H68yBPTNEfq756w95xv-98,83
|
15
15
|
gr_libs/ml/agent.py,sha256=ea1yRltKX0LSpRMnpAQLRKvvKoLMQz9MgMeWBPhQISw,2095
|
16
|
-
gr_libs/ml/consts.py,sha256=
|
16
|
+
gr_libs/ml/consts.py,sha256=TsuTuQZNRrZ5bFRaUkFOeYnzljHjtyFszQJpqg4xq7s,420
|
17
17
|
gr_libs/ml/base/__init__.py,sha256=f63VN3Lv4tQp3dAZjtT78PGV5XuOD8WlU4svy43LZrU,123
|
18
18
|
gr_libs/ml/base/rl_agent.py,sha256=Ewqu583gUkgRmeGWCJgkyDBKxTqQnN4qa2vxq0-ydoE,3843
|
19
19
|
gr_libs/ml/neural/__init__.py,sha256=vGdjx1KzlB9UxNRwkAeYBEoYdVtRdhj0M4mtWuzqvU8,55
|
20
|
-
gr_libs/ml/neural/deep_rl_learner.py,sha256=
|
20
|
+
gr_libs/ml/neural/deep_rl_learner.py,sha256=ND1D8b5Tc96ZpWc3yu-JjtP7662E2q4cKVLV9aFheD0,30141
|
21
21
|
gr_libs/ml/neural/utils/__init__.py,sha256=Av5wB2eSHR7spHqZFdgau_9EJV0FmijaYqXeyGMwktQ,69
|
22
22
|
gr_libs/ml/neural/utils/dictlist.py,sha256=ORFez_KmaCzraStF97hxdgCAAALP4Er8u3e9RcqlvhM,1030
|
23
23
|
gr_libs/ml/planner/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -41,16 +41,19 @@ gr_libs/ml/utils/storage.py,sha256=CgZHWcC3GovKe-U3Cvwz0s5qCbBrYHY6w_CV-LnTquc,3
|
|
41
41
|
gr_libs/problems/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
42
42
|
gr_libs/problems/consts.py,sha256=FQk2TaKAFHdZiISubGXeYleBaOXpk8ZC749NtP5RqWs,68520
|
43
43
|
gr_libs/recognizer/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
44
|
-
gr_libs/recognizer/recognizer.py,sha256=
|
44
|
+
gr_libs/recognizer/recognizer.py,sha256=IZ3KU5jopf5WhQZe_dQWYZp_fdMFvcabqoU3z6ZOFK8,3128
|
45
45
|
gr_libs/recognizer/_utils/__init__.py,sha256=MvXPRyr30W5C_n-Dul3aheE_9SWy2aIMGINKWj36mfM,42
|
46
|
-
gr_libs/recognizer/_utils/format.py,sha256=
|
46
|
+
gr_libs/recognizer/_utils/format.py,sha256=6m-csTBg8hBLrrKwRGFwS1uKGmulihsABH_BUl5TV80,567
|
47
47
|
gr_libs/recognizer/gr_as_rl/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
48
|
-
gr_libs/recognizer/gr_as_rl/gr_as_rl_recognizer.py,sha256=
|
48
|
+
gr_libs/recognizer/gr_as_rl/gr_as_rl_recognizer.py,sha256=efQtSECx73FMzIB1bpldN8CqBrlIrXf0ELvHeEMEImA,15664
|
49
49
|
gr_libs/recognizer/graml/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
50
50
|
gr_libs/recognizer/graml/_gr_dataset.py,sha256=JChqXOh7TP8yu-zQPCQ34ghw7iJFnAzd2FkeOyndvFk,10038
|
51
|
-
gr_libs/recognizer/graml/graml_recognizer.py,sha256=
|
51
|
+
gr_libs/recognizer/graml/graml_recognizer.py,sha256=BL2sydjRoFRx2wZBm0-IfkBvDfVy07JyOsKjodaIGGU,26340
|
52
52
|
gr_libs/tutorials/draco_panda_tutorial.py,sha256=9_scjcyMjkjw8l6g9E-GKOrFTxsIIndW_J1WKjE6-wo,2146
|
53
53
|
gr_libs/tutorials/draco_parking_tutorial.py,sha256=jjbNzSv5l4EvjydwslNYh51xHoIkNmcjPbi0YL6WAeA,1896
|
54
|
+
gr_libs/tutorials/gcaura_panda_tutorial.py,sha256=Z8RmzLLHboRzCfGWbM_Bhc_glJ4VIWCGMNky1_3i_VA,6189
|
55
|
+
gr_libs/tutorials/gcaura_parking_tutorial.py,sha256=OgSa6NvG0W0pm3h-lbN8v4YY1Br7WY3tIguGd9P4HWY,6221
|
56
|
+
gr_libs/tutorials/gcaura_point_maze_tutorial.py,sha256=Z39Tydx7VqXlB37YNhHOc9ge5Zjo0EQNQte_q6ZUXLE,6593
|
54
57
|
gr_libs/tutorials/gcdraco_panda_tutorial.py,sha256=HzGKqZR--rcTYj3RQMuQCzTVll2Q-Z_RQbmGpcZPovg,2301
|
55
58
|
gr_libs/tutorials/gcdraco_parking_tutorial.py,sha256=kd7xRsjGPCHohwhbJEK5XAsD3R9k8rcd0qz8IZIgjN4,2103
|
56
59
|
gr_libs/tutorials/graml_minigrid_tutorial.py,sha256=bEsi21-9-AiOw4-H98Fr3YaCrp8_uSXOiiGahaCO4mg,2356
|
@@ -59,14 +62,16 @@ gr_libs/tutorials/graml_parking_tutorial.py,sha256=vRvcbrbM8N7npt7W_0g-CbUhALkXV
|
|
59
62
|
gr_libs/tutorials/graml_point_maze_tutorial.py,sha256=KA28__CNKslxq3p6O5htjJFDKOXXbiA1bOX-oPJxjmI,2463
|
60
63
|
gr_libs/tutorials/graql_minigrid_tutorial.py,sha256=HT8kCFNbZXAraIau9wtgC_aW8xg-QNRZB2lcpGm3yWk,1941
|
61
64
|
tests/test_draco.py,sha256=oIeTDgn6pt3RfTC-RPX3Bw5cG4BThxRGH3z8en3TX0M,385
|
65
|
+
tests/test_gcaura.py,sha256=mPqBGnqPto4uFkoLj8OrKySvG0Ph-w5ucIlAQ4bw8Yw,466
|
62
66
|
tests/test_gcdraco.py,sha256=vV6rp7PkJJk_WpAfRekb197QiMHjXXApqrBiLG9RTwo,308
|
63
67
|
tests/test_graml.py,sha256=amSikMWrGS9BNVSXGNKc1n5tfRl-FfgCsyHYsJtduD4,608
|
64
68
|
tests/test_graql.py,sha256=KxVKx6rcSCbN-PjxR2DFoKcILRUmMDz0dTM5SvJZMXg,154
|
65
69
|
tests/test_odgr_executor_expertbasedgraml.py,sha256=UQh1pzaqAy9kRN1O--x1tQLGWkRXuYnz5ujB2H1XMas,558
|
70
|
+
tests/test_odgr_executor_gcaura.py,sha256=rggRtH-1xU67_m_mtHRwk_tX-hNFiWNdcyp3kzmOEXs,502
|
66
71
|
tests/test_odgr_executor_gcdraco.py,sha256=VUmnO33tuMVlNYz7Fh08VUW4jfUXhhUsJu7oPiLF2iU,506
|
67
72
|
tests/test_odgr_executor_gcgraml.py,sha256=MmyadmboVxFwfRigqe9jondZopqUjhbQ3gXjCbK4yAs,506
|
68
73
|
tests/test_odgr_executor_graql.py,sha256=06p_kPAUn2OQrL-nBik58C22UPbTDC4CwDaB7MUk61o,514
|
69
|
-
gr_libs-0.2.
|
70
|
-
gr_libs-0.2.
|
71
|
-
gr_libs-0.2.
|
72
|
-
gr_libs-0.2.
|
74
|
+
gr_libs-0.2.6.dist-info/METADATA,sha256=Le6ZmUIXTb7B8D9ohgOCo0YkiGeXvvioS_usH_Q_oDc,15032
|
75
|
+
gr_libs-0.2.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
76
|
+
gr_libs-0.2.6.dist-info/top_level.txt,sha256=Yzc_VSW3gzbVM7ZtlV4r6VXmfAC8WXqGVUgK1r6JcLs,14
|
77
|
+
gr_libs-0.2.6.dist-info/RECORD,,
|
tests/test_gcaura.py
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
from gr_libs.tutorials.gcaura_panda_tutorial import run_gcaura_panda_tutorial
|
2
|
+
from gr_libs.tutorials.gcaura_parking_tutorial import run_gcaura_parking_tutorial
|
3
|
+
from gr_libs.tutorials.gcaura_point_maze_tutorial import run_gcaura_point_maze_tutorial
|
4
|
+
|
5
|
+
|
6
|
+
def test_gcaura_panda_tutorial():
|
7
|
+
run_gcaura_panda_tutorial()
|
8
|
+
|
9
|
+
|
10
|
+
def test_gcaura_parking_tutorial():
|
11
|
+
run_gcaura_parking_tutorial()
|
12
|
+
|
13
|
+
|
14
|
+
def test_gcaura_point_maze_tutorial():
|
15
|
+
run_gcaura_point_maze_tutorial()
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import subprocess
|
2
|
+
import sys
|
3
|
+
|
4
|
+
def test_odgr_executor_gcaura_parking():
|
5
|
+
"""Test odgr_executor.py with GCAura on parking, L1, easiest env."""
|
6
|
+
result = subprocess.run([
|
7
|
+
sys.executable, "gr_libs/odgr_executor.py",
|
8
|
+
"--domain", "parking",
|
9
|
+
"--env_name", "Parking-S-14-PC-",
|
10
|
+
"--recognizer", "GCAura",
|
11
|
+
"--task", "L1",
|
12
|
+
"--collect_stats"
|
13
|
+
], capture_output=True, text=True)
|
14
|
+
assert result.returncode == 0, f"GCAura parking L1 failed: {result.stderr}"
|
File without changes
|
File without changes
|