-
Notifications
You must be signed in to change notification settings - Fork 18
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
Separate System and Interactions #126
Comments
Would having a separation like that be OK ? #[derive(Clone)]
pub struct SystemConfiguration {
/// Unit cell of the system
cell: UnitCell,
/// List of particles in the system
particles: Vec<Particle>,
/// Molecules in the system
molecules: Vec<Molecule>,
/// Molecules indexes for all the particles
molids: Vec<usize>,
}
/// The System type hold all the data about a simulated system.
///
/// This data contains:
///
/// - an unit cell, containing the system;
/// - a list of particles in the system;
/// - a list of molecules in the system;
/// - a list of interactions, associating particles kinds and potentials
/// - a hash map associating particles names and particles kinds.
///
/// In the implementation, the particles contained in a molecule are guaranteed
/// to be contiguous in memory. This allow for faster access when iterating over
/// molecules, and easier molecule removal in the system.
#[derive(Clone)]
pub struct System {
configuration: SystemConfiguration,
/// Interactions manages the associations between particles and potentials
interactions: Interactions,
/// Current step of the simulation
step: u64,
/// Externally managed temperature for the system, if the propagation
/// algorithm does not update the velocities.
external_temperature: Option<f64>
} |
In this context maybe it is good to talk about #18 again? Also @Luthaf and I had a conversation about how to represent molecules, how to get bonding information from the input and how to apply a move for a certain molecule. While this is not directly connected to parallelization, it would also change the structure of @antoinewdg What would be the first step? Using something like rayon with the energy and force loops? |
Probably. My take on this is that no matter what we do, the system should keep this internally and expose a clear interface, and that it we are getting closer and closer to a moment where we would have to sit down and think about it.
Exactly. Energy and virial computation would be simpler because they are just a simple reduction, while forces are a little subtler (avoiding computation of the same force twice as we can do sequentially does not seem easy). |
I'm not sure I understand this? We also have this issue with energies where the outer loop is over all particles minus one (with index |
The issue is actually not computing the values forces for each pair, it's the aggregation that causes problems: energy and virial are just a big reduce operation over all pairs, while forces is a weird scatter. |
Ah, I see what you mean 😄 |
Global interactions are inside a RefCell because it was faster for Ewald summation to just check the borrow state once. As you say, it should be moved to something like The issue I have with a separation of System and Interactions is that they are tightly coupled right now: the system setup the particles kinds from the interactions, and will only work with one interaction instance. We could decouple them if we don't get a performance penalty, maybe by changing how we store and represent interactions. And yes, we should definitively think again about #18, with requirements from the parallelism (we may want to use multiple subsystems for MPI style parallelisation); possibility to refer to molecules in the system by molecular species; possibility to have SoA style optimization; and offering a nice API. I don't know how much these are coupled together, and how many trade-offs there will be. Maybe we could have a video call at some point to actually sit down and discuss all of this? |
Indeed this is a problem I did not see.
That is definitely a good idea ! |
Sorry, I might be too tired, but I really don't get your solution. The idea is to have only Sync Interactions, and pass the (read-only) interactions maps aside with the systems? Then how would one implement caching with this? |
No problem, I'll elaborate a bit:
|
👍 |
Can we organize this call in the not too far future ? Parallelizing stuff is my original goal, and I can't work on it as long a we do not make these changes. |
Yes, sure. I'll send an email about it.
I disagree here =). We can go for incremental changes, and just start with the non-optimal way of using |
That's totally right, thanks for pointing it out ! |
Changing the issue to track the System/Interactions separation now that the system is Sync (#132). As I said during the video call, this whole issue comes from the need to cache Ewald computation in MC moves. But the We can resolve this by separating the System in two as proposed in #126 (comment), and then change the The main issue with this way of doing this is the atomic names <=> atomic kind association. We need to be sure a specific atomic name correspond to the right atomic kind, as both are stored in the |
If we want to do any parallelization, we will need the
System
object to beSend
andSync
, and it is notSync
because of theRefCell
s used inInteraction
.The good news is that we actually do not need to have the interactions passed around threads, so making the system (here the configuration of the particles) and the interactions two separate entities would solve the problem. The bad news is that it would require some non trivial refactoring. I'll work on a draft for this and open a PR.
As a side note : according to the rust doc, it would make more sense if
GlobalPotential::energy
(and others) were immutable and theRefCell
was actually inside the struct implementingGlobalPotential
if it were to use caching, theSystem
should not be aware of this mutability. Is there a particular reason that it is done the other way around ?The text was updated successfully, but these errors were encountered: