Skip to content

Reproducible random generator #346

@myurkin

Description

@myurkin

Is your feature request related to a problem? Please describe.

When granule generator is used (currently, that is the only place in the code, which uses random generator), the inherent randomness breaks the reproducibility. This is important for following scenarios:

  • cross-testing different versions of the code (to obtain many-digit agreement)
  • reproducibility of benchmarks or published simulation results
  • variation of some variable (like, wavelength) for granulated particles (see discussion)

Describe the solution you'd like

Fortunately, ADDA uses a reproducible random generator (Mersenne Twister), so only the following functionality should be added:

  • Explicit seed setting (e.g., with command line -seed ...). If not specified, the current default seeding algorithm should be used.
  • Record the used seed in the log file (even if it is automatically generated). To have in log something like
  domain 1 is filled with 30545 granules of diameter 0.0999989
    volume fraction: specified - 0.1, actual - 0.0574449
    random seed used: 827364918

Also, it should be tested, whether this reproducibility holds in MPI mode (should be fine, since random generator is currently called only from ROOT).

Describe alternatives you've considered

Right now, the workaround for granule generator is to store shape file (-store_geom) and reuse it afterwards (-shape read ...).

Moreover, a dirty fix is possible by using any constants (instead of time and clock) in the current initialization:

adda/src/make_particle.c

Lines 675 to 678 in ff4b449

// initialize random generator
key[0]=(unsigned long)time(NULL);
key[1]=(unsigned long)(clock());
init_by_array(key,KEY_LENGTH);

Additional context

Unfortunately, this will not help immediately for convergence studies (refining discretization), since ADDA granulation algorithm woks on a specific grid (for efficiency in parallel implementation). Thus the only way to make a reproducible refinement is to save granule positions to the file with -store_grans and then to regenerate the shape based on that. Unfortunately, there are no established tools for the latter step:

  • see this discussion (other parts of that long thread are also relevant).
  • I also have a couple of simple scripts (in Mathematica or Python), which can be adjusted for such task (ask me if you need them).

Note also, that the granule positions are not guaranteed to be completely non-overlapping. ADDA only checks that each newly added granule doesn't overlap with voxel centers that were already intersected by previous granules. So in principle, refining the discretization of this analytic granulated model may lead to effective sintering of granules (although this doesn't seem to be important for any applications).

Metadata

Metadata

Assignees

No one assigned

    Labels

    comp-LogicRelated to internal code logichelp wantedShould be doable without understanding the whole code, but not as easy as "good first issue"maintainabilitySimplifies further code development (standardization, robustness)pri-MediumWorth assigning to a milestoneusabilityMakes using code more convenient

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions