JuliaMolSim / Molly.jl

Molecular simulation in Julia
Other
393 stars 53 forks source link

Improving tests #11

Closed SebastianM-C closed 1 year ago

SebastianM-C commented 4 years ago

I noticed that the current tests only check if the simulation doesn't error, but not if the results are wrong. Since I'm refactoring several internal components, I think I should be careful not to change the results. To this end I was thinking to check for some general properties of the simulation to ensure that it is correct. I was thinking of checking for the energy of the system. Do you have any other ideas?

jgreener64 commented 4 years ago

Yes, this is something we need. Since it's not thoroughly tested I'm not fully confident in the implementation as is. Some ideas in addition to the energy would be:

About the energy, I was thinking of implementing this as an EnergyLogger. So users would add EnergyLogger(10) to the loggers to record the energy every 10 steps. The energy function would be defined for the in-built forces. Users could define their own alongside their custom force function, but if they don't it would default to returning 0.0. log_property! for the EnergyLogger would loop over all the interactions, sum up the energies and store them. Let me know if you have any input on that idea.

SebastianM-C commented 4 years ago

Regarding the energy we could look at the

For both we could look at the time evolution or at the final value only. If we look at the energy value, we would need some results to compare with and I'm not sure where to look for those. For the energy error I can use the results from NBodySimulator as guidance, but I'd appreciate if you could give me some references.

The problem that I am also facing with the solver benchmarks in https://github.com/SciML/DiffEqBenchmarks.jl/pull/106 is that the energy (in the case of a Lennard Jones potential) has a quite large variation.

There are also some tests in the NBodySimulator.jl repo which I could try to port to Molly.

jgreener64 commented 4 years ago

Indeed, testing stochastic systems is difficult. I don't know any references off the top of my head but will keep an eye out.

Fixing the starting coordinates and velocities should lead to fixed output to within numerical error when not using a stochastic thermostat, we can use that to some degree.

Porting tests for NBodySimulator or elsewhere sounds like a good idea.

jgreener64 commented 1 year ago

Energy, forces and simulation are now compared against OpenMM. Of course there is always more work to do on the tests.