Skip to content
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 8 commits into from
Mar 13, 2024

Conversation

corentinlger
Copy link
Collaborator

@corentinlger corentinlger commented Mar 11, 2024

…configs

Description

Aims to enhance the organization and usability of the project by restructuring executable scripts and integrating argparse functionality.

Firstly, it relocates executable parts of files in the vivarium directory to the root directory, separating source code from execution scripts for improved clarity and ease of use. For instance, the main execution logic currently embedded within individual files like vivarium/simulator/simulator.py, vivarium/simulator/grpc_server/simulator_server.py and vivarium/interface/panel_app.py are moved to dedicated scripts named simulate.py (to run simulations without server mode, on a cluster of GPUs for example), run_server.py and interface_app.py (removed panel from the name as we discussed), respectively. This reorganization simplifies command-line usage for script execution

Secondly, argparse options are added to executable scripts to define default simulation parameters and enable command-line parameter customization. It allows for easy adjustment of simulation parameters such as max number of agents, box size, and physics parameters without necessitating code modifications in various files. At the moment I only implemented it for the simulator_config, but it could be useful for other arguments as discussed in #35 (especially if we launch simulations in GPU clusters where we don't have access to an IDE).

@Marsolo1 also added an option for the logging level to set it with argparse (with a default value of INFO). This way we only define it in the script we run instead of doing so in all the files from which we import functions/classes to run the script.

I also renamed the executable files with more explicit names (starting with 'run'):

interface_app.py --> run_interface.py
simulate.py --> run_simulation.py

After a discussion with Clément Romac, I decided to put all the executable script in a directory named scripts to make the organization of the project cleaner.

For example if you want to run a simulation with 20 agents and 5 objects in a server, run :

python3 scripts/run_server.py --n_agents 20 --n_objects 5

Related Issue (if applicable)

#38

How to Test (!! This has been modified !!)

Launch the server

python3 scripts/run_server.py

Launch the Panel interface

panel serve scripts/run_interfacepy --autoreload

Copy link
Collaborator

@Marsolo1 Marsolo1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works fine for me

Copy link
Collaborator

@clement-moulin-frier clement-moulin-frier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works great, well done :) I pointed to a few issues in the code, please solve them and then you can directly merge. Also, I recommend that we remove the main bloc at the end of the files when this code is already in the new scripts (better to avoid code duplication). I think it concerns simulator.py and simulator_server.py. But let me know if you don't agree

README.md Outdated
```

### Interact with it from a web interface

And launch the web interface from another terminal :

```bash
panel serve vivarium/interface/panel_app.py --autoreload
panel serve scrits/run_interface.py --autoreload
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

Copy link
Collaborator Author

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 !

Comment on lines 282 to 285
# if __name__ == "__main__":
# # Serve the app
# wm = WindowManager()
# wm.app.servable(title="Vivarium")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe remove these commented lines?

@corentinlger corentinlger merged commit 37499d5 into main Mar 13, 2024
2 checks passed
@corentinlger corentinlger deleted the corentin/refactor_code_argparse branch March 13, 2024 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants