This tutorial demonstrates how to use Alchemist-SAPERE through a sequence of working examples and increasingly challenging exercises.
Introductory material on simulation concepts and the rationale behind the development of Alchemist and its SAPERE incarnation is available here (PDF).
Further information on writing simulations in Alchemist can be found on the official website.
Alchemist requires a working installation of Java Runtime Environment 17 or newer. We recommend using the latest LTS OpenJDK from Adoptium.
If running via Docker, you do not need to install the JDK.
Instead, ensure that both Docker and Docker Compose are installed.
On macOS and Windows, an X Window System is required to display the simulation interface:
To run the project with Docker:
docker-compose up
You can specify the simulation to be run via the docker-compose.yml file.
This project uses the Gradle Build Tool.
You don’t need to install Gradle — the provided launch script will download the correct version automatically.
To launch a simulation named SIMNAME, a file named SIMNAME.yml must be located in the src/main/yaml directory.
Gradle will automatically generate a task for each simulation file, which you can run as follows:
./gradlew SIMNAME
If an effect file named SIMNAME.json is present in the effects/ folder, it will be automatically loaded.
Note
The environment variableCIis used to determine whether the task is running in a headless continuous integration environment.
IfCI=trueis set, the graphical interface will not be launched.
Use the provided simulation files and the documentation on the official Alchemist website to complete the following exercises:
- Refer to:
- Add two nodes to an empty, continuous environment and ensure they are connected.
- Create 10,000 nodes randomly placed inside a circle centered at (0,0) with radius 10.
- Create a regular grid of nodes from (-5,-5) to (5,5) spaced by (0.25, 0.25), without perturbation.
- Create a perturbed version of the grid from Exercise 3.
- Insert
{token}LSAs in some nodes. - Implement a "dodgeball" program.
- Use YAML to write custom sections and refer to them.
- Modify the dodgeball program to count passes within the LSA.
- Implement an LSA diffusion program so that all nodes eventually contain the
{token}LSA using the*operator. - Open
10-math.yml, experiment with it, and manually move nodes around. - Write a gradient propagation program that:
- Converts
{source}into{gradient, 0}(keep the source). - Diffuses the gradient to neighbors, incrementing the value by
#D. - Keeps only the lowest gradient value if multiple copies exist.
- Ages the gradient value periodically.
- Deletes gradients with values exceeding a threshold (e.g., 20).
- Converts
- Review
12-sets.ymland observe the behavior of set arithmetic. - Modify Exercise 12 to use a custom time distribution (e.g., a
DiracCombwith parameter 0.5). - Review
14-yaml.vars.ymland understand the variable system. - Open
15-move.yml, run it, and experiment with its parameters. - Run
16-maps.yml(note: first run may take time). Observe complex scenario capabilities, modify as desired, and reflect on results.