Skip to content

Isochrone File Name Backward Compatibility; Changed Global Random Seed to Random Number Generator of Each Class#143

Open
wei-lingfeng wants to merge 15 commits intoastropy:devfrom
wei-lingfeng:dev
Open

Isochrone File Name Backward Compatibility; Changed Global Random Seed to Random Number Generator of Each Class#143
wei-lingfeng wants to merge 15 commits intoastropy:devfrom
wei-lingfeng:dev

Conversation

@wei-lingfeng
Copy link
Contributor

@wei-lingfeng wei-lingfeng commented Feb 26, 2026

  • Added backward compatibility of isochrone file names.
  • Changed the global random seed to a random generator within each class, but still retaining the reproducibility.
  • Added support for specifying the random number generator in generate_cluster, calc_multi, and the testing function
  • Added documentation on the behavior of the random number generator.
  • Updated the comparison star systems and companions for future comparisons accordingly.
  • Moved IMF testing functions under spisea/tests

Random number generator is now an attribute of the IMF and Cluster classes:

cluster1 = ResolvedCluster(..., seed=42)
cluster2 = ResolvedCluster(..., seed=42)

cluster1 == cluster2.

For IMF:

imf = IMF(..., seed=42)
result1 = imf.generate_cluster()
result2 = imf.generate_cluster()
imf = IMF(..., seed=42)
result3 = imf.generate_cluster()
result4 = imf.generate_cluster()

result1 == result3, result2 == result4
but result1 ≠ result2, result3 ≠ result4.
This is the same behavior as

rng = np.random.default_rng(seed=42)
result1 = rng.random(1)
result2 = rng.random(1)
rng = np.random.default_rng(seed=42)
result3 = rng.random(1)
result4 = rng.random(1)

If identical output is desired over each run, the random state can be reset before running the function, e.g.,

imf.rng = np.random.default_rng(seed=42)
result1 = imf.generate_cluster()
imf.rng = np.random.default_rng(seed=42)
result2 = imf.generate_cluster()

In this case, result1==result2.

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.

2 participants