Skip to content

Commit

Permalink
Update Readme and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
corentinlger committed Feb 13, 2024
1 parent 46264d5 commit c333e02
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 17 deletions.
4 changes: 2 additions & 2 deletions MultiAgentsSim/two_d_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import jax.numpy as jnp
from jax import random, jit
from flax import struct
import matplotlib
matplotlib.use('Qt5Agg')
import matplotlib.pyplot as plt

from MultiAgentsSim.base import Simulation, SimState
Expand Down Expand Up @@ -49,8 +51,6 @@ def step(self, sim_state, actions, key):
sim_state = sim_state.replace(time=time, x_pos=x_pos, y_pos=y_pos)
return sim_state


# TODO : See if I had if conditions to check wether the idx is valid or not, or if I jit the function
def add_agent(self, sim_state, agent_idx):
sim_state = sim_state.replace(alive=sim_state.alive.at[agent_idx].set(1.0))
print(f"agent {agent_idx} added")
Expand Down
47 changes: 42 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,48 @@
# SimulationSandbox

Minimalistic simulation environment with simple server-client interaction.
Minimalistic simulation environment with simple server-client interaction. Enables modifying the simulation state in real time from notebook controllers, and plotting the state on distant clients.

## TODO
## Install

- Better understand how to do clean socket classes
Get the repo :

- Put colors inside agents state
```bash
git clone [email protected]:corentinlger/SimulationSandbox.git
cd SimulationSandox/
```

- Add static objects
Setup a virtual environment and install the dependencies :

```bash
python3 -m venv myvenv
source myvenv/bin/activate
pip install -r requirements.txt
```

## Usage

You can run a simulation on your machine (using either the 2D or 3D envs):

```bash
python3 simulate.py
```

Or host it on a server :

```bash
python3 server.py
```

Visualize it on distant clients :

```bash
python3 client.py
```

And modify the state of the simulation using [this notebook client](notebook_controller.ipynb)

## TODO :

- Stop the atrocious popping up of matplotlib interactive figures
- Replace sending the first example state with pickle by generating it on the client side
- Further check the interaction between 3D sim and notebook client
29 changes: 19 additions & 10 deletions notebook_controller.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 100,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -27,7 +27,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 101,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -43,7 +43,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 102,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -66,7 +66,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 104,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -94,16 +94,24 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 105,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Connected to ('localhost', 5050)\n"
]
}
],
"source": [
"client, state_example, state_bytes_size = connect_client()"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 106,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -112,16 +120,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 108,
"metadata": {},
"outputs": [],
"source": [
"set_color(client, 0, 'r', state_example, state_bytes_size)"
"# Apply this function with whatever agent_idx or color\n",
"set_color(client, 2, 'b', state_example, state_bytes_size)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 109,
"metadata": {},
"outputs": [],
"source": [
Expand Down

0 comments on commit c333e02

Please sign in to comment.