This package is a Python wrapper for the differentiable simulator Dojo.
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.
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:
Below we walk through each of the required installation steps:
Get dojopy
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 Python
In ~/.pyenv
run:
PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install 3.6.6
to create a custom binary.
custom_python
. It's located at path/to/custom_python
e.g., /home/user/.pyenv/versions/3.6.6/bin/python3
(Optional, Recommended) Create a virtual environment linked to custom_python
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
custom_python
.
ENV["PYTHON"] = "/home/user/.pyenv/versions/3.6.6/bin/python3"
Pkg.build("PyCall")
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.
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: thowell@stanford.edu (Taylor) or simonlc@stanford.edu (Simon)