-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move executable code in separate scripts and add argparse option for … #39
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5ab20a5
Move executable code in separate scripts and add argparse option for …
corentinlger a6d5f41
Fix typos in argparse
corentinlger fffe2ce
changed logging level from hardcoded to argument
Marsolo1 8febad8
Rename file with more explicit names
corentinlger 15667c6
Move executable files to scripts dir
corentinlger 0c09f4c
Add scripts in command lines instructions
corentinlger 2b7a1dd
Remove main bloc in simulator_server and panel_app
corentinlger 167b32b
Fix typo
corentinlger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -159,3 +159,4 @@ profiler_stats | |
.vscode | ||
.pylintrc | ||
myvenv/ | ||
test.ipynb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from vivarium.interface.panel_app import WindowManager | ||
|
||
# Serve the app | ||
wm = WindowManager() | ||
wm.app.servable(title="Vivarium") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import logging | ||
import argparse | ||
|
||
import numpy as np | ||
|
||
import vivarium.simulator.behaviors as behaviors | ||
from vivarium.controllers.config import SimulatorConfig, AgentConfig, ObjectConfig | ||
from vivarium.simulator.sim_computation import StateType | ||
from vivarium.simulator.simulator import Simulator | ||
from vivarium.simulator.sim_computation import dynamics_rigid | ||
from vivarium.controllers.converters import set_state_from_config_dict | ||
from vivarium.simulator.grpc_server.simulator_server import serve | ||
|
||
lg = logging.getLogger(__name__) | ||
|
||
def parse_args(): | ||
parser = argparse.ArgumentParser(description='Simulator Configuration') | ||
parser.add_argument('--box_size', type=float, default=100.0, help='Size of the simulation box') | ||
parser.add_argument('--n_agents', type=int, default=10, help='Number of agents') | ||
parser.add_argument('--n_objects', type=int, default=2, help='Number of objects') | ||
parser.add_argument('--num_steps-lax', type=int, default=4, help='Number of lax steps per loop') | ||
parser.add_argument('--dt', type=float, default=0.1, help='Time step size') | ||
parser.add_argument('--freq', type=float, default=40.0, help='Frequency parameter') | ||
parser.add_argument('--neighbor_radius', type=float, default=100.0, help='Radius for neighbor calculations') | ||
# By default jit compile the code and use normal python loops | ||
parser.add_argument('--to_jit', action='store_false', help='Whether to use JIT compilation') | ||
parser.add_argument('--use_fori_loop', action='store_true', help='Whether to use fori loop') | ||
parser.add_argument('--log_level', type=str, default='INFO', help='Logging level') | ||
|
||
return parser.parse_args() | ||
|
||
|
||
if __name__ == '__main__': | ||
args = parse_args() | ||
|
||
logging.basicConfig(level=args.log_level.upper()) | ||
|
||
simulator_config = SimulatorConfig( | ||
box_size=args.box_size, | ||
n_agents=args.n_agents, | ||
n_objects=args.n_objects, | ||
num_steps_lax=args.num_steps_lax, | ||
dt=args.dt, | ||
freq=args.freq, | ||
neighbor_radius=args.neighbor_radius, | ||
to_jit=args.to_jit, | ||
use_fori_loop=args.use_fori_loop | ||
) | ||
|
||
agent_configs = [AgentConfig(idx=i, | ||
x_position=np.random.rand() * simulator_config.box_size, | ||
y_position=np.random.rand() * simulator_config.box_size, | ||
orientation=np.random.rand() * 2. * np.pi) | ||
for i in range(simulator_config.n_agents)] | ||
|
||
object_configs = [ObjectConfig(idx=simulator_config.n_agents + i, | ||
x_position=np.random.rand() * simulator_config.box_size, | ||
y_position=np.random.rand() * simulator_config.box_size, | ||
orientation=np.random.rand() * 2. * np.pi) | ||
for i in range(simulator_config.n_objects)] | ||
|
||
state = set_state_from_config_dict({StateType.AGENT: agent_configs, | ||
StateType.OBJECT: object_configs, | ||
StateType.SIMULATOR: [simulator_config] | ||
}) | ||
|
||
simulator = Simulator(state, behaviors.behavior_bank, dynamics_rigid) | ||
lg.info('Simulator server started') | ||
serve(simulator) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import argparse | ||
import logging | ||
|
||
import numpy as np | ||
|
||
from vivarium.simulator import behaviors | ||
from vivarium.simulator.sim_computation import dynamics_rigid, StateType | ||
from vivarium.controllers.config import AgentConfig, ObjectConfig, SimulatorConfig | ||
from vivarium.controllers import converters | ||
from vivarium.simulator.simulator import Simulator | ||
|
||
lg = logging.getLogger(__name__) | ||
|
||
def parse_args(): | ||
parser = argparse.ArgumentParser(description='Simulator Configuration') | ||
# Experiment run arguments | ||
parser.add_argument('--num_loops', type=int, default=10, help='Number of simulation loops') | ||
# Simulator config arguments | ||
parser.add_argument('--box_size', type=float, default=100.0, help='Size of the simulation box') | ||
parser.add_argument('--n_agents', type=int, default=10, help='Number of agents') | ||
parser.add_argument('--n_objects', type=int, default=2, help='Number of objects') | ||
parser.add_argument('--num_steps_lax', type=int, default=4, help='Number of lax steps per loop') | ||
parser.add_argument('--dt', type=float, default=0.1, help='Time step size') | ||
parser.add_argument('--freq', type=float, default=40.0, help='Frequency parameter') | ||
parser.add_argument('--neighbor_radius', type=float, default=100.0, help='Radius for neighbor calculations') | ||
# By default jit compile the code and use normal python loops | ||
parser.add_argument('--to_jit', action='store_false', help='Whether to use JIT compilation') | ||
parser.add_argument('--use_fori_loop', action='store_true', help='Whether to use fori loop') | ||
parser.add_argument('--log_level', type=str, default='INFO', help='Logging level') | ||
|
||
return parser.parse_args() | ||
|
||
|
||
if __name__ == "__main__": | ||
args = parse_args() | ||
|
||
logging.basicConfig(level=args.log_level.upper()) | ||
|
||
simulator_config = SimulatorConfig( | ||
box_size=args.box_size, | ||
n_agents=args.n_agents, | ||
n_objects=args.n_objects, | ||
num_steps_lax=args.num_steps_lax, | ||
dt=args.dt, | ||
freq=args.freq, | ||
neighbor_radius=args.neighbor_radius, | ||
to_jit=args.to_jit, | ||
use_fori_loop=args.use_fori_loop | ||
) | ||
|
||
agent_configs = [ | ||
AgentConfig(idx=i, | ||
x_position=np.random.rand() * simulator_config.box_size, | ||
y_position=np.random.rand() * simulator_config.box_size, | ||
orientation=np.random.rand() * 2. * np.pi) | ||
for i in range(simulator_config.n_agents) | ||
] | ||
|
||
object_configs = [ | ||
ObjectConfig(idx=simulator_config.n_agents + i, | ||
x_position=np.random.rand() * simulator_config.box_size, | ||
y_position=np.random.rand() * simulator_config.box_size, | ||
orientation=np.random.rand() * 2. * np.pi) | ||
for i in range(simulator_config.n_objects) | ||
] | ||
|
||
state = converters.set_state_from_config_dict( | ||
{ | ||
StateType.AGENT: agent_configs, | ||
StateType.OBJECT: object_configs, | ||
StateType.SIMULATOR: [simulator_config] | ||
} | ||
) | ||
|
||
|
||
simulator = Simulator(state, behaviors.behavior_bank, dynamics_rigid) | ||
|
||
lg.info("Running simulation") | ||
|
||
simulator.run(threaded=False, num_loops=10) | ||
|
||
lg.info("Simulation complete") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -279,6 +279,7 @@ def set_callbacks(self): | |
self.update_switch.param.watch(self.update_switch_cb, "value") | ||
self.update_timestep.param.watch(self.update_timestep_cb, "value") | ||
|
||
# Serve the app | ||
wm = WindowManager() | ||
wm.app.servable(title="Vivarium") | ||
# if __name__ == "__main__": | ||
# # Serve the app | ||
# wm = WindowManager() | ||
# wm.app.servable(title="Vivarium") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe remove these commented lines? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed I forgot to remove the
main
bloc in some old files, thanks for noticing !