ncsu-landscape-dynamics / pops-core

PoPS Core: C++ library for the Pest or Pathogen Spread Model
https://ncsu-landscape-dynamics.github.io/pops-core
GNU General Public License v2.0
5 stars 2 forks source link

Separate seeds and random number generators #192

Closed wenzeslaus closed 1 year ago

wenzeslaus commented 1 year ago

Random number generators for Model can be seeded in Config using one seed, multiple seeds, or one seed but incremented for each of the different generators.

On most places where standard C++ generator was used, custom generator provider class is now used instead and the functions pick what generator they need. Places which are general or reused at different places take the standard C++ generator.

The generator provider classes have also the standard C++ generator interface and can be used wherever a standard C++ generator can be used as long as the configuration allows it.

Generator is no longer part of Simulation, but generator provider is included in Model. Simulation takes it as a parameter of each function which needs a generator similarly to other places in PoPS and C++ library where generators are used.

Config can read text, accept vector of seeds, or std::map can be assigned to its random_seeds attribute.

A lot of tests needed code update because either generator provider object is now needed in the given context (not just seed) or different type is needed (provider, not standard C++ generator).

Text key-value parsing is general. Potentially reusable.

Date now reports the invalid text. (Unrelated but included.)

The new and old core tests and r.pops.spread tests pass. A new test in r.pops.spread tests that enabling and disabling feature does not change results if feature does not have other effects besides consuming random numbers (ncsu-landscape-dynamics/r.pops.spread/pull/61).

wenzeslaus commented 1 year ago

This is ready for review with tests and documentation. Description updated accordingly.