Skip to content

Commit

Permalink
🔐 Collate random seed setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Athoy Nilima committed Jan 31, 2024
1 parent 51c7fdf commit f01f07e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
13 changes: 13 additions & 0 deletions bluemira/base/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
A collection of generic physical constants, conversions, and miscellaneous constants.
"""

from enum import Enum
from typing import Callable, List, Optional, Union

import numpy as np
Expand Down Expand Up @@ -616,3 +617,15 @@ def gcm3_to_kgm3(
"lightcyan": "\x1b[96m",
"darkred": "\x1b[38;5;124m",
}


class RNGSeeds(Enum):
"""
Random Seeds for necessary use cases
"""

equilibria_harmonics = 2944412338698111642
timeline_tools_lognorm = 6613659347120864846
timeline_tools_truncnorm = 9523110846560405221
timeline_tools_expo = 15335509124046896388
timeline_outages = 5876826953682921855
4 changes: 2 additions & 2 deletions bluemira/fuel_cycle/timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import matplotlib.pyplot as plt
import numpy as np

from bluemira.base.constants import S_TO_YR, YR_TO_S
from bluemira.base.constants import S_TO_YR, YR_TO_S, RNGSeeds

Check warning on line 16 in bluemira/fuel_cycle/timeline.py

View check run for this annotation

Codecov / codecov/patch

bluemira/fuel_cycle/timeline.py#L16

Added line #L16 was not covered by tests
from bluemira.fuel_cycle.timeline_tools import (
LogNormalAvailabilityStrategy,
OperationalAvailabilityStrategy,
Expand Down Expand Up @@ -175,7 +175,7 @@ def calculate_outages(

dist += self.t_min_down
self._dist = dist # Store for plotting/debugging
rng = np.random.default_rng()
rng = np.random.default_rng(RNGSeeds.timeline_outages.value)

Check warning on line 178 in bluemira/fuel_cycle/timeline.py

View check run for this annotation

Codecov / codecov/patch

bluemira/fuel_cycle/timeline.py#L178

Added line #L178 was not covered by tests
return rng.permutation(dist)

def plot_dist(self):
Expand Down
7 changes: 4 additions & 3 deletions bluemira/fuel_cycle/timeline_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import numpy as np
from scipy.optimize import brentq

from bluemira.base.constants import RNGSeeds
from bluemira.base.look_and_feel import bluemira_warn
from bluemira.fuel_cycle.error import FuelCycleError

Expand Down Expand Up @@ -70,7 +71,7 @@ def generate_lognorm_distribution(n: int, integral: float, sigma: float) -> np.n
-------
The distribution of size n and of the correct integral value
"""
rng = np.random.default_rng()
rng = np.random.default_rng(RNGSeeds.timeline_tools_lognorm.value)

def f_integral(x):
return np.sum(rng.lognormal(x, sigma, n)) - integral
Expand Down Expand Up @@ -100,7 +101,7 @@ def generate_truncnorm_distribution(n: int, integral: float, sigma: float) -> np
-------
The distribution of size n and of the correct integral value
"""
rng = np.random.default_rng()
rng = np.random.default_rng(RNGSeeds.timeline_tools_truncnorm.value)
distribution = rng.normal(0, sigma, n)
# Truncate distribution by 0-folding
distribution = np.abs(distribution)
Expand Down Expand Up @@ -129,7 +130,7 @@ def generate_exponential_distribution(
-------
The distribution of size n and of the correct integral value
"""
rng = np.random.default_rng()
rng = np.random.default_rng(RNGSeeds.timeline_tools_expo.value)
distribution = rng.exponential(lambdda, n)
# Correct distribution integral
distribution /= np.sum(distribution)
Expand Down

0 comments on commit f01f07e

Please sign in to comment.