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

Refactor thermostats: RNG and code duplication #3461

Merged
merged 7 commits into from
Feb 7, 2020

Conversation

jngrad
Copy link
Member

@jngrad jngrad commented Feb 6, 2020

Description of changes:

  • make thermostats fully object-oriented
  • convert DPD and thermalized bond to BaseThermostat
  • centralize their interface in thermostat.hpp
  • refactor the random number generators using templates
  • guard scipy in the testsuite (fixes Rotation test not properly guarded #3460)

The uniform noise function generates 60% less assembly instructions,
the gaussian noise function generates 10% less assembly instructions
in GCC. In Clang, uniform has the same size, gaussian is 10% smaller.
Reduce code duplication by using the existing thermostat framework.
The method `as_matrix` was not implemented before v1.4.0. Fixes
`AttributeError: 'Rotation' object has no attribute 'as_matrix'`.
@jngrad jngrad added this to the Espresso 4.2 milestone Feb 6, 2020
@jngrad jngrad requested a review from fweik February 6, 2020 16:20
@codecov
Copy link

codecov bot commented Feb 6, 2020

Codecov Report

Merging #3461 into python will decrease coverage by <1%.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           python   #3461    +/-   ##
=======================================
- Coverage      86%     86%    -1%     
=======================================
  Files         539     537     -2     
  Lines       25674   24721   -953     
=======================================
- Hits        22282   21335   -947     
+ Misses       3392    3386     -6
Impacted Files Coverage Δ
src/core/electrostatics_magnetostatics/coulomb.cpp 80% <ø> (ø) ⬆️
...e/electrostatics_magnetostatics/coulomb_inline.hpp 94% <ø> (-1%) ⬇️
src/core/electrostatics_magnetostatics/elc.cpp 93% <0%> (-5%) ⬇️
src/core/event.cpp 94% <0%> (-2%) ⬇️
src/core/electrostatics_magnetostatics/p3m.cpp 85% <0%> (-1%) ⬇️
src/core/grid_based_algorithms/lb_interface.cpp 70% <0%> (-1%) ⬇️
src/core/cells.hpp 100% <0%> (ø) ⬆️
src/core/particle_data.cpp 97% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update de56701...c98f653. Read the comment docs.

Copy link
Contributor

@fweik fweik left a comment

Choose a reason for hiding this comment

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

LGTM except for some minor changes.

src/core/random.hpp Outdated Show resolved Hide resolved
return Utils::Vector3d{uniform(noise[0]), uniform(noise[1]),
uniform(noise[2])} -
Utils::Vector3d::broadcast(0.5);
auto const integers = philox_4_uint64s<salt>(counter, key1, key2);
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't it be sufficient to use a Philox2x64 here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Philox2x64 can only take 1 particle id for the key:

src/core/random.hpp:95:18: error: too many initializers for ‘const key_type {aka const r123array1x64}’
   const key_type k{id1, id2};

Although the function that generates 1 random uniform value is only called in an NPT function that has no second particle (hence the second key is always 0), we could in the future have a need to generate 1 random value from two particle ids. We would also introduce ambiguity in the function call, since the function generating N=2-4 random values has an optional argument.

Copy link
Contributor

Choose a reason for hiding this comment

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

It takes 64 bits as key, e.g. 2 * 32 bit or 2 int.

src/core/random.hpp Outdated Show resolved Hide resolved
src/core/random.hpp Outdated Show resolved Hide resolved
src/core/random.hpp Outdated Show resolved Hide resolved
/** Is the RNG counter initialized */
bool rng_is_initialized() const { return rng_counter != nullptr; }

private:
/** RNG counter. */
std::unique_ptr<Utils::Counter<uint64_t>> rng_counter;
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no need anymore to store this on the heap right? A boost::optional<uint64_t> would too I think.

@RudolfWeeber
Copy link
Contributor

RudolfWeeber commented Feb 6, 2020 via email

@fweik
Copy link
Contributor

fweik commented Feb 6, 2020

No, doesn't matter here, it's one static optional per thermostat. For an int an optional is also basically an pair<int, bool>...

Use boost::optional and C++14 std::enable_if_t. Simplify code.
@fweik fweik added the automerge Merge with kodiak label Feb 7, 2020
@kodiakhq kodiakhq bot merged commit b6b9187 into espressomd:python Feb 7, 2020
@jngrad jngrad deleted the thermostats-rng branch January 18, 2022 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rotation test not properly guarded
3 participants