Unity
From Robin
(→Unity timing / indeterminism fixing (how to get your simulator deterministic)) |
(→Unity timing / indeterminism fixing (how to get your simulator deterministic)) |
||
Line 38: | Line 38: | ||
The Open Dynamic Robot Initiative Quadruped package can be imported into Unity by going to Assets->Import Package->Custom Package. It requires ML agents version 1.0.7. | The Open Dynamic Robot Initiative Quadruped package can be imported into Unity by going to Assets->Import Package->Custom Package. It requires ML agents version 1.0.7. | ||
- | == | + | == Notes on deterministic behavior == |
[[Unity-Timing-David | David's tips on getting deterministic timing]] | [[Unity-Timing-David | David's tips on getting deterministic timing]] |
Revision as of 14:07, 27 October 2022
Contents |
Installation
- Download and install Unity : unity.com
For coding in Unity and Python it is recommended to use Visual Studio Code but you can of course use your preferred IDE and editor.
- Install Unity ML-Agents
In the Unity editor, go to window->package manager. Inside the package manager search for ML agents in the Unity Registry. Install the most recent ML Agents package.
Documentation
Unity ML-Agents Github Page Unity Documentation
Using Unity ML-Agents
- Build a standalone Unity Executable
You can run a Unity build (executable) from the Unity ML agents python scripts where this build is a standalone version of the game (robot simulation). You will have to create this build from the Unity editor using by adding an active scene (the scene that contains the ML agent) to the Scenes in build. It is explained in more detail here.
3. Using the python scripts
The 4 python scripts included in this repository are the bare minimum of what you would need to run a standard evolutionary algorithm. To get started, make sure to make a virtual environment and install the python packages from the requirements.txt. You can find more information on how to do this here
3.1 UnityMLInterface The Unity ML agents script contains code that allows you to open a Unity executable of your project and send motor commands to the environment. Note that you will have to change the PATH variable to point to your standalone build of the robot simulation.
3.2 EvolutionaryAlgorithm The Evolutionary Algorithm script contains a minimal example of how you can Distributed Evolutionary Algorithms in Python (DEAP). You will have to pass references of the environment, the evaluation function, the individual, and the controller to the evolutionary algorithm.
ea = EvolutionaryAlgorithm.EvolutionaryAlgorithm(env, evaluate,EvolutionaryAlgorithm.Individual, SmallWorldNeuralNetwork.SmallWorldNeuralNetwork) 3.3 SmallWorldNeuralNetwork The SmallWorldNeuralNetwork is a simple type of neural network that can be evolved using the evolutionary algorithm. The network serves as an example but have a look at it to hack in your own type of controller.
3.4 EvolvingUnityMLAgents The EvolvingUnityMLAgents script combines the above implementations to evolve the behavior of the robot. This example runs on a single thread and will have to be turned into a multithreaded solution for your experiments.
3.5 Unity ODRI package The Open Dynamic Robot Initiative Quadruped package can be imported into Unity by going to Assets->Import Package->Custom Package. It requires ML agents version 1.0.7.