This package is a Python wrapper for the differentiable simulator Dojo.
- arXiv preprint: https://arxiv.org/abs/2203.00806
- site: https://sites.google.com/view/dojo-sim
- video presentation: https://youtu.be/TRtOESXJxJQ
Included are interfaces to PyTorch and JAX.
This example simulates a pendulum for 1 time step.
import dojopy
from julia import Base
from julia import Dojo as dojo
# get an environment
env = dojo.get_environment('pendulum')
dojo.initialize_pendulum_b(env.mechanism, angle=0.0, angular_velocity=0.0)
# get state
x1 = dojo.get_minimal_state(env.mechanism)
# random control
u1 = Base.rand(nu)
# simulate one time step
dojo.step(env, x1, u1)
Using Dojo
with Python requires a number of installations in addition to dojopy
. Below are two options for installing all dependencies.
- Clone this repository:
git clone https://github.com/dojo-sim/dojopy
-
Install Docker (https://docs.docker.com/engine/install/)
-
Enter the repository folder, build the Dockerfile and tag the image as
dojopy
: (this step may take a few minutes)
cd dojopy
docker build --tag dojopy .
- Open a bash shell in your Docker container
docker run -it -v /absolute/path/to/dojopy:/dojopip dojopy bash
(-v /absolute/path/to/dojopy:/dojopip
allows you to synchronize files from your folder /absolute/path/to/dojopy
to your docker image)
- You can now run dojopy inside your Docker image! Inside the shell of your Docker image opened in step 4., run
python3 quick_start.py
Calling Dojo from Python requires:
- dojopy: this wrapper
- Julia v1.6
- Dojo.jl: the actual simulator
- PyCall: interface between Julia and Python
- custom Python binary: this is required to make calls to Dojo fast and efficient
Below we walk through each of the required installation steps:
Get dojopy
- Clone this repository:
git clone https://github.com/dojo-sim/dojopy
(for now, soon via pip)
Custom Python installation
To make calls from Python to Dojo
efficient requires a custom Python installation.
-
Install
pyenv
-
Use
pyenv
to build your own PythonIn
~/.pyenv
run:PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install 3.6.6
to create a custom binary.
- We call this python binary the
custom_python
. It's located atpath/to/custom_python
e.g.,/home/user/.pyenv/versions/3.6.6/bin/python3
- This step is needed because PyJulia cannot be initialized properly out-of-the-box when Python executables are statically linked to libpython. This is the case if you use Python installed with Debian-based Linux distribution such as Ubuntu or installed Python via conda. More details about this here.
- We call this python binary the
-
(Optional, Recommended) Create a virtual environment linked to
custom_python
- In your shell run:
path/to/custom_python -m venv /path/to/new/virtual/environment/my_env
Julia installation
-
Install the Julia programming language (
v1.6
recommended) [Julia Download page] -
Install
PyCall
- Specify the Python version to be the
custom_python
.- e.g.
ENV["PYTHON"] = "/home/user/.pyenv/versions/3.6.6/bin/python3"
Pkg.build("PyCall")
- e.g.
- Specify the Python version to be the
-
Open the Julia REPL and install the Julia package
Dojo.jl
:(type ])
:
pkg> add Dojo
Python setup
-
In your virtual environment, install:
pyjulia
, the interface that lets you call Julia code from Python.- Activate your virtual environement, then run:
python3 -m pip install julia
-
In Python run:
import julia
julia.install()
to finish the pyjulia
setup.
We can now call Dojo from Python!
See the Documentation for using Dojo.
When Dojo is called from a python script, e.g. python3 ...
Julia will just-in-time compile the solver code which will slow down the overall execution. For larger problems it is advisable to solve a mini problem first to trigger the JIT-compilation and get full performance on the subsequent solve of the actual problem .
This project is licensed under the MIT License - see the LICENSE.md file for details.
@article{howelllecleach2022,
title={Dojo: A Differentiable Simulator for Robotics},
author={Taylor, A. Howell and Le Cleac'h, Simon and Kolter, Zico and Schwager, Mac and Manchester, Zachary},
journal={arXiv preprint arXiv:2203.00806},
url={https://arxiv.org/abs/2203.00806},
year={2022}
}
Please submit a pull request, open an issue, or reach out to: [email protected] (Taylor) or [email protected] (Simon)