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

Thermalized bond philox #3070

Merged
merged 19 commits into from
Aug 22, 2019

Conversation

KonradBreitsprecher
Copy link
Contributor

Fixes the TB part of #2683

  • Common philox counter for all thermalized bonds. Decorrelation via the bond partner IDs (not taking into account the bond ID). This was much easier to implement and is valid, as two (different) thermalized bonds on the same particle pair makes no sense.

Copy link
Member

@jngrad jngrad left a comment

Choose a reason for hiding this comment

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

  • overall LGTM
  • There are merge conflicts with 2 of my PRs, one of which is still open (New logic for default parameters in IA classes #3081). I'll take care of resolving the merge conflicts once the review is finished.
  • @KaiSzuttor my comments on the RNG seed being valid even if zero/negative are not specific to this PR, they also hold for classes in espressomd.thermostat.pyx.

if self.params["seed"]:
utils.check_type_or_throw_except(
self.params["seed"], 1, int, "seed must be a positive integer")
thermalized_bond_set_rng_state(self.params["seed"])
Copy link
Member

Choose a reason for hiding this comment

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

The check above only verifies it's an int, so seed=-12 is sent to the core as 18446744073709551604 and after 12 increments it'll be back to 0, then 1, ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should check_type_or_throw_except handle that centrally as this happens also for DPD and Langevin Thermostat?

Copy link
Member

Choose a reason for hiding this comment

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

A case was made against using is_valid_type to check values (#3080), the same argument can be used against using check_type_or_throw_except. However, creating a seed-dedicated function in utils.pyx that handles both type checking and signedness centrally would probably be fine.

seed : :obj:`int`
Counter value of the philox RNG. Initially, this defines the seed of
the RNG. If prompted, it does not return the initially set counter value
(the seed) but the current state of the RNG.
Copy link
Member

Choose a reason for hiding this comment

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

  1. if multiple thermalized bonds are created on different particles, is the global TB seed overwritten each time?
  2. the corresponding documentation in inter_bonded.rst is now out of sync. I would suggest we remove the duplicated argument descriptions in inter_bonded.rst and add a link to the Python class, like we do for all other bonded IA classes. This is something I should do because it'll cause a merge conflict with one of my recently merged PRs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. If a seed is provided on creation of the bond, the global counter for all TBs is set to that value. I realise now that this causes trouble in the (very special) case of a second (third..) TB with the same seed that will 'reset' the thermalization of all the TBs.
  2. Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

What do you think of this approach:

    def _set_params_in_es_core(self):
        if thermalized_bond_is_seed_required():
            if self.params["seed"] is None:
                raise ValueError(
                    "A seed has to be given as keyword argument on first activation of the thermalized bond")
            else:
                utils.check_type_or_throw_except(
                    self.params["seed"], 1, int, "seed must be a positive integer")
                thermalized_bond_set_rng_state(self.params["seed"])
        elif self.params["seed"] is not None:
            raise ValueError(
                "A seed has to be given as keyword argument only on first activation of the thermalized bond")

        thermalized_bond_set_params(
            self._bond_id, self._params["temp_com"], self._params["gamma_com"],
            self._params["temp_distance"], self._params["gamma_distance"], self._params["r_cut"])
>>> import espressomd
>>> system = espressomd.system.System(box_l=3*[12])
>>> tb1 = espressomd.interactions.ThermalizedBond(temp_com=300,gamma_com=50,temp_distance=300,gamma_distance=20,r_cut=1)
>>> tb2 = espressomd.interactions.ThermalizedBond(temp_com=300,gamma_com=50,temp_distance=300,gamma_distance=20,r_cut=1,seed=5)
>>> system.bonded_inter.add(tb1) # fails: has no seed
ValueError: A seed has to be given as keyword argument on first activation of the thermalized bond
>>> system.bonded_inter.add(tb2) # ok: has a seed
>>> system.bonded_inter.add(tb2) # fails: overwrites seed
ValueError: A seed has to be given as keyword argument only on first activation of the thermalized bond
>>> system.bonded_inter.add(tb1) # ok: has no seed

Copy link
Member

@jngrad jngrad Aug 20, 2019

Choose a reason for hiding this comment

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

Update on my approach: it's not a good idea. It's problematic when setting TBs in a for loop. Also when setting a TB in multiple test methods of a unittest class, since the order of the tests is based on the alphabetical order of the methods and the presence/absence of fixtures, the only way to reliably set the seed only once is to implement an MPI-safe lock mechanism... We'll just leave the seed logic as it currently is.

@codecov
Copy link

codecov bot commented Aug 14, 2019

Codecov Report

Merging #3070 into python will decrease coverage by <1%.
The diff coverage is 89%.

Impacted file tree graph

@@           Coverage Diff           @@
##           python   #3070    +/-   ##
=======================================
- Coverage      83%     83%    -1%     
=======================================
  Files         530     530            
  Lines       26100   25966   -134     
=======================================
- Hits        21915   21770   -145     
- Misses       4185    4196    +11
Impacted Files Coverage Δ
src/core/random.hpp 58% <ø> (ø) ⬆️
...re/bonded_interactions/bonded_interaction_data.hpp 100% <ø> (ø) ⬆️
src/core/bonded_interactions/thermalized_bond.hpp 100% <100%> (ø) ⬆️
src/core/integrate.cpp 75% <100%> (ø) ⬆️
src/core/bonded_interactions/thermalized_bond.cpp 93% <77%> (-7%) ⬇️
...ore/grid_based_algorithms/lb_particle_coupling.cpp 88% <0%> (-8%) ⬇️
src/core/global.cpp 74% <0%> (-7%) ⬇️
src/core/rotation.cpp 91% <0%> (-7%) ⬇️
...rc/core/electrostatics_magnetostatics/scafacos.cpp 65% <0%> (-6%) ⬇️
src/core/grid_based_algorithms/lb_interface.cpp 72% <0%> (-4%) ⬇️
... and 26 more

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 2948859...99e2a57. Read the comment docs.

@RudolfWeeber
Copy link
Contributor

RudolfWeeber commented Aug 20, 2019 via email

@jngrad
Copy link
Member

jngrad commented Aug 20, 2019

@RudolfWeeber is the test in 1bda0e9 sufficient?

@RudolfWeeber RudolfWeeber added this to the Espresso 4.1 milestone Aug 21, 2019
@jngrad
Copy link
Member

jngrad commented Aug 22, 2019

bors r+

bors bot added a commit that referenced this pull request Aug 22, 2019
3070: Thermalized bond philox r=jngrad a=KonradBreitsprecher

Fixes the TB part of #2683 

- Common philox counter for all thermalized bonds. Decorrelation via the bond partner IDs (not taking into account the bond ID). This was much easier to implement and is valid, as two (different) thermalized bonds on the same particle pair makes no sense.

3080: testsuite: add test for is_valid_type. r=jngrad a=KaiSzuttor

Currently it is possible to give ```nan``` as values to the particle properties because in python a ```nan``` is of type ```float```. This PR adds a check for ```None```, ```inf``` and ```nan``` to the ```is_valid_type``` and tests for the correct behavior.

3096: Core: Correct maximum permissible skin in tune_skin() r=jngrad a=RudolfWeeber

Fixes #2924 
Fix according to the discussion in #2924 




Co-authored-by: KonradBreitsprecher <[email protected]>
Co-authored-by: Konrad Breitsprecher <[email protected]>
Co-authored-by: Konrad Breitsprecher <[email protected]>
Co-authored-by: Jean-Noël Grad <[email protected]>
Co-authored-by: Kai Szuttor <[email protected]>
Co-authored-by: Kai Szuttor <[email protected]>
Co-authored-by: Rudolf Weeber <[email protected]>
@bors
Copy link
Contributor

bors bot commented Aug 22, 2019

Build succeeded

@bors bors bot merged commit 99e2a57 into espressomd:python Aug 22, 2019
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