This project implements an evolutionary robotics pipeline where robot morphologies are evolved using a grammar-based evolutionary algorithm and evaluated in PyBullet. The system supports running experiments locally, inside a Docker container, and within a Conda environment.
The repository contains:
- experiment scripts to evolve and evaluate robots
- a PyBullet simulation environment (flat plane and Mars terrain)
- integration with a grammar-based evolutionary algorithm (SGE3 / DSGE-style workflow)
- utilities for running and resuming experiments from checkpoints
At a high level, the pipeline follows this loop:
- Grammar-based evolution generates candidate robot “individuals” (morphology encoded by a grammar).
- Each individual is materialized (e.g., URDF robot) and evaluated in PyBullet.
- The evaluation produces fitness metrics (distance traveled, stability, etc.).
- Evolution uses the fitness to create the next generation (selection + variation).
- The process repeats, and results/checkpoints are stored on disk.
-
PyBullet Simulation
-
Robots are loaded as URDFs and evaluated in physics simulation.
-
For this project, supports different terrains:
- Flat plane
- Mars terrain (mesh-based)
-
-
Grammar-based Evolution Algorithm
- This project uses the SGE3 implementation by Nuno Lourenço as the evolutionary engine. The SGE3 README already documents the algorithm, operators, and configuration format, so this repository focuses on how SGE3 is applied to evolving robots and running physics-based evaluations.
You can run this project either:
- inside Docker (recommended for reproducibility), or
- locally with Conda.
- Python 3.10
- PyBullet
- gymnasium
- stable-baselines3 (if running PPO-based controllers or evaluation scripts)
- numpy, pyyaml, etc.
Tip: keep
PYTHONNOUSERSITE=1when debugging to avoid mixing system Python packages with the conda environment.
- Create / activate your conda environment (example):
conda create -n ppo5090 python=3.10 -y
conda activate ppo5090- Install dependencies:
pip install pybullet gymnasium numpy pyyaml
pip install stable-baselines3 # optional, only if you run PPO scripts- Run an experiment (example) ( mars has to be 1 to be activated, 0 to be not activated ):
PYTHONUNBUFFERED=1 PYTHONPATH=/workspace \
python -m sge_FOR_ER.sge.examples.Test_Robots \
--experiment_name dumps/example \
--seed 42 \
--parameters ../parameters/standard.yml
--mars 1This repository can be used in a Docker workflow. Typical setup:
- Build the image (or use your existing image)
- Run a container with the repo mounted
- Activate the conda environment inside the container
- Run the same
python -m ...command
Example structure (adjust to your Dockerfile / image):
docker run -d --gpus "device=2" \
-v "$(pwd)":/workspace \
--name "(name of the docker)" \
ppo5090:test2 \
bash -c "sleep infinity"
docker exec -it "(name of the docker)" bashThen inside:
source /opt/conda/etc/profile.d/conda.sh
conda activate ppo5090
PYTHONUNBUFFERED=1 PYTHONPATH=/workspace \
python -m sge_FOR_ER.sge.examples.Test_Robots \
--experiment_name dumps/example \
--seed 42 \
--parameters ../parameters/standard.yml
--mars 1This project uses Mars terrain assets sourced from the mars_gazebo repository. Specifically, the following files are reused:
mars.worldmars_topografi.daemars_topografi.objmaterial.mtlmaterial_0.pngmodel_texture.jpg
Upstream source: aunefyren/mars_gazebo (GitHub). (GitHub)
These assets are used to generate/load a Mars-like surface for simulation, enabling more realistic traction and stability tests compared to a flat plane.
The mars.world file contains absolute file:///... URIs for mars_topografi.dae (e.g., lines around 33 and 40). You must update those entries to match your local file path.
Example line to edit:
file:///home/your-user/path/to/mars_topografi.dae
Recommended alternatives:
Replace the absolute path with the correct absolute path on your machine, or
Prefer a setup using relative paths + proper search paths, if your simulator tooling supports it.
If mars.world is not updated, terrain loading may fail with PyBullet errors like “failed to parse link” / “Cannot load SDF file.”
The grammar-based evolutionary algorithm is provided by:
nunolourenco/sge3(Dynamic / Structured Grammatical Evolution in Python 3). (GitHub)
Since this project uses SGE3 as a dependency/base, its upstream README is the reference for:
- algorithm details
- parameter configuration
- recommended citations / references
Experiments typically write results under a dumps/ directory (or similar), including:
- per-run folders (e.g.,
run_1/) - iteration checkpoint files (e.g.,
iteration_40.json) - generated robots (URDFs) and logs depending on configuration
If you support resume, you can load the latest checkpoint automatically by selecting the highest iteration_<N>.json in the run folder(s).
On some Linux setups, PyBullet GUI can fail due to OpenGL / Mesa driver resolution when using Conda (Conda may override system C++ runtime libraries). If you get a black window or “failed to create an OpenGL context”, a reliable workaround is to set these environment variables before running (terminal or PyCharm):
PYTHONUNBUFFERED=1
PYTHONNOUSERSITE=1
DISPLAY=:1
LIBGL_DRIVERS_PATH=/usr/lib/x86_64-linux-gnu/dri
LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libstdc++.so.6
PYTHONPATH=.Important: use PYTHONPATH=. (project root) instead of a full absolute path. This avoids hardcoding usernames/paths and makes the project more portable. Then run your script as usual.
If loading SDF/mesh assets fails, ensure:
- mesh paths are correct (prefer relative paths +
setAdditionalSearchPath) - the process working directory is your repo root
- the relevant files exist on disk
- Mars terrain assets adapted from
aunefyren/mars_gazebo. (GitHub) - Evolution engine based on
nunolourenco/sge3Structured/Dynamic Structured Grammatical Evolution. (GitHub)
Add your license here (e.g., MIT, Apache-2.0, GPL, or “All rights reserved”). If you are redistributing assets/code from other repositories, ensure license compatibility and include required notices.