gr-libs 0.1.6.post1__py3-none-any.whl → 0.1.8__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.
Files changed (64) hide show
  1. evaluation/analyze_results_cross_alg_cross_domain.py +236 -246
  2. evaluation/create_minigrid_map_image.py +10 -6
  3. evaluation/file_system.py +16 -5
  4. evaluation/generate_experiments_results.py +123 -74
  5. evaluation/generate_experiments_results_new_ver1.py +227 -243
  6. evaluation/generate_experiments_results_new_ver2.py +317 -317
  7. evaluation/generate_task_specific_statistics_plots.py +481 -253
  8. evaluation/get_plans_images.py +41 -26
  9. evaluation/increasing_and_decreasing_.py +97 -56
  10. gr_libs/__init__.py +6 -1
  11. gr_libs/_version.py +2 -2
  12. gr_libs/environment/__init__.py +17 -9
  13. gr_libs/environment/environment.py +167 -39
  14. gr_libs/environment/utils/utils.py +22 -12
  15. gr_libs/metrics/__init__.py +5 -0
  16. gr_libs/metrics/metrics.py +76 -34
  17. gr_libs/ml/__init__.py +2 -0
  18. gr_libs/ml/agent.py +21 -6
  19. gr_libs/ml/base/__init__.py +1 -1
  20. gr_libs/ml/base/rl_agent.py +13 -10
  21. gr_libs/ml/consts.py +1 -1
  22. gr_libs/ml/neural/deep_rl_learner.py +433 -352
  23. gr_libs/ml/neural/utils/__init__.py +1 -1
  24. gr_libs/ml/neural/utils/dictlist.py +3 -3
  25. gr_libs/ml/neural/utils/penv.py +5 -2
  26. gr_libs/ml/planner/mcts/mcts_model.py +524 -302
  27. gr_libs/ml/planner/mcts/utils/__init__.py +1 -1
  28. gr_libs/ml/planner/mcts/utils/node.py +11 -7
  29. gr_libs/ml/planner/mcts/utils/tree.py +14 -10
  30. gr_libs/ml/sequential/__init__.py +1 -1
  31. gr_libs/ml/sequential/lstm_model.py +256 -175
  32. gr_libs/ml/tabular/state.py +7 -7
  33. gr_libs/ml/tabular/tabular_q_learner.py +123 -73
  34. gr_libs/ml/tabular/tabular_rl_agent.py +20 -19
  35. gr_libs/ml/utils/__init__.py +8 -2
  36. gr_libs/ml/utils/format.py +78 -70
  37. gr_libs/ml/utils/math.py +2 -1
  38. gr_libs/ml/utils/other.py +1 -1
  39. gr_libs/ml/utils/storage.py +95 -28
  40. gr_libs/problems/consts.py +1549 -1227
  41. gr_libs/recognizer/gr_as_rl/gr_as_rl_recognizer.py +145 -80
  42. gr_libs/recognizer/graml/gr_dataset.py +209 -110
  43. gr_libs/recognizer/graml/graml_recognizer.py +431 -231
  44. gr_libs/recognizer/recognizer.py +38 -27
  45. gr_libs/recognizer/utils/__init__.py +1 -1
  46. gr_libs/recognizer/utils/format.py +8 -3
  47. {gr_libs-0.1.6.post1.dist-info → gr_libs-0.1.8.dist-info}/METADATA +1 -1
  48. gr_libs-0.1.8.dist-info/RECORD +70 -0
  49. {gr_libs-0.1.6.post1.dist-info → gr_libs-0.1.8.dist-info}/WHEEL +1 -1
  50. {gr_libs-0.1.6.post1.dist-info → gr_libs-0.1.8.dist-info}/top_level.txt +0 -1
  51. tests/test_gcdraco.py +10 -0
  52. tests/test_graml.py +8 -4
  53. tests/test_graql.py +2 -1
  54. tutorials/gcdraco_panda_tutorial.py +66 -0
  55. tutorials/gcdraco_parking_tutorial.py +61 -0
  56. tutorials/graml_minigrid_tutorial.py +42 -12
  57. tutorials/graml_panda_tutorial.py +35 -14
  58. tutorials/graml_parking_tutorial.py +37 -19
  59. tutorials/graml_point_maze_tutorial.py +33 -13
  60. tutorials/graql_minigrid_tutorial.py +31 -15
  61. CI/README.md +0 -12
  62. CI/docker_build_context/Dockerfile +0 -15
  63. gr_libs/recognizer/recognizer_doc.md +0 -61
  64. gr_libs-0.1.6.post1.dist-info/RECORD +0 -70
@@ -4,89 +4,138 @@ import matplotlib.pyplot as plt
4
4
  import numpy as np
5
5
  import os
6
6
  import dill
7
- from gr_libs.ml.utils.storage import get_experiment_results_path, set_global_storage_configs
7
+ from gr_libs.ml.utils.storage import (
8
+ get_experiment_results_path,
9
+ set_global_storage_configs,
10
+ )
8
11
  from scripts.generate_task_specific_statistics_plots import get_figures_dir_path
9
12
 
10
- def gen_graph(graph_name, x_label_str, tasks, panda_env, minigrid_env, parking_env, maze_env, percentage):
11
13
 
12
- fragmented_accuracies = {
13
- 'graml': {
14
- #'panda': [],
15
- #'minigrid': [],
16
- #'point_maze': [],
17
- 'parking': []
18
- },
19
- 'graql': {
20
- #'panda': [],
21
- #'minigrid': [],
22
- #'point_maze': [],
23
- 'parking': []
24
- }
25
- }
14
+ def gen_graph(
15
+ graph_name,
16
+ x_label_str,
17
+ tasks,
18
+ panda_env,
19
+ minigrid_env,
20
+ parking_env,
21
+ maze_env,
22
+ percentage,
23
+ ):
26
24
 
27
- continuing_accuracies = copy.deepcopy(fragmented_accuracies)
28
-
29
- #domains_envs = [('minigrid', minigrid_env), ('point_maze', maze_env), ('parking', parking_env)]
30
- domains_envs = [('parking', parking_env)]
25
+ fragmented_accuracies = {
26
+ "graml": {
27
+ #'panda': [],
28
+ #'minigrid': [],
29
+ #'point_maze': [],
30
+ "parking": []
31
+ },
32
+ "graql": {
33
+ #'panda': [],
34
+ #'minigrid': [],
35
+ #'point_maze': [],
36
+ "parking": []
37
+ },
38
+ }
31
39
 
32
- for partial_obs_type, accuracies, is_same_learn in zip(['fragmented', 'continuing'], [fragmented_accuracies, continuing_accuracies], [False, True]):
33
- for domain, env in domains_envs:
34
- for task in tasks:
35
- set_global_storage_configs(recognizer_str='graml', is_fragmented=partial_obs_type,
36
- is_inference_same_length_sequences=True, is_learn_same_length_sequences=is_same_learn)
37
- graml_res_file_path = f'{get_experiment_results_path(domain, env, task)}.pkl'
38
- set_global_storage_configs(recognizer_str='graql', is_fragmented=partial_obs_type)
39
- graql_res_file_path = f'{get_experiment_results_path(domain, env, task)}.pkl'
40
- if os.path.exists(graml_res_file_path):
41
- with open(graml_res_file_path, 'rb') as results_file:
42
- results = dill.load(results_file)
43
- accuracies['graml'][domain].append(results[percentage]['accuracy'])
44
- else:
45
- assert(False, f"no file for {graml_res_file_path}")
46
- if os.path.exists(graql_res_file_path):
47
- with open(graql_res_file_path, 'rb') as results_file:
48
- results = dill.load(results_file)
49
- accuracies['graql'][domain].append(results[percentage]['accuracy'])
50
- else:
51
- assert(False, f"no file for {graql_res_file_path}")
40
+ continuing_accuracies = copy.deepcopy(fragmented_accuracies)
52
41
 
53
- def plot_accuracies(accuracies, partial_obs_type):
54
- plt.figure(figsize=(10, 6))
55
- colors = plt.cm.get_cmap('tab10', len(accuracies['graml']) * len(accuracies['graml']['parking']))
42
+ # domains_envs = [('minigrid', minigrid_env), ('point_maze', maze_env), ('parking', parking_env)]
43
+ domains_envs = [("parking", parking_env)]
56
44
 
57
- # Define different line styles for each algorithm
58
- line_styles = {'graml': '-', 'graql': '--'}
59
- x_vals = np.arange(3, 8)
60
- plt.xticks(x_vals)
61
- plt.yticks(np.linspace(0, 1, 6))
62
- plt.ylim([0, 1])
63
- # Plot each domain-env pair's accuracies with different line styles for each algorithm
64
- for alg in ['graml', 'graql']:
65
- for idx, (domain, acc_values) in enumerate(accuracies[alg].items()):
66
- if acc_values and len(acc_values) > 0: # Only plot if there are values
67
- x_values = np.arange(3, len(acc_values) + 3)
68
- plt.plot(x_values, acc_values, marker='o', linestyle=line_styles[alg],
69
- color=colors(idx), label=f"{alg}-{domain}-{partial_obs_type}-{percentage}")
45
+ for partial_obs_type, accuracies, is_same_learn in zip(
46
+ ["fragmented", "continuing"],
47
+ [fragmented_accuracies, continuing_accuracies],
48
+ [False, True],
49
+ ):
50
+ for domain, env in domains_envs:
51
+ for task in tasks:
52
+ set_global_storage_configs(
53
+ recognizer_str="graml",
54
+ is_fragmented=partial_obs_type,
55
+ is_inference_same_length_sequences=True,
56
+ is_learn_same_length_sequences=is_same_learn,
57
+ )
58
+ graml_res_file_path = (
59
+ f"{get_experiment_results_path(domain, env, task)}.pkl"
60
+ )
61
+ set_global_storage_configs(
62
+ recognizer_str="graql", is_fragmented=partial_obs_type
63
+ )
64
+ graql_res_file_path = (
65
+ f"{get_experiment_results_path(domain, env, task)}.pkl"
66
+ )
67
+ if os.path.exists(graml_res_file_path):
68
+ with open(graml_res_file_path, "rb") as results_file:
69
+ results = dill.load(results_file)
70
+ accuracies["graml"][domain].append(
71
+ results[percentage]["accuracy"]
72
+ )
73
+ else:
74
+ assert (False, f"no file for {graml_res_file_path}")
75
+ if os.path.exists(graql_res_file_path):
76
+ with open(graql_res_file_path, "rb") as results_file:
77
+ results = dill.load(results_file)
78
+ accuracies["graql"][domain].append(
79
+ results[percentage]["accuracy"]
80
+ )
81
+ else:
82
+ assert (False, f"no file for {graql_res_file_path}")
70
83
 
71
- # Set labels, title, and grid
72
- plt.xlabel(x_label_str)
73
- plt.ylabel('Accuracy')
74
- plt.grid(True)
84
+ def plot_accuracies(accuracies, partial_obs_type):
85
+ plt.figure(figsize=(10, 6))
86
+ colors = plt.cm.get_cmap(
87
+ "tab10", len(accuracies["graml"]) * len(accuracies["graml"]["parking"])
88
+ )
75
89
 
76
- # Add legend to differentiate between domain-env pairs
77
- plt.legend()
90
+ # Define different line styles for each algorithm
91
+ line_styles = {"graml": "-", "graql": "--"}
92
+ x_vals = np.arange(3, 8)
93
+ plt.xticks(x_vals)
94
+ plt.yticks(np.linspace(0, 1, 6))
95
+ plt.ylim([0, 1])
96
+ # Plot each domain-env pair's accuracies with different line styles for each algorithm
97
+ for alg in ["graml", "graql"]:
98
+ for idx, (domain, acc_values) in enumerate(accuracies[alg].items()):
99
+ if acc_values and len(acc_values) > 0: # Only plot if there are values
100
+ x_values = np.arange(3, len(acc_values) + 3)
101
+ plt.plot(
102
+ x_values,
103
+ acc_values,
104
+ marker="o",
105
+ linestyle=line_styles[alg],
106
+ color=colors(idx),
107
+ label=f"{alg}-{domain}-{partial_obs_type}-{percentage}",
108
+ )
109
+
110
+ # Set labels, title, and grid
111
+ plt.xlabel(x_label_str)
112
+ plt.ylabel("Accuracy")
113
+ plt.grid(True)
114
+
115
+ # Add legend to differentiate between domain-env pairs
116
+ plt.legend()
117
+
118
+ # Save the figure
119
+ fig_path = os.path.join(f"{graph_name}_{partial_obs_type}.png")
120
+ plt.savefig(fig_path)
121
+ print(f"Accuracies figure saved at: {fig_path}")
122
+
123
+ print(f"fragmented_accuracies: {fragmented_accuracies}")
124
+ plot_accuracies(fragmented_accuracies, "fragmented")
125
+ print(f"continuing_accuracies: {continuing_accuracies}")
126
+ plot_accuracies(continuing_accuracies, "continuing")
78
127
 
79
- # Save the figure
80
- fig_path = os.path.join(f"{graph_name}_{partial_obs_type}.png")
81
- plt.savefig(fig_path)
82
- print(f"Accuracies figure saved at: {fig_path}")
83
128
 
84
- print(f'fragmented_accuracies: {fragmented_accuracies}')
85
- plot_accuracies(fragmented_accuracies, 'fragmented')
86
- print(f'continuing_accuracies: {continuing_accuracies}')
87
- plot_accuracies(continuing_accuracies, 'continuing')
88
-
89
129
  if __name__ == "__main__":
90
- #gen_graph("increasing_base_goals", "Number of base goals", ['L1', 'L2', 'L3', 'L4', 'L5'], panda_env='gd_agent', minigrid_env='obstacles', parking_env='gd_agent', maze_env='obstacles')
91
- #gen_graph("increasing_dynamic_goals", "Number of dynamic goals", ['L1', 'L2', 'L3', 'L4', 'L5'], panda_env='gc_agent', minigrid_env='lava_crossing', parking_env='gc_agent', maze_env='four_rooms')
92
- gen_graph("base_problems", "Number of goals", ['L111', 'L222', 'L333', 'L444', 'L555'], panda_env='gd_agent', minigrid_env='obstacles', parking_env='gc_agent', maze_env='obstacles', percentage='0.7')
130
+ # gen_graph("increasing_base_goals", "Number of base goals", ['L1', 'L2', 'L3', 'L4', 'L5'], panda_env='gd_agent', minigrid_env='obstacles', parking_env='gd_agent', maze_env='obstacles')
131
+ # gen_graph("increasing_dynamic_goals", "Number of dynamic goals", ['L1', 'L2', 'L3', 'L4', 'L5'], panda_env='gc_agent', minigrid_env='lava_crossing', parking_env='gc_agent', maze_env='four_rooms')
132
+ gen_graph(
133
+ "base_problems",
134
+ "Number of goals",
135
+ ["L111", "L222", "L333", "L444", "L555"],
136
+ panda_env="gd_agent",
137
+ minigrid_env="obstacles",
138
+ parking_env="gc_agent",
139
+ maze_env="obstacles",
140
+ percentage="0.7",
141
+ )