diff --git a/documentation/GUI_description_1.jpg b/documentation/GUI_description_1.jpg new file mode 100644 index 0000000000000000000000000000000000000000..f43f90287ae52c1053b5f30c916b2d9a3b172320 Binary files /dev/null and b/documentation/GUI_description_1.jpg differ diff --git a/documentation/GUI_description_2.jpg b/documentation/GUI_description_2.jpg new file mode 100644 index 0000000000000000000000000000000000000000..69d573416f07c978cff3173c1e19a8d136f57ede Binary files /dev/null and b/documentation/GUI_description_2.jpg differ diff --git a/documentation/gui.md b/documentation/gui.md index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..bcc8913fe6a20feb3d35273d3cd4dcfde7d54317 100644 --- a/documentation/gui.md +++ b/documentation/gui.md @@ -0,0 +1,3 @@ +# GUI description + + \ No newline at end of file diff --git a/documentation/py4j.md b/documentation/py4j.md new file mode 100644 index 0000000000000000000000000000000000000000..19bcf82b9b08de5529e3ee4f2f86fd0814728dd4 --- /dev/null +++ b/documentation/py4j.md @@ -0,0 +1,11 @@ +# Using Py4j +[Py4j](https://www.py4j.org/) is a Python/Java tool allowing control java code with python. + +Demos are available in the [py4j_demo](py4j_demo) directory. + +A minimalistic main is provided at `py4j.Main.java`. Please note that py4j use socket, so only one process of that main can be executed at a given time. You can have multiple amoeba on a same process, but only one GUI on the same process. If you need to launch multiple amoebas with GUI at a same time, check py4j official documentation on how to change sockets. + +To compile AMOEBA as an executable jar with this main, do : +``` +mvn clean compile assembly:single -Dmain.class=py4j.Main +``` \ No newline at end of file diff --git a/documentation/py4j_demo/README.md b/documentation/py4j_demo/README.md new file mode 100644 index 0000000000000000000000000000000000000000..a4b64cc9539e079618c23c5c48df8dbd6a579809 --- /dev/null +++ b/documentation/py4j_demo/README.md @@ -0,0 +1,30 @@ +# Install : +Install python dependencies : +``` +pip3 install requirements.txt +``` +Optional : check [openai gym](https://gym.openai.com/) documentation for a full install. + +Run the setup script [setup.sh](setup.sh) (linux only) + +You're good to go, check that py4j is correctly working with [basic_demo.py](basic_demo.py) : +``` +python3 basic_demo.py +``` +You should get the classic amoeba's GUI, and random context appearing. + +Then you can look at some actual learning, inside [learn_gym.py](learn_gym.py). + + +# Optional : Ros2Learn +[Ros2Learn](https://github.com/AcutronicRobotics/ros2learn) provide some tools for machine learning on robots, using Ros2, openAI gym, and gazebo. + +Install Ros2 and Ros2learn, follow Ros2Learn instruction. Make sure your version of gazebo is at least 9.9. + +In your python script, import gym_gazebo2. Before running your python code make sure that you properly loaded Ros2 and Ros2learn environment using their provision scripts. + +You can now use gym environment provided by Ros2learn as regular gym environment. +```Python +env = gym.make('MARA-v0') +``` + diff --git a/documentation/py4j_demo/learn_gym.py b/documentation/py4j_demo/learn_gym.py index d21dcae6757358d86309c8bf21068a9c7cca1b70..ffc206c3186b3bcdc945bb21e877a2d40d82e764 100644 --- a/documentation/py4j_demo/learn_gym.py +++ b/documentation/py4j_demo/learn_gym.py @@ -1,6 +1,6 @@ import os import gym -import gym_gazebo2 +#import gym_gazebo2 import subprocess import time import math diff --git a/documentation/save_system.md b/documentation/save_system.md new file mode 100644 index 0000000000000000000000000000000000000000..4219c489f00ceb30e162ed33cdf81f37300279d7 --- /dev/null +++ b/documentation/save_system.md @@ -0,0 +1,54 @@ +#The Save System +The save system is composed of two main elements, and some GUI elements : + +## The Backup System : +Found in `kernel.backup`. + +A backup system is an object responsible for reading/writing the state of amoeba from/to a file. It implement the interface `IBackupSystem`. The implementation provided is `BackupSystem` and use xml to store data. + +Usage : +```Java +AMOEBA amoeba = new AMOEBA() +IBackupSystem backupSystem = new BackupSystem(amoeba); +backupSystem.load(new File("path/to/a/save.xml")); +// do some learning with the amoeba ... +backupSystem.save(new File("path/to/a/new/file.xml")) +``` + +## The Save Helper : +Found in `kernel.backup`. + +A save helper is an object that provide additional functionality over a BackupSystem for the user or other components. Most importantly it : +- Create a temporary directory for saves +- Allow automatic saving during amoeba execution +- Add the options to save/load on the GUI +- Add functionality used by the SaveExplorer. + +See `ISaveHelper` for more. + +Two implementation are provided : the fully functioning `SaveHelperImpl` and `SaveHelperDummy` that do nothing. The dummy is used to deactivate ALL automatic saving, giving a HUGE performance boost. + +Each amoeba has a save helper, available with `amoeba.saver` +```Java +AMOEBA amoeba = new AMOEBA(); +// This constructor initialize the amoeba's saver with a dummy, meaning : +amoeba.saver.save("this_does_not_save"); +// will do nothing + +// or ... +AMOEBA amoeba = new AMOEBA("path/to/save.xml", null); +// This constructor create and use a SaveHelperImpl to initilize the amoeba +amoeba.saver.save("a/valid/path/save.xml"); +// will create a save, and +amoeba.saver.autosave(); +// will create a save in the temporary directory creates by the save helper, located in +System.out.println(SaveHelperImpl.dir) +``` +If amoeba crash, the save files will not be automatically deleted, you may have to manually clean the save directory. + +## The Save Explorer +Found in `gui.saveExplorer`. + +The save explorer read saves from an amoeba's SaveHelper and offer some graphical tool, most importantly the ability to preview a save and quickly cycle trough saves. Allowing to visually play back the execution of an amoeba. + +See the [GUI description](gui.md) for more detail on the GUI. diff --git a/documentation/usage.md b/documentation/usage.md index 352759c9a5788a13213e84dabdc1dcac627f1b07..b7235148d0d75d1ce59ae9429eb6fd0dcb84c012 100644 --- a/documentation/usage.md +++ b/documentation/usage.md @@ -16,7 +16,7 @@ Depending on your problem, determine what AMOEBA should learn, and from what. Bu A config file is a xml file used to initialize your amoeba. Most importantly it contain the list of percepts. You can use `utils/genFiles.py` to generate your xml file based on a list of percept. `python genFiles.py MySystem false px py` will create `MySystem.xml` (and `MySystem.msg`, but ignore it if you don't use [AMOEBA and ROS](rosbridge.md)) containing something looking like the following example : - +(if you don't want to use python, a java class doing the same job is available at `utils.XmlConfigGenerator`) ```xml <?xml version="1.0" encoding="UTF-8"?> <System> @@ -144,6 +144,6 @@ public static void main(String[] args) { } } ``` -We can ask amoeba how well it performed on the last prediction with `amoeba.getHeads().get(0).getCriticity()`. +We can ask amoeba how well it performed on the last prediction with `amoeba.getHeadAgent().getCriticity()`. For more example on how to use amoeba, check `AdvancedMain.java`, `MinimalMain.java`, and `Main.java` in the `experiments` package. \ No newline at end of file