gr-libs 0.1.3__tar.gz
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-0.1.3/.github/workflows/release.yml +32 -0
- gr_libs-0.1.3/.gitignore +160 -0
- gr_libs-0.1.3/PKG-INFO +197 -0
- gr_libs-0.1.3/README.md +182 -0
- gr_libs-0.1.3/all_experiments.py +194 -0
- gr_libs-0.1.3/consts.py +1244 -0
- gr_libs-0.1.3/evaluation/analyze_results_cross_alg_cross_domain.py +277 -0
- gr_libs-0.1.3/evaluation/create_minigrid_map_image.py +34 -0
- gr_libs-0.1.3/evaluation/file_system.py +42 -0
- gr_libs-0.1.3/evaluation/generate_experiments_results.py +92 -0
- gr_libs-0.1.3/evaluation/generate_experiments_results_new_ver1.py +254 -0
- gr_libs-0.1.3/evaluation/generate_experiments_results_new_ver2.py +331 -0
- gr_libs-0.1.3/evaluation/generate_task_specific_statistics_plots.py +272 -0
- gr_libs-0.1.3/evaluation/get_plans_images.py +47 -0
- gr_libs-0.1.3/evaluation/increasing_and_decreasing_.py +63 -0
- gr_libs-0.1.3/gr_libs/__init__.py +2 -0
- gr_libs-0.1.3/gr_libs/environment/__init__.py +0 -0
- gr_libs-0.1.3/gr_libs/environment/environment.py +227 -0
- gr_libs-0.1.3/gr_libs/environment/utils/__init__.py +0 -0
- gr_libs-0.1.3/gr_libs/environment/utils/utils.py +17 -0
- gr_libs-0.1.3/gr_libs/metrics/__init__.py +0 -0
- gr_libs-0.1.3/gr_libs/metrics/metrics.py +224 -0
- gr_libs-0.1.3/gr_libs/ml/__init__.py +6 -0
- gr_libs-0.1.3/gr_libs/ml/agent.py +56 -0
- gr_libs-0.1.3/gr_libs/ml/base/__init__.py +1 -0
- gr_libs-0.1.3/gr_libs/ml/base/rl_agent.py +54 -0
- gr_libs-0.1.3/gr_libs/ml/consts.py +22 -0
- gr_libs-0.1.3/gr_libs/ml/neural/__init__.py +3 -0
- gr_libs-0.1.3/gr_libs/ml/neural/deep_rl_learner.py +395 -0
- gr_libs-0.1.3/gr_libs/ml/neural/utils/__init__.py +2 -0
- gr_libs-0.1.3/gr_libs/ml/neural/utils/dictlist.py +33 -0
- gr_libs-0.1.3/gr_libs/ml/neural/utils/penv.py +57 -0
- gr_libs-0.1.3/gr_libs/ml/planner/__init__.py +0 -0
- gr_libs-0.1.3/gr_libs/ml/planner/mcts/__init__.py +0 -0
- gr_libs-0.1.3/gr_libs/ml/planner/mcts/mcts_model.py +330 -0
- gr_libs-0.1.3/gr_libs/ml/planner/mcts/utils/__init__.py +2 -0
- gr_libs-0.1.3/gr_libs/ml/planner/mcts/utils/node.py +33 -0
- gr_libs-0.1.3/gr_libs/ml/planner/mcts/utils/tree.py +102 -0
- gr_libs-0.1.3/gr_libs/ml/sequential/__init__.py +1 -0
- gr_libs-0.1.3/gr_libs/ml/sequential/lstm_model.py +192 -0
- gr_libs-0.1.3/gr_libs/ml/tabular/__init__.py +3 -0
- gr_libs-0.1.3/gr_libs/ml/tabular/state.py +21 -0
- gr_libs-0.1.3/gr_libs/ml/tabular/tabular_q_learner.py +453 -0
- gr_libs-0.1.3/gr_libs/ml/tabular/tabular_rl_agent.py +126 -0
- gr_libs-0.1.3/gr_libs/ml/utils/__init__.py +6 -0
- gr_libs-0.1.3/gr_libs/ml/utils/env.py +7 -0
- gr_libs-0.1.3/gr_libs/ml/utils/format.py +100 -0
- gr_libs-0.1.3/gr_libs/ml/utils/math.py +13 -0
- gr_libs-0.1.3/gr_libs/ml/utils/other.py +24 -0
- gr_libs-0.1.3/gr_libs/ml/utils/storage.py +127 -0
- gr_libs-0.1.3/gr_libs/recognizer/__init__.py +0 -0
- gr_libs-0.1.3/gr_libs/recognizer/gr_as_rl/__init__.py +0 -0
- gr_libs-0.1.3/gr_libs/recognizer/gr_as_rl/gr_as_rl_recognizer.py +102 -0
- gr_libs-0.1.3/gr_libs/recognizer/graml/__init__.py +0 -0
- gr_libs-0.1.3/gr_libs/recognizer/graml/gr_dataset.py +134 -0
- gr_libs-0.1.3/gr_libs/recognizer/graml/graml_recognizer.py +266 -0
- gr_libs-0.1.3/gr_libs/recognizer/recognizer.py +46 -0
- gr_libs-0.1.3/gr_libs/recognizer/utils/__init__.py +1 -0
- gr_libs-0.1.3/gr_libs/recognizer/utils/format.py +13 -0
- gr_libs-0.1.3/gr_libs.egg-info/PKG-INFO +197 -0
- gr_libs-0.1.3/gr_libs.egg-info/SOURCES.txt +70 -0
- gr_libs-0.1.3/gr_libs.egg-info/dependency_links.txt +1 -0
- gr_libs-0.1.3/gr_libs.egg-info/requires.txt +3 -0
- gr_libs-0.1.3/gr_libs.egg-info/top_level.txt +4 -0
- gr_libs-0.1.3/odgr_executor.py +125 -0
- gr_libs-0.1.3/pyproject.toml +32 -0
- gr_libs-0.1.3/setup.cfg +4 -0
- gr_libs-0.1.3/tutorials/graml_minigrid_tutorial.py +30 -0
- gr_libs-0.1.3/tutorials/graml_panda_tutorial.py +32 -0
- gr_libs-0.1.3/tutorials/graml_parking_tutorial.py +38 -0
- gr_libs-0.1.3/tutorials/graml_point_maze_tutorial.py +43 -0
- gr_libs-0.1.3/tutorials/graql_minigrid_tutorial.py +29 -0
@@ -0,0 +1,32 @@
|
|
1
|
+
name: Publish to PyPI
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
tags:
|
6
|
+
- "v*"
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
build-and-publish:
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
|
12
|
+
steps:
|
13
|
+
- name: Check out the repository
|
14
|
+
uses: actions/checkout@v4
|
15
|
+
|
16
|
+
- name: Set up Python
|
17
|
+
uses: actions/setup-python@v4
|
18
|
+
with:
|
19
|
+
python-version: "3.11"
|
20
|
+
|
21
|
+
- name: Install build dependencies
|
22
|
+
run: |
|
23
|
+
python -m pip install --upgrade pip
|
24
|
+
pip install build twine
|
25
|
+
|
26
|
+
- name: Build the package
|
27
|
+
run: python -m build # Uses pyproject.toml instead of setup.py
|
28
|
+
|
29
|
+
- name: Publish to PyPI
|
30
|
+
env:
|
31
|
+
PYPY_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
|
32
|
+
run: python -m twine upload dist/* -u __token__ -p $PYPY_API_TOKEN
|
gr_libs-0.1.3/.gitignore
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
2
|
+
__pycache__/
|
3
|
+
*.py[cod]
|
4
|
+
*$py.class
|
5
|
+
|
6
|
+
# C extensions
|
7
|
+
*.so
|
8
|
+
|
9
|
+
# Distribution / packaging
|
10
|
+
.Python
|
11
|
+
build/
|
12
|
+
develop-eggs/
|
13
|
+
dist/
|
14
|
+
downloads/
|
15
|
+
eggs/
|
16
|
+
.eggs/
|
17
|
+
lib/
|
18
|
+
lib64/
|
19
|
+
parts/
|
20
|
+
sdist/
|
21
|
+
var/
|
22
|
+
wheels/
|
23
|
+
share/python-wheels/
|
24
|
+
*.egg-info/
|
25
|
+
.installed.cfg
|
26
|
+
*.egg
|
27
|
+
MANIFEST
|
28
|
+
|
29
|
+
# PyInstaller
|
30
|
+
# Usually these files are written by a python script from a template
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
32
|
+
*.manifest
|
33
|
+
*.spec
|
34
|
+
|
35
|
+
# Installer logs
|
36
|
+
pip-log.txt
|
37
|
+
pip-delete-this-directory.txt
|
38
|
+
|
39
|
+
# Unit test / coverage reports
|
40
|
+
htmlcov/
|
41
|
+
.tox/
|
42
|
+
.nox/
|
43
|
+
.coverage
|
44
|
+
.coverage.*
|
45
|
+
.cache
|
46
|
+
nosetests.xml
|
47
|
+
coverage.xml
|
48
|
+
*.cover
|
49
|
+
*.py,cover
|
50
|
+
.hypothesis/
|
51
|
+
.pytest_cache/
|
52
|
+
cover/
|
53
|
+
|
54
|
+
# Translations
|
55
|
+
*.mo
|
56
|
+
*.pot
|
57
|
+
|
58
|
+
# Django stuff:
|
59
|
+
*.log
|
60
|
+
local_settings.py
|
61
|
+
db.sqlite3
|
62
|
+
db.sqlite3-journal
|
63
|
+
|
64
|
+
# Flask stuff:
|
65
|
+
instance/
|
66
|
+
.webassets-cache
|
67
|
+
|
68
|
+
# Scrapy stuff:
|
69
|
+
.scrapy
|
70
|
+
|
71
|
+
# Sphinx documentation
|
72
|
+
docs/_build/
|
73
|
+
|
74
|
+
# PyBuilder
|
75
|
+
.pybuilder/
|
76
|
+
target/
|
77
|
+
|
78
|
+
# Jupyter Notebook
|
79
|
+
.ipynb_checkpoints
|
80
|
+
|
81
|
+
# IPython
|
82
|
+
profile_default/
|
83
|
+
ipython_config.py
|
84
|
+
|
85
|
+
# pyenv
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
88
|
+
# .python-version
|
89
|
+
|
90
|
+
# pipenv
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
94
|
+
# install all needed dependencies.
|
95
|
+
#Pipfile.lock
|
96
|
+
|
97
|
+
# poetry
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
100
|
+
# commonly ignored for libraries.
|
101
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
102
|
+
#poetry.lock
|
103
|
+
|
104
|
+
# pdm
|
105
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
106
|
+
#pdm.lock
|
107
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
108
|
+
# in version control.
|
109
|
+
# https://pdm.fming.dev/#use-with-ide
|
110
|
+
.pdm.toml
|
111
|
+
|
112
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
113
|
+
__pypackages__/
|
114
|
+
|
115
|
+
# Celery stuff
|
116
|
+
celerybeat-schedule
|
117
|
+
celerybeat.pid
|
118
|
+
|
119
|
+
# SageMath parsed files
|
120
|
+
*.sage.py
|
121
|
+
|
122
|
+
# Environments
|
123
|
+
.env
|
124
|
+
.venv
|
125
|
+
env/
|
126
|
+
venv/
|
127
|
+
ENV/
|
128
|
+
env.bak/
|
129
|
+
venv.bak/
|
130
|
+
|
131
|
+
# Spyder project settings
|
132
|
+
.spyderproject
|
133
|
+
.spyproject
|
134
|
+
|
135
|
+
# Rope project settings
|
136
|
+
.ropeproject
|
137
|
+
|
138
|
+
# mkdocs documentation
|
139
|
+
/site
|
140
|
+
|
141
|
+
# mypy
|
142
|
+
.mypy_cache/
|
143
|
+
.dmypy.json
|
144
|
+
dmypy.json
|
145
|
+
|
146
|
+
# Pyre type checker
|
147
|
+
.pyre/
|
148
|
+
|
149
|
+
# pytype static type analyzer
|
150
|
+
.pytype/
|
151
|
+
|
152
|
+
# Cython debug symbols
|
153
|
+
cython_debug/
|
154
|
+
|
155
|
+
# PyCharm
|
156
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
157
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
158
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
159
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
160
|
+
#.idea/
|
gr_libs-0.1.3/PKG-INFO
ADDED
@@ -0,0 +1,197 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: gr_libs
|
3
|
+
Version: 0.1.3
|
4
|
+
Summary: Package with goal recognition frameworks baselines
|
5
|
+
Author: Osher Elhadad, Ben Nageris
|
6
|
+
Author-email: Matan Shamir <matan.shamir@live.biu.ac.il>
|
7
|
+
License-Expression: MIT
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
9
|
+
Classifier: Operating System :: OS Independent
|
10
|
+
Requires-Python: >=3.11
|
11
|
+
Description-Content-Type: text/markdown
|
12
|
+
Requires-Dist: gr_envs
|
13
|
+
Requires-Dist: dill
|
14
|
+
Requires-Dist: opencv-python
|
15
|
+
|
16
|
+
# GRLib
|
17
|
+
GRLib is a python package containing implementations of Goal Recognition (GR) algorithms which use MDPs to represent the decision making process. All agents in those algorithms interact with an environment that's registered in gym API.
|
18
|
+
## Setup:
|
19
|
+
If you're on linux, great, If on windows, use git bash for the next commands to work.
|
20
|
+
1. Find where your python is installed. If you want to find where's your python3.12, you can run:
|
21
|
+
```sh
|
22
|
+
py -3.12 -c "import sys; print(sys.executable)"
|
23
|
+
```
|
24
|
+
2. Create a new empty venv from that python venv module:
|
25
|
+
```sh
|
26
|
+
C:/Users/path/to/Programs/Python/Python312/python.exe -m venv test_env
|
27
|
+
```
|
28
|
+
3. Activate the environment:
|
29
|
+
```sh
|
30
|
+
source test_env/Scripts/activate
|
31
|
+
```
|
32
|
+
4. There's no equivalent to conda env list to check the global virtual environments status, so you can verify the active one via:
|
33
|
+
```sh
|
34
|
+
echo $VIRTUAL_ENV
|
35
|
+
```
|
36
|
+
5. Install and upgrade basic package management modules:
|
37
|
+
```sh
|
38
|
+
/path/to/python.exe -m pip install --upgrade pip setuptools wheel versioneer
|
39
|
+
```
|
40
|
+
6. Install the gr_libss package (can add -e for editable mode):
|
41
|
+
```sh
|
42
|
+
cd /path/to/clone/of/GoalRecognitionLibs
|
43
|
+
pip install -e .
|
44
|
+
```
|
45
|
+
7. Install gr_libs package (can add -e for editable mode):
|
46
|
+
```sh
|
47
|
+
cd /path/to/clone/of/Grlib
|
48
|
+
pip install -e .
|
49
|
+
```
|
50
|
+
|
51
|
+
|
52
|
+
<!-- 1. Ensure you have python 3.11 installed.
|
53
|
+
If you have root permissions, simply use:
|
54
|
+
```sh
|
55
|
+
mkdir -p ~/.local/python3.11
|
56
|
+
dnf install python3.11 --prefix ~/.local/python3.11
|
57
|
+
echo 'export PATH=$HOME/.local/python3.11/bin:$PATH' >> ~/.bashrc
|
58
|
+
source ~/.bashrc
|
59
|
+
```
|
60
|
+
Else, use pyenv:
|
61
|
+
```sh
|
62
|
+
pyenv install 3.11.0
|
63
|
+
```
|
64
|
+
2. Create a new venv or use an existing 3.11 venv, and activate it. To create a new venv:
|
65
|
+
```sh
|
66
|
+
~/.pyenv/versions/3.11.0/bin/python -m venv graml_env
|
67
|
+
./Python-3.11.0/graml_env/bin/activate
|
68
|
+
```
|
69
|
+
If you're not a sudo, and you have problems with building python getting such warnings:
|
70
|
+
```sh
|
71
|
+
WARNING: The Python ctypes extension was not compiled. Missing the libffi lib?
|
72
|
+
```
|
73
|
+
That means you don't have the necesarry libraries for building python, and you probably can't change that since you're not a sudoer.
|
74
|
+
An alternative solution can be using a conda env:
|
75
|
+
```sh
|
76
|
+
conda create -n graml_env python=3.11
|
77
|
+
conda activate graml_env
|
78
|
+
```
|
79
|
+
3. Install GoalRecognitionLibs to get all needed dependencies:
|
80
|
+
```sh
|
81
|
+
git clone [GoalRecognitionLibs address]
|
82
|
+
cd GoalRecognitionLibs
|
83
|
+
pip install -e . # using the conda's pip of course
|
84
|
+
``` -->
|
85
|
+
|
86
|
+
### Issues & Problems ###
|
87
|
+
If you're not a sudo, and you have problems with building python getting such warnings:
|
88
|
+
```sh
|
89
|
+
WARNING: The Python ctypes extension was not compiled. Missing the libffi lib?
|
90
|
+
```
|
91
|
+
That means you don't have the necesarry libraries for building python.
|
92
|
+
|
93
|
+
### How to use Grlib ###
|
94
|
+
Now that you've installed the package, you have additional custom gym environments and you can start creating an ODGR scenario with the algorithm you wish to test.
|
95
|
+
The tutorial at tutorials/tutorial.py follows a simple ODGR scnenario. We guide through the initialization and deployment process following an example where GRAML is expected to adapt to new emerging goals in the point_maze gym environment.
|
96
|
+
|
97
|
+
#### Method 1: write your own script
|
98
|
+
1. create the recognizer: we need to state the base problems on which the recognizer train.
|
99
|
+
we also need the env_name for the sake of storing the trained models.
|
100
|
+
Other notable parameters include the parameters for the training of the model: For example, Graml's LSTM needs to accept input sizes the size of the concatenation of the state space with the action space.
|
101
|
+
|
102
|
+
```python
|
103
|
+
recognizer = Graml(
|
104
|
+
env_name="point_maze", # TODO change to macros which are importable from some info or env module of enums.
|
105
|
+
problems=[("PointMaze-FourRoomsEnvDense-11x11-Goal-9x1"),
|
106
|
+
("PointMaze-FourRoomsEnv-11x11-Goal-9x9"), # this one doesn't work with dense rewards because of encountering local minima
|
107
|
+
("PointMaze-FourRoomsEnvDense-11x11-Goal-1x9"),
|
108
|
+
("PointMaze-FourRoomsEnvDense-11x11-Goal-3x3"),
|
109
|
+
("PointMaze-FourRoomsEnvDense-11x11-Goal-3x4"),
|
110
|
+
("PointMaze-FourRoomsEnvDense-11x11-Goal-8x2"),
|
111
|
+
("PointMaze-FourRoomsEnvDense-11x11-Goal-3x7"),
|
112
|
+
("PointMaze-FourRoomsEnvDense-11x11-Goal-2x8")],
|
113
|
+
task_str_to_goal=maze_str_to_goal,
|
114
|
+
method=DeepRLAgent,
|
115
|
+
collect_statistics=False,
|
116
|
+
train_configs=[(SAC, 200000) for i in range(8)],
|
117
|
+
partial_obs_type="fragmented",
|
118
|
+
batch_size=32,
|
119
|
+
input_size=6,
|
120
|
+
hidden_size=8,
|
121
|
+
num_samples=20000,
|
122
|
+
problem_list_to_str_tuple=lambda problems: "_".join([f"[{s.split('-')[-1]}]" for s in problems]),
|
123
|
+
is_learn_same_length_sequences=False,
|
124
|
+
goals_adaptation_sequence_generation_method=AGENT_BASED # take expert samples in goals adaptation phase
|
125
|
+
)
|
126
|
+
```
|
127
|
+
|
128
|
+
2. The domain learning phase: In GRAML's case, the recognizer generates a dataset by training agents towards the base goals and trains an metric model combined of an LSTM on traces generated by those agents.
|
129
|
+
|
130
|
+
```python
|
131
|
+
recognizer.domain_learning_phase()
|
132
|
+
```
|
133
|
+
3. The goals adaptation phase: The recognizer receives new goals, along with configurations to the training of those agents - since the sequence generation method in this case is from an expert.
|
134
|
+
```python
|
135
|
+
recognizer.goals_adaptation_phase(
|
136
|
+
dynamic_goals_problems = ["PointMaze-FourRoomsEnvDense-11x11-Goal-4x4",
|
137
|
+
"PointMaze-FourRoomsEnvDense-11x11-Goal-7x3",
|
138
|
+
"PointMaze-FourRoomsEnvDense-11x11-Goal-3x7"],
|
139
|
+
dynamic_train_configs=[(SAC, 200000) for i in range(3)] # for expert sequence generation
|
140
|
+
)
|
141
|
+
```
|
142
|
+
4. Inference phase - this snippet generates a partial sequence by an agent trained towards one of the goals of the inference phase. Note how the trace is generated using a different agent from the recognizer's inner agents or expert (TD3 rather than SAC), and with noise added to every action to simulate suboptimal behavior.
|
143
|
+
```python
|
144
|
+
actor = DeepRLAgent(env_name="point_maze", problem_name="PointMaze-FourRoomsEnvDense-11x11-Goal-4x4", algorithm=TD3, num_timesteps=200000)
|
145
|
+
actor.learn()
|
146
|
+
full_sequence = actor.generate_observation(
|
147
|
+
action_selection_method=stochastic_amplified_selection,
|
148
|
+
random_optimalism=True, # the noise that's added to the actions
|
149
|
+
)
|
150
|
+
partial_sequence = random_subset_with_order(full_sequence, (int)(0.5 * len(full_sequence)), is_fragmented="fragmented")
|
151
|
+
closest_goal = recognizer.inference_phase(partial_sequence, maze_str_to_goal("PointMaze-FourRoomsEnvDense-11x11-Goal-4x4"), 0.5)
|
152
|
+
```
|
153
|
+
5. check the result returned by GRAML and print whether it was right or not.
|
154
|
+
```python
|
155
|
+
print(f"closest_goal returned by GRAML: {closest_goal}\nactual goal actor aimed towards: (4, 4)")
|
156
|
+
```
|
157
|
+
|
158
|
+
#### Method 2: use a configuration file
|
159
|
+
The configuraiton file consts.py holds configurations of ODGR problems.
|
160
|
+
You can either use existing ones or add new ones.
|
161
|
+
Note that using the config file, despite being easier on a large scale, some inputs to the ODGR problem are not as flexible as they would be using method 1.
|
162
|
+
For example, the sequence generation will be performed by trained agents and is non configurable. The sequences will either be completely consecutive or randomly sampled from the trace.
|
163
|
+
Example for a problem:
|
164
|
+
|
165
|
+
You can use odgr_executor.py to execute a single task:
|
166
|
+
```sh
|
167
|
+
python odgr_executor.py --recognizer MCTSBasedGraml --domain minigrid --task L1 --minigrid_env MinigridSimple
|
168
|
+
```
|
169
|
+
|
170
|
+
|
171
|
+
## Supported Algorithms
|
172
|
+
|
173
|
+
| **Name** | **Supervised** | **RL** | **Discrete** | **Continuous** | **Model-Based** | **Model-Free** | **Actions Only** |
|
174
|
+
| ------------------- | ------------------ | ------------------ | ------------------ | ------------------- | ------------------ | --------------------------------- |
|
175
|
+
| GRAQL | :x: | :heavy_check_mark: | :heavy_check_mark: | :x: | :x: | :heavy_check_mark: | :x: |
|
176
|
+
| DRACO | :x: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :x: | :heavy_check_mark: | :x: |
|
177
|
+
| GRAML | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :x: | :heavy_check_mark: | :heavy_check_mark: |
|
178
|
+
|
179
|
+
## Supported Domains
|
180
|
+
|
181
|
+
| **Name** | **Action** | **State** |
|
182
|
+
| ------------------- | ------------------ | ------------------ |
|
183
|
+
| Minigrid | Discrete | Discrete |
|
184
|
+
| PointMaze | Continuous | Continuous |
|
185
|
+
| Parking | Continuous | Continuous |
|
186
|
+
| Panda | Continuous | Continuous |
|
187
|
+
|
188
|
+
### Experiments
|
189
|
+
Given here is a guide for executing the experiments. There are benchmark domains suggested in the repository, and the 'scripts' directory suggests a series of tools to analyze them. They are defaultly set on the domains used for GRAML and GRAQL analysis during the writing of GRAML paper, but can easily be adjusted for new domains and algorithms.
|
190
|
+
1. analyze_results_cross_alg_cross_domain.py: this script runs with no arguments. it injects information from get_experiment_results_path (for example: dataset\graml\minigrid\continuing\inference_same_seq_len\learn_diff_seq_len\experiment_results\obstacles\L111\experiment_results.pkl), and produces a plot with 4 figures showing the accuracy trend of algorithms on the domains checked one against the other. Currently GRAML is checked against GRAQL or DRACO but it can easily be adjusted from within the script.
|
191
|
+
2. generate_task_specific_statistics_plots.py - this script produces, for a specific task execution (results of execution of experiments.py), a summary combined of a figure with sticks with the accuracies and confidence levels of an algorithm on the task on the varying percentages. figures\point_maze\obstacles\graql_point_maze_obstacles_fragmented_stats.png is an example of a path at which the output is dumped. Another product of this script is a confusion matrix with the confidence levels - visualizing the same data, and the output file resides in this path: figures\point_maze\obstacles\graml_point_maze_obstacles_fragmented_inference_same_seq_len_learn_diff_seq_len_goals_conf_mat.png.
|
192
|
+
|
193
|
+
### How to add a new environment
|
194
|
+
1. bla
|
195
|
+
2. blalba
|
196
|
+
|
197
|
+
### How to add a new Learner
|
gr_libs-0.1.3/README.md
ADDED
@@ -0,0 +1,182 @@
|
|
1
|
+
# GRLib
|
2
|
+
GRLib is a python package containing implementations of Goal Recognition (GR) algorithms which use MDPs to represent the decision making process. All agents in those algorithms interact with an environment that's registered in gym API.
|
3
|
+
## Setup:
|
4
|
+
If you're on linux, great, If on windows, use git bash for the next commands to work.
|
5
|
+
1. Find where your python is installed. If you want to find where's your python3.12, you can run:
|
6
|
+
```sh
|
7
|
+
py -3.12 -c "import sys; print(sys.executable)"
|
8
|
+
```
|
9
|
+
2. Create a new empty venv from that python venv module:
|
10
|
+
```sh
|
11
|
+
C:/Users/path/to/Programs/Python/Python312/python.exe -m venv test_env
|
12
|
+
```
|
13
|
+
3. Activate the environment:
|
14
|
+
```sh
|
15
|
+
source test_env/Scripts/activate
|
16
|
+
```
|
17
|
+
4. There's no equivalent to conda env list to check the global virtual environments status, so you can verify the active one via:
|
18
|
+
```sh
|
19
|
+
echo $VIRTUAL_ENV
|
20
|
+
```
|
21
|
+
5. Install and upgrade basic package management modules:
|
22
|
+
```sh
|
23
|
+
/path/to/python.exe -m pip install --upgrade pip setuptools wheel versioneer
|
24
|
+
```
|
25
|
+
6. Install the gr_libss package (can add -e for editable mode):
|
26
|
+
```sh
|
27
|
+
cd /path/to/clone/of/GoalRecognitionLibs
|
28
|
+
pip install -e .
|
29
|
+
```
|
30
|
+
7. Install gr_libs package (can add -e for editable mode):
|
31
|
+
```sh
|
32
|
+
cd /path/to/clone/of/Grlib
|
33
|
+
pip install -e .
|
34
|
+
```
|
35
|
+
|
36
|
+
|
37
|
+
<!-- 1. Ensure you have python 3.11 installed.
|
38
|
+
If you have root permissions, simply use:
|
39
|
+
```sh
|
40
|
+
mkdir -p ~/.local/python3.11
|
41
|
+
dnf install python3.11 --prefix ~/.local/python3.11
|
42
|
+
echo 'export PATH=$HOME/.local/python3.11/bin:$PATH' >> ~/.bashrc
|
43
|
+
source ~/.bashrc
|
44
|
+
```
|
45
|
+
Else, use pyenv:
|
46
|
+
```sh
|
47
|
+
pyenv install 3.11.0
|
48
|
+
```
|
49
|
+
2. Create a new venv or use an existing 3.11 venv, and activate it. To create a new venv:
|
50
|
+
```sh
|
51
|
+
~/.pyenv/versions/3.11.0/bin/python -m venv graml_env
|
52
|
+
./Python-3.11.0/graml_env/bin/activate
|
53
|
+
```
|
54
|
+
If you're not a sudo, and you have problems with building python getting such warnings:
|
55
|
+
```sh
|
56
|
+
WARNING: The Python ctypes extension was not compiled. Missing the libffi lib?
|
57
|
+
```
|
58
|
+
That means you don't have the necesarry libraries for building python, and you probably can't change that since you're not a sudoer.
|
59
|
+
An alternative solution can be using a conda env:
|
60
|
+
```sh
|
61
|
+
conda create -n graml_env python=3.11
|
62
|
+
conda activate graml_env
|
63
|
+
```
|
64
|
+
3. Install GoalRecognitionLibs to get all needed dependencies:
|
65
|
+
```sh
|
66
|
+
git clone [GoalRecognitionLibs address]
|
67
|
+
cd GoalRecognitionLibs
|
68
|
+
pip install -e . # using the conda's pip of course
|
69
|
+
``` -->
|
70
|
+
|
71
|
+
### Issues & Problems ###
|
72
|
+
If you're not a sudo, and you have problems with building python getting such warnings:
|
73
|
+
```sh
|
74
|
+
WARNING: The Python ctypes extension was not compiled. Missing the libffi lib?
|
75
|
+
```
|
76
|
+
That means you don't have the necesarry libraries for building python.
|
77
|
+
|
78
|
+
### How to use Grlib ###
|
79
|
+
Now that you've installed the package, you have additional custom gym environments and you can start creating an ODGR scenario with the algorithm you wish to test.
|
80
|
+
The tutorial at tutorials/tutorial.py follows a simple ODGR scnenario. We guide through the initialization and deployment process following an example where GRAML is expected to adapt to new emerging goals in the point_maze gym environment.
|
81
|
+
|
82
|
+
#### Method 1: write your own script
|
83
|
+
1. create the recognizer: we need to state the base problems on which the recognizer train.
|
84
|
+
we also need the env_name for the sake of storing the trained models.
|
85
|
+
Other notable parameters include the parameters for the training of the model: For example, Graml's LSTM needs to accept input sizes the size of the concatenation of the state space with the action space.
|
86
|
+
|
87
|
+
```python
|
88
|
+
recognizer = Graml(
|
89
|
+
env_name="point_maze", # TODO change to macros which are importable from some info or env module of enums.
|
90
|
+
problems=[("PointMaze-FourRoomsEnvDense-11x11-Goal-9x1"),
|
91
|
+
("PointMaze-FourRoomsEnv-11x11-Goal-9x9"), # this one doesn't work with dense rewards because of encountering local minima
|
92
|
+
("PointMaze-FourRoomsEnvDense-11x11-Goal-1x9"),
|
93
|
+
("PointMaze-FourRoomsEnvDense-11x11-Goal-3x3"),
|
94
|
+
("PointMaze-FourRoomsEnvDense-11x11-Goal-3x4"),
|
95
|
+
("PointMaze-FourRoomsEnvDense-11x11-Goal-8x2"),
|
96
|
+
("PointMaze-FourRoomsEnvDense-11x11-Goal-3x7"),
|
97
|
+
("PointMaze-FourRoomsEnvDense-11x11-Goal-2x8")],
|
98
|
+
task_str_to_goal=maze_str_to_goal,
|
99
|
+
method=DeepRLAgent,
|
100
|
+
collect_statistics=False,
|
101
|
+
train_configs=[(SAC, 200000) for i in range(8)],
|
102
|
+
partial_obs_type="fragmented",
|
103
|
+
batch_size=32,
|
104
|
+
input_size=6,
|
105
|
+
hidden_size=8,
|
106
|
+
num_samples=20000,
|
107
|
+
problem_list_to_str_tuple=lambda problems: "_".join([f"[{s.split('-')[-1]}]" for s in problems]),
|
108
|
+
is_learn_same_length_sequences=False,
|
109
|
+
goals_adaptation_sequence_generation_method=AGENT_BASED # take expert samples in goals adaptation phase
|
110
|
+
)
|
111
|
+
```
|
112
|
+
|
113
|
+
2. The domain learning phase: In GRAML's case, the recognizer generates a dataset by training agents towards the base goals and trains an metric model combined of an LSTM on traces generated by those agents.
|
114
|
+
|
115
|
+
```python
|
116
|
+
recognizer.domain_learning_phase()
|
117
|
+
```
|
118
|
+
3. The goals adaptation phase: The recognizer receives new goals, along with configurations to the training of those agents - since the sequence generation method in this case is from an expert.
|
119
|
+
```python
|
120
|
+
recognizer.goals_adaptation_phase(
|
121
|
+
dynamic_goals_problems = ["PointMaze-FourRoomsEnvDense-11x11-Goal-4x4",
|
122
|
+
"PointMaze-FourRoomsEnvDense-11x11-Goal-7x3",
|
123
|
+
"PointMaze-FourRoomsEnvDense-11x11-Goal-3x7"],
|
124
|
+
dynamic_train_configs=[(SAC, 200000) for i in range(3)] # for expert sequence generation
|
125
|
+
)
|
126
|
+
```
|
127
|
+
4. Inference phase - this snippet generates a partial sequence by an agent trained towards one of the goals of the inference phase. Note how the trace is generated using a different agent from the recognizer's inner agents or expert (TD3 rather than SAC), and with noise added to every action to simulate suboptimal behavior.
|
128
|
+
```python
|
129
|
+
actor = DeepRLAgent(env_name="point_maze", problem_name="PointMaze-FourRoomsEnvDense-11x11-Goal-4x4", algorithm=TD3, num_timesteps=200000)
|
130
|
+
actor.learn()
|
131
|
+
full_sequence = actor.generate_observation(
|
132
|
+
action_selection_method=stochastic_amplified_selection,
|
133
|
+
random_optimalism=True, # the noise that's added to the actions
|
134
|
+
)
|
135
|
+
partial_sequence = random_subset_with_order(full_sequence, (int)(0.5 * len(full_sequence)), is_fragmented="fragmented")
|
136
|
+
closest_goal = recognizer.inference_phase(partial_sequence, maze_str_to_goal("PointMaze-FourRoomsEnvDense-11x11-Goal-4x4"), 0.5)
|
137
|
+
```
|
138
|
+
5. check the result returned by GRAML and print whether it was right or not.
|
139
|
+
```python
|
140
|
+
print(f"closest_goal returned by GRAML: {closest_goal}\nactual goal actor aimed towards: (4, 4)")
|
141
|
+
```
|
142
|
+
|
143
|
+
#### Method 2: use a configuration file
|
144
|
+
The configuraiton file consts.py holds configurations of ODGR problems.
|
145
|
+
You can either use existing ones or add new ones.
|
146
|
+
Note that using the config file, despite being easier on a large scale, some inputs to the ODGR problem are not as flexible as they would be using method 1.
|
147
|
+
For example, the sequence generation will be performed by trained agents and is non configurable. The sequences will either be completely consecutive or randomly sampled from the trace.
|
148
|
+
Example for a problem:
|
149
|
+
|
150
|
+
You can use odgr_executor.py to execute a single task:
|
151
|
+
```sh
|
152
|
+
python odgr_executor.py --recognizer MCTSBasedGraml --domain minigrid --task L1 --minigrid_env MinigridSimple
|
153
|
+
```
|
154
|
+
|
155
|
+
|
156
|
+
## Supported Algorithms
|
157
|
+
|
158
|
+
| **Name** | **Supervised** | **RL** | **Discrete** | **Continuous** | **Model-Based** | **Model-Free** | **Actions Only** |
|
159
|
+
| ------------------- | ------------------ | ------------------ | ------------------ | ------------------- | ------------------ | --------------------------------- |
|
160
|
+
| GRAQL | :x: | :heavy_check_mark: | :heavy_check_mark: | :x: | :x: | :heavy_check_mark: | :x: |
|
161
|
+
| DRACO | :x: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :x: | :heavy_check_mark: | :x: |
|
162
|
+
| GRAML | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :x: | :heavy_check_mark: | :heavy_check_mark: |
|
163
|
+
|
164
|
+
## Supported Domains
|
165
|
+
|
166
|
+
| **Name** | **Action** | **State** |
|
167
|
+
| ------------------- | ------------------ | ------------------ |
|
168
|
+
| Minigrid | Discrete | Discrete |
|
169
|
+
| PointMaze | Continuous | Continuous |
|
170
|
+
| Parking | Continuous | Continuous |
|
171
|
+
| Panda | Continuous | Continuous |
|
172
|
+
|
173
|
+
### Experiments
|
174
|
+
Given here is a guide for executing the experiments. There are benchmark domains suggested in the repository, and the 'scripts' directory suggests a series of tools to analyze them. They are defaultly set on the domains used for GRAML and GRAQL analysis during the writing of GRAML paper, but can easily be adjusted for new domains and algorithms.
|
175
|
+
1. analyze_results_cross_alg_cross_domain.py: this script runs with no arguments. it injects information from get_experiment_results_path (for example: dataset\graml\minigrid\continuing\inference_same_seq_len\learn_diff_seq_len\experiment_results\obstacles\L111\experiment_results.pkl), and produces a plot with 4 figures showing the accuracy trend of algorithms on the domains checked one against the other. Currently GRAML is checked against GRAQL or DRACO but it can easily be adjusted from within the script.
|
176
|
+
2. generate_task_specific_statistics_plots.py - this script produces, for a specific task execution (results of execution of experiments.py), a summary combined of a figure with sticks with the accuracies and confidence levels of an algorithm on the task on the varying percentages. figures\point_maze\obstacles\graql_point_maze_obstacles_fragmented_stats.png is an example of a path at which the output is dumped. Another product of this script is a confusion matrix with the confidence levels - visualizing the same data, and the output file resides in this path: figures\point_maze\obstacles\graml_point_maze_obstacles_fragmented_inference_same_seq_len_learn_diff_seq_len_goals_conf_mat.png.
|
177
|
+
|
178
|
+
### How to add a new environment
|
179
|
+
1. bla
|
180
|
+
2. blalba
|
181
|
+
|
182
|
+
### How to add a new Learner
|