Skip to content

Commit

Permalink
Rename visualize_sim render
Browse files Browse the repository at this point in the history
  • Loading branch information
corentinlger committed Apr 29, 2024
1 parent a836897 commit 2369589
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 13 deletions.
4 changes: 2 additions & 2 deletions client.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def receive_loop():
i += 1
raw_data = client.recv(state_bytes_size)
state = serialization.from_bytes(state_example, raw_data)
Simulation.visualize_sim(state)
Simulation.render(state)

except socket.error as e:
print(e)
Expand All @@ -50,7 +50,7 @@ def test():
i += 1
raw_data = client.recv(state_bytes_size)
state = serialization.from_bytes(state_example, raw_data)
Simulation.visualize_sim(state)
Simulation.render(state)
client.close()

print(f"{i = } : {i / EVAL_TIME } data received per second")
Expand Down
2 changes: 1 addition & 1 deletion simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def main():
state = sim.step(state, step_key)

if args.visualize:
Simulation.visualize_sim(state)
Simulation.render(state)
print("\nSimulation ended")

if __name__ == "__main__":
Expand Down
11 changes: 5 additions & 6 deletions simulationsandbox/environments/lake_env.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
# TODO : Créer un aquarium env en jax
# TODO : Ensure the agents do not spawn in the lake
# TODO : Change the init of lake
# TODO : Add more elements to the environment
# TODO : Maybe test particle based with different speeds on earth / lake


from functools import partial

Expand All @@ -28,6 +23,10 @@ class Agents:
obs: jnp.array


class Object:
pos: jnp.array


@struct.dataclass
class LakeEnvState(BaseEnvState):
time: int
Expand Down Expand Up @@ -135,7 +134,7 @@ def remove_agent(self, state, agent_idx):
return state

@staticmethod
def visualize_sim(state):
def render(state):
if not plt.fignum_exists(1):
plt.ion()
plt.figure(figsize=(10, 10))
Expand Down
2 changes: 1 addition & 1 deletion simulationsandbox/environments/three_d_example_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def get_env_params(self):
return self.grid_size, self.max_agents

@staticmethod
def visualize_sim(state):
def render(state):
if not plt.fignum_exists(1):
plt.ion()
fig = plt.figure(figsize=(10, 10))
Expand Down
2 changes: 1 addition & 1 deletion simulationsandbox/environments/two_d_example_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def get_env_params(self):
return self.grid_size, self.max_agents

@staticmethod
def visualize_sim(state):
def render(state):
if not plt.fignum_exists(1):
plt.ion()
plt.figure(figsize=(10, 10))
Expand Down
4 changes: 2 additions & 2 deletions tests/test_run_sims.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_simple_simulation_run():
state = sim.step(state, actions, step_key)

if VIZUALIZE:
TwoDEnv.visualize_sim(state)
TwoDEnv.render(state)
print("\nSimulation ended")

assert jnp.sum(state.alive) == 5
Expand Down Expand Up @@ -93,7 +93,7 @@ def test_three_d_simulation_run():
state = sim.step(state, actions, step_key)

if VIZUALIZE:
ThreeDEnv.visualize_sim(state)
ThreeDEnv.render(state)

plt.close()
print("\nSimulation ended")
Expand Down

0 comments on commit 2369589

Please sign in to comment.