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

Add collisions as part of the simulator state and change default values #46

Merged
merged 14 commits into from
Mar 23, 2024

Conversation

corentinlger
Copy link
Collaborator

Description

Added the collision parameters (alpha : interaction stiffness and epsilon: the interaction energy scale ) as part of the simulator state. In the future this could change (because we would ideally want to have custom alphas and epsilons between different types of particles) but it is already useful at the moment. This enables defining initial values for these parameters when launching experiments, and moreover to play with them directly in the web interface (in the Simulator config).

I think I fixed a small bug in the sim_computation : the sigma (diameter of the particle undergoing the soft_sphere_energy) was the sum of the diameter of sender and receiver, I set it to the sum of the radius (but I'm not sure to understand very well how this function works so I might be wrong). From their documentation, it almost seems like sigma is only the diameter of 1 particle (and then it should maybe be the diameter of the receiving particle ...).

I also added a module (grpcio-tools) to the requirements.txt because it was missing (to recompile proto files).

I also played a bit with the parameters and set them to values that didn't seem horrible. For example try to set an epsilon really high or an alpha really low, you'll see that it makes the simulation extremely chaotic ! Feel free to change the default values to ones that make the simulation looks cooler (: @Marsolo1 @clement-moulin-frier

Related Issue (if applicable)

#29
this PR replaces the #35 (which wasn't really clean)

How to Test

Launch the server

python3 scripts/run_server.py

Launch the Panel interface

panel serve scripts/run_interface.py --autoreload

@corentinlger
Copy link
Collaborator Author

TODO : Fix the requirements.txt, there seems to be a problem with the version of the newly added grpcio-tools

@Marsolo1
Copy link
Collaborator

Marsolo1 commented Mar 14, 2024

TODO : Fix the requirements.txt, there seems to be a problem with the version of the newly added grpcio-tools

I think we could put >= instead of == in the requirements, because the error comes from having grpcio==1.60.0 in the requirements and grpcio-tools==1.62.1 having grpcio>=1.62.1 in its dependencies.

Or we could just set the versions of grpcio and grpcio-toolsto the same version (or simply remove the grpcio requirement as it is already in the dependencies of grpcio-tools).

@corentinlger

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.

Except for the requirement bug, the new parameters seems to work as expected

@corentinlger
Copy link
Collaborator Author

Modified a bit the logic of the mask in the collision functions. Before the mask was applied on the whole array of energies for all pairs of neighbor particles in total_collision_energy, now it is applied at the level of collision_energy between a single pair of particles. (I don't really know why but it seems to solve the problem we had with non existing entities that still had collisions with other particles)

Copy link
Owner

@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.

Cool that you manage by yourself to add a new argument in the entire pipeline, well done :)
And thanks for the having documented the collision functions.
I have written some comments in the code, please have a look.
When testing it, I observed that the agents/objects where largely overlapping with each other, as if the collision parameters were way too low. I increased them in the interface, but even at every large values it was still the same

Comment on lines 17 to 19
# TODO : Quick nnote : would be cool to have a separate file to have all the default values
# In fact the best solution might be to use hydra with yaml files instead of argparse,
# Would also be pretty convenient to store positions etcc for different notebook scenes

Choose a reason for hiding this comment

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

We can discuss this yes, my impression is that this could be done in the context of #30 , so you could move this comment there (and remove it from this file)

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 these comments

Comment on lines 86 to 87
col_eps = param.Number(0.003)
col_alpha = param.Number(0.7)

Choose a reason for hiding this comment

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

These names are not very informative. They might actually be misleading because we already use "col" as a shortcut for column in some files. I would suggest "collision_*" instead (in general better to favor clarity than concision for variable name).
This is a bit fastidious to change though ... but using "search and replace", or even the "refactor" functionality of you IDE, this could be done relatively quickly

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes I thought about it, the "collision_*" syntax will be more informative

:param epsilon: interaction energy scale between two particles
:param alpha: interaction stiffness between two particles
:return: sum of all collisions energies of the system
"""
diameter = lax.stop_gradient(diameter)

Choose a reason for hiding this comment

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

Not sure at all about this but I mention it here just in case you have thoughts about it:

From what I understood of jax/jax_md, the stop_gradient here is to avoid that the system goes down the energy function by reducing the particle diameter, as we only want it to change particle positions. But I'm wondering if internally, it could minimize the energy by changing other parameters in this function, e.g. epsilon and alpha, or even exists_mask?
Do you see a way to check this? Potential options could be to either check manually that those values are not modified during a collision, or asserting that their gradient is at 0.
Not sure at all, but I'm actually wondering if this could be the reason of the bug we observed yesterday (imagine that it was actually modifying the exists_mask as a way to minimize energy ... I'm doubting it was the case though because the best way to do this would be to make entities non-existing, whereas we observe the opposite somehow ..)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's a good question, I'm not sure to understand how everything works in jax_md.

For the epsilon and alpha parameters, we see in the web interface that they aren't changed during the simulation. For the exists_mask,

I tried to debug the code and the exists mask seemed to work fine (but I could do a further checking if you want, for example by creating a copy of the exists_mask at the beginning of each update, and asserting it isn't changed after the update). But it doesn't tell us why the collisions were acting weirdly ...

@corentinlger
Copy link
Collaborator Author

When testing it, I observed that the agents/objects where largely overlapping with each other, as if the collision parameters were way too low. I increased them in the interface, but even at every large values it was still the same

I tested it again and indeed the default values are not optimal (I don't understand why they give a different result compared to last time). It you increase the epsilon, you should have collisions with a really strong 'repulsive' effect. If you increase the alpha, you should have collisions that are softer and softer (in fact you need to lower alpha to prevent particles from overlapping, so stiffness is kind of misleading for this parameter).

I'll change the default values and precise how to use these parameters in the docstring of the collision function.

@corentinlger corentinlger merged commit e085e43 into main Mar 23, 2024
2 checks passed
@corentinlger corentinlger deleted the corentin/new_collisions branch April 4, 2024 15:40
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