From f06b2993e230f90cc49a3bdbcde0cf5c9f56736a Mon Sep 17 00:00:00 2001 From: Seth Gossage Date: Wed, 18 Mar 2026 14:43:55 -0500 Subject: [PATCH 1/7] Adding an RNG kwarg to load_steps() and load_a_step() in simulationproperties.py. Adding RNG kwarg to step_SN and using RNG object in places where randomness occurs --- posydon/binary_evol/SN/step_SN.py | 19 ++++++++++--------- posydon/binary_evol/simulationproperties.py | 17 ++++++++++------- posydon/popsyn/binarypopulation.py | 2 +- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/posydon/binary_evol/SN/step_SN.py b/posydon/binary_evol/SN/step_SN.py index afe015d73..64a8dce86 100644 --- a/posydon/binary_evol/SN/step_SN.py +++ b/posydon/binary_evol/SN/step_SN.py @@ -250,6 +250,7 @@ class StepSN(object): "mean_kick_ECSN": None, # other "verbose": False, + "RNG": np.random.default_rng() } # add core collapse physics DEFAULT_KWARGS.update(DEFAULT_SN_MODEL) @@ -404,7 +405,7 @@ def format_data_Patton20(file_name): def __repr__(self): """Get the string representation of the class and any parameters.""" return "StepSN:\n" + \ - "\n".join([f"{key} = {getattr(self, key)}" for key in SN_MODEL]) + "\n".join([f"{key} = {getattr(self, key)}" for key in self.DEFAULT_KWARGS]) def _reset_other_star_properties(self, star): @@ -1538,13 +1539,13 @@ def orbital_kick(self, binary): if not binary.star_1.natal_kick_azimuthal_angle is None: phi = binary.star_1.natal_kick_azimuthal_angle else: - phi = np.random.uniform(0, 2 * np.pi) + phi = self.RNG.uniform(0, 2 * np.pi) binary.star_1.natal_kick_azimuthal_angle = phi if not binary.star_1.natal_kick_polar_angle is None: cos_theta = np.cos(binary.star_1.natal_kick_polar_angle) else: - cos_theta = np.random.uniform(-1, 1) + cos_theta = self.RNG.uniform(-1, 1) binary.star_1.natal_kick_polar_angle = np.arccos(cos_theta) # generate random point in the orbit where the kick happens @@ -1555,7 +1556,7 @@ def orbital_kick(self, binary): raise ValueError("mean_anomaly must be a single float value." f"\n mean_anomaly = {mean_anomaly}") else: - mean_anomaly = np.random.uniform(0, 2 * np.pi) + mean_anomaly = self.RNG.uniform(0, 2 * np.pi) binary.star_1.natal_kick_mean_anomaly = mean_anomaly elif binary.event == "CC2": @@ -1639,13 +1640,13 @@ def orbital_kick(self, binary): if not binary.star_2.natal_kick_azimuthal_angle is None: phi = binary.star_2.natal_kick_azimuthal_angle else: - phi = np.random.uniform(0, 2 * np.pi) + phi = self.RNG.uniform(0, 2 * np.pi) binary.star_2.natal_kick_azimuthal_angle = phi if not binary.star_2.natal_kick_polar_angle is None: cos_theta = np.cos(binary.star_2.natal_kick_polar_angle) else: - cos_theta = np.random.uniform(-1, 1) + cos_theta = self.RNG.uniform(-1, 1) binary.star_2.natal_kick_polar_angle = np.arccos(cos_theta) # generate random point in the orbit where the kick happens @@ -1655,7 +1656,7 @@ def orbital_kick(self, binary): if not isinstance(mean_anomaly, float): raise ValueError("mean_anomaly must be a single float value.") else: - mean_anomaly = np.random.uniform(0, 2 * np.pi) + mean_anomaly = self.RNG.uniform(0, 2 * np.pi) binary.star_2.natal_kick_mean_anomaly = mean_anomaly # update the orbit @@ -2081,7 +2082,7 @@ def _get_kick_velocity(self, star, sigma=None, mean=None): # this is a fallback if sigma is None: sigma = 265.0 - Vkick_ej = sp.stats.maxwell.rvs(loc=0., scale=sigma, size=1)[0] + Vkick_ej = sp.stats.maxwell.rvs(loc=0., scale=sigma, size=1, random_state=self.RNG)[0] elif self.kick_prescription == "log_normal": # sigma==None should never be reached, since in that case Vkick=0 @@ -2091,7 +2092,7 @@ def _get_kick_velocity(self, star, sigma=None, mean=None): sigma = 0.68 if mean is None: mean = np.exp(5.60) - Vkick_ej = sp.stats.lognorm.rvs(s=sigma, scale=mean, size=1)[0] + Vkick_ej = sp.stats.lognorm.rvs(s=sigma, scale=mean, size=1, random_state=self.RNG)[0] elif self.kick_prescription == "asym_ej": f_kin = 0.1 # Fraction of SN explosion energy that is kinetic energy of the gas diff --git a/posydon/binary_evol/simulationproperties.py b/posydon/binary_evol/simulationproperties.py index cdefb8fa0..42002c9d1 100644 --- a/posydon/binary_evol/simulationproperties.py +++ b/posydon/binary_evol/simulationproperties.py @@ -268,7 +268,7 @@ def from_ini(cls, path, metallicity = None, load_steps=False, verbose=False, **o return new_instance - def load_steps(self, metallicity=None, verbose=False): + def load_steps(self, metallicity=None, RNG=None, verbose=False): """Instantiate all step classes and set as instance attributes. Parameters @@ -292,7 +292,7 @@ def load_steps(self, metallicity=None, verbose=False): if isinstance(tup, tuple): step_kwargs = tup[1] metallicity = step_kwargs.get('metallicity', metallicity) - self.load_a_step(name, tup, metallicity=metallicity, verbose=verbose) + self.load_a_step(name, tup, metallicity=metallicity, RNG=RNG, verbose=verbose) if verbose: if self.steps_loaded: @@ -300,7 +300,7 @@ def load_steps(self, metallicity=None, verbose=False): else: print("Not all steps were loaded successfully. Check warnings for details.") - def load_a_step(self, step_name, step_tup=(NullStep, {}), metallicity=None, from_ini='', verbose=False): + def load_a_step(self, step_name, step_tup=(NullStep, {}), metallicity=None, RNG=None, from_ini='', verbose=False): """ Instantiate and attach a simulation step to this object. @@ -362,12 +362,12 @@ def load_a_step(self, step_name, step_tup=(NullStep, {}), metallicity=None, from if os.path.isfile(from_ini): step_tup = simprop_kwargs_from_ini(from_ini, only=step_name)[step_name] - if step_name is not "flow": + if step_name != "flow": # check to make sure the step has a... # 1) metallicity assigned (if needed) # 2) TrackMatcher assigned (if needed) - step_tup = self.check_step(metallicity, step_name, - step_tup, verbose) + step_tup = self.check_step(metallicity, RNG, step_name, + step_tup, verbose) step_func, step_kwargs = step_tup @@ -392,7 +392,7 @@ def load_a_step(self, step_name, step_tup=(NullStep, {}), metallicity=None, from for name, tup in self.kwargs.items() if isinstance(tup, tuple)) - def check_step(self, metallicity, step_name, step_tup, verbose=False): + def check_step(self, metallicity, RNG, step_name, step_tup, verbose=False): """ Validate and update configuration for an evolution step. @@ -457,6 +457,9 @@ def check_step(self, metallicity, step_name, step_tup, verbose=False): print(f"matcher_kwargs: \n" + "\n".join(kw_list)) step_kwargs['track_matcher'] = self.track_matchers[matcher_key] + if "RNG" in step_func.DEFAULT_KWARGS: + step_kwargs['RNG'] = RNG + return step_tup def create_track_matcher(self, metallicity, step_name, matcher_kwargs): diff --git a/posydon/popsyn/binarypopulation.py b/posydon/popsyn/binarypopulation.py index d4f6a1ac7..9e119490d 100644 --- a/posydon/popsyn/binarypopulation.py +++ b/posydon/popsyn/binarypopulation.py @@ -304,7 +304,7 @@ def _safe_evolve(self, **kwargs): modified_tup = (step_function, step_kwargs) self.population_properties.kwargs[step_name] = modified_tup - self.population_properties.load_steps() + self.population_properties.load_steps(RNG=self.RNG) indices = kwargs.get('indices', list(range(self.number_of_binaries))) From 003060a6d6c667ac2d94e606664da72f99985e31 Mon Sep 17 00:00:00 2001 From: Seth Gossage Date: Wed, 18 Mar 2026 15:23:49 -0500 Subject: [PATCH 2/7] use __dict__ to print all attributes of StepSN in __repr__ --- posydon/binary_evol/SN/step_SN.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/posydon/binary_evol/SN/step_SN.py b/posydon/binary_evol/SN/step_SN.py index 64a8dce86..054fc02e5 100644 --- a/posydon/binary_evol/SN/step_SN.py +++ b/posydon/binary_evol/SN/step_SN.py @@ -405,7 +405,7 @@ def format_data_Patton20(file_name): def __repr__(self): """Get the string representation of the class and any parameters.""" return "StepSN:\n" + \ - "\n".join([f"{key} = {getattr(self, key)}" for key in self.DEFAULT_KWARGS]) + "\n".join([f"{key} = {getattr(self, key)}" for key in self.__dict__]) def _reset_other_star_properties(self, star): From c604093e59aabb149b09dcc4a780bf2725286fe7 Mon Sep 17 00:00:00 2001 From: Seth Gossage Date: Thu, 19 Mar 2026 13:13:39 -0500 Subject: [PATCH 3/7] pass RNG down to bondi_hoyle accretion functions in step_mesa and step_detached. Also set default RNG in load_steps and load_a_step (simulationproperties.py) --- posydon/binary_evol/DT/step_detached.py | 31 +++++++++++---------- posydon/binary_evol/MESA/step_mesa.py | 9 ++++-- posydon/binary_evol/SN/step_SN.py | 4 +-- posydon/binary_evol/simulationproperties.py | 6 ++-- posydon/utils/common_functions.py | 4 +-- 5 files changed, 30 insertions(+), 24 deletions(-) diff --git a/posydon/binary_evol/DT/step_detached.py b/posydon/binary_evol/DT/step_detached.py index c7b167833..711fb1728 100644 --- a/posydon/binary_evol/DT/step_detached.py +++ b/posydon/binary_evol/DT/step_detached.py @@ -163,17 +163,18 @@ class detached_step: # settings in .ini will override DEFAULT_KWARGS = {"dt": None, - "n_o_steps_history": None, - "do_wind_loss": True, - "do_tides": True, - "do_gravitational_radiation": True, - "do_magnetic_braking": True, - "magnetic_braking_mode": "RVJ83", - "do_stellar_evolution_and_spin_from_winds": True, - "RLO_orbit_at_orbit_with_same_am": False, - "metallicity": None, - "track_matcher": None, - "verbose": False} + "n_o_steps_history": None, + "do_wind_loss": True, + "do_tides": True, + "do_gravitational_radiation": True, + "do_magnetic_braking": True, + "magnetic_braking_mode": "RVJ83", + "do_stellar_evolution_and_spin_from_winds": True, + "RLO_orbit_at_orbit_with_same_am": False, + "metallicity": None, + "track_matcher": None, + "RNG": np.random.default_rng(), + "verbose": False} def __init__(self, **kwargs): @@ -224,12 +225,12 @@ def init_evo_kwargs(self): "magnetic_braking_mode": self.magnetic_braking_mode, "do_stellar_evolution_and_spin_from_winds": self.do_stellar_evolution_and_spin_from_winds, "do_gravitational_radiation": self.do_gravitational_radiation, - "verbose": self.verbose, - } + "verbose": self.verbose} def __repr__(self): """Return the name of evolution step.""" - return "Detached Step." + return "detached_step:\n" + \ + "\n".join([f"{key} = {getattr(self, key)}" for key in self.__dict__]) def __call__(self, binary): """ @@ -352,7 +353,7 @@ def __call__(self, binary): elif primary.co: mdot_acc = np.atleast_1d(bondi_hoyle( binary, primary, secondary, slice(-len(t), None), - wind_disk_criteria=True, scheme='Kudritzki+2000')) + wind_disk_criteria=True, RNG=self.RNG, scheme='Kudritzki+2000')) primary.lg_mdot = np.log10(mdot_acc.item(-1)) primary.lg_mdot_history[len(primary.lg_mdot_history) - len(t) + 1:] = np.log10(mdot_acc[:-1]) else: diff --git a/posydon/binary_evol/MESA/step_mesa.py b/posydon/binary_evol/MESA/step_mesa.py index ccc23e6c1..020bf6981 100644 --- a/posydon/binary_evol/MESA/step_mesa.py +++ b/posydon/binary_evol/MESA/step_mesa.py @@ -139,6 +139,7 @@ class MesaGridStep: 'stop_var_name': None, 'stop_value': None, 'stop_interpolate': True, + 'RNG': np.random.default_rng(), 'verbose': False} def __init__(self, **kwargs): @@ -775,7 +776,7 @@ def update_properties_NN(self, star_1_CO=False, star_2_CO=False, key_bh = POSYDON_TO_MESA['star']['lg_mdot']+'_%d' % (k_bh+1) tmp_lg_mdot = np.log10(10**cb_bh[key_bh][-1] + cf.bondi_hoyle( binary, accretor, donor, idx=-1, - wind_disk_criteria=True, scheme='Kudritzki+2000')) + wind_disk_criteria=True, RNG=self.RNG, scheme='Kudritzki+2000')) mdot_edd = cf.eddington_limit(binary, idx=-1)[0] if 10**tmp_lg_mdot > mdot_edd: @@ -788,7 +789,7 @@ def update_properties_NN(self, star_1_CO=False, star_2_CO=False, history_of_attribute = (np.log10( 10**cb_bh[key_bh][0] + cf.bondi_hoyle( binary, accretor, donor, idx=len_binary_hist, - wind_disk_criteria=True, scheme='Kudritzki+2000'))) + wind_disk_criteria=True, RNG=self.RNG, scheme='Kudritzki+2000'))) if 10**history_of_attribute > edd: history_of_attribute = np.log10(edd) accretor.lg_mdot_history.append(history_of_attribute) @@ -800,6 +801,7 @@ def update_properties_NN(self, star_1_CO=False, star_2_CO=False, # hence we loop one back range(-N-1,-1) tmp_h = [cf.bondi_hoyle(binary, accretor, donor, idx=i, wind_disk_criteria=True, + RNG=self.RNG, scheme='Kudritzki+2000') for i in range(-length_hist-1, -1)] tmp_edd = [cf.eddington_limit(binary, idx=i)[0] @@ -966,7 +968,8 @@ def initial_final_interpolation(self, star_1_CO=False, star_2_CO=False): tmp_lg_mdot = np.log10( 10**fv[key_bh] + cf.bondi_hoyle( binary, accretor, donor, idx=-1, - wind_disk_criteria=True, scheme='Kudritzki+2000')) + wind_disk_criteria=True, + RNG=self.RNG, scheme='Kudritzki+2000')) mdot_edd = cf.eddington_limit(binary, idx=-1)[0] if 10**tmp_lg_mdot > mdot_edd: diff --git a/posydon/binary_evol/SN/step_SN.py b/posydon/binary_evol/SN/step_SN.py index 054fc02e5..6cc4d64a5 100644 --- a/posydon/binary_evol/SN/step_SN.py +++ b/posydon/binary_evol/SN/step_SN.py @@ -249,8 +249,8 @@ class StepSN(object): "sigma_kick_ECSN": 20.0, "mean_kick_ECSN": None, # other - "verbose": False, - "RNG": np.random.default_rng() + "RNG": np.random.default_rng(), + "verbose": False } # add core collapse physics DEFAULT_KWARGS.update(DEFAULT_SN_MODEL) diff --git a/posydon/binary_evol/simulationproperties.py b/posydon/binary_evol/simulationproperties.py index 42002c9d1..5805b9fa7 100644 --- a/posydon/binary_evol/simulationproperties.py +++ b/posydon/binary_evol/simulationproperties.py @@ -16,6 +16,7 @@ import os import time +import numpy as np from posydon.binary_evol.track_match import TrackMatcher from posydon.config import PATH_TO_POSYDON_DATA @@ -268,7 +269,7 @@ def from_ini(cls, path, metallicity = None, load_steps=False, verbose=False, **o return new_instance - def load_steps(self, metallicity=None, RNG=None, verbose=False): + def load_steps(self, metallicity=None, RNG=np.random.default_rng(), verbose=False): """Instantiate all step classes and set as instance attributes. Parameters @@ -300,7 +301,8 @@ def load_steps(self, metallicity=None, RNG=None, verbose=False): else: print("Not all steps were loaded successfully. Check warnings for details.") - def load_a_step(self, step_name, step_tup=(NullStep, {}), metallicity=None, RNG=None, from_ini='', verbose=False): + def load_a_step(self, step_name, step_tup=(NullStep, {}), metallicity=None, + RNG=np.random.default_rng(), from_ini='', verbose=False): """ Instantiate and attach a simulation step to this object. diff --git a/posydon/utils/common_functions.py b/posydon/utils/common_functions.py index 97c7e0cfc..abb540cd0 100644 --- a/posydon/utils/common_functions.py +++ b/posydon/utils/common_functions.py @@ -507,7 +507,7 @@ def beaming(binary): def bondi_hoyle(binary, accretor, donor, idx=-1, wind_disk_criteria=True, - scheme='Hurley+2002'): + RNG=np.random.default_rng(), scheme='Hurley+2002'): """Calculate the Bondi-Hoyle accretion rate of a binary [1]_. Parameters @@ -629,7 +629,7 @@ def bondi_hoyle(binary, accretor, donor, idx=-1, wind_disk_criteria=True, pass n = np.sqrt((G * (m_acc + m) * Msun) / ((radius * Rsun)**3)) - t0 = np.random.rand(len(sep)) * 2 * np.pi / n + t0 = RNG.random(len(sep)) * 2 * np.pi / n E = newton(lambda x: x - ecc * np.sin(x) - n * t0, np.ones_like(sep) * np.pi / 2, maxiter=100) From 00c257cf90f5e08352f4f5b088b17438877d71e8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 19 Mar 2026 18:13:56 +0000 Subject: [PATCH 4/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- posydon/binary_evol/MESA/step_mesa.py | 2 +- posydon/binary_evol/simulationproperties.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/posydon/binary_evol/MESA/step_mesa.py b/posydon/binary_evol/MESA/step_mesa.py index 020bf6981..e8da3b8db 100644 --- a/posydon/binary_evol/MESA/step_mesa.py +++ b/posydon/binary_evol/MESA/step_mesa.py @@ -968,7 +968,7 @@ def initial_final_interpolation(self, star_1_CO=False, star_2_CO=False): tmp_lg_mdot = np.log10( 10**fv[key_bh] + cf.bondi_hoyle( binary, accretor, donor, idx=-1, - wind_disk_criteria=True, + wind_disk_criteria=True, RNG=self.RNG, scheme='Kudritzki+2000')) mdot_edd = cf.eddington_limit(binary, idx=-1)[0] diff --git a/posydon/binary_evol/simulationproperties.py b/posydon/binary_evol/simulationproperties.py index 5805b9fa7..47e0d6bb3 100644 --- a/posydon/binary_evol/simulationproperties.py +++ b/posydon/binary_evol/simulationproperties.py @@ -16,6 +16,7 @@ import os import time + import numpy as np from posydon.binary_evol.track_match import TrackMatcher @@ -301,7 +302,7 @@ def load_steps(self, metallicity=None, RNG=np.random.default_rng(), verbose=Fals else: print("Not all steps were loaded successfully. Check warnings for details.") - def load_a_step(self, step_name, step_tup=(NullStep, {}), metallicity=None, + def load_a_step(self, step_name, step_tup=(NullStep, {}), metallicity=None, RNG=np.random.default_rng(), from_ini='', verbose=False): """ Instantiate and attach a simulation step to this object. From 5ced319d147fa31191b3b7804c52d9cf8c9c0545 Mon Sep 17 00:00:00 2001 From: Seth Gossage Date: Thu, 19 Mar 2026 13:33:10 -0500 Subject: [PATCH 5/7] add RNG argument for SimulationProperties.from_ini that may be used to pass an RNG during load_steps --- posydon/binary_evol/simulationproperties.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/posydon/binary_evol/simulationproperties.py b/posydon/binary_evol/simulationproperties.py index 5805b9fa7..2f3d59894 100644 --- a/posydon/binary_evol/simulationproperties.py +++ b/posydon/binary_evol/simulationproperties.py @@ -230,7 +230,8 @@ def preload_imports(self): self._MesaGridStep = MesaGridStep @classmethod - def from_ini(cls, path, metallicity = None, load_steps=False, verbose=False, **override_sim_kwargs): + def from_ini(cls, path, metallicity = None, load_steps=False, RNG=np.random.default_rng(), + verbose=False, **override_sim_kwargs): """Create a SimulationProperties instance from an inifile. Parameters @@ -247,9 +248,19 @@ def from_ini(cls, path, metallicity = None, load_steps=False, verbose=False, **o load_steps : bool Whether or not evolution steps should be automatically loaded. + RNG : numpy.random.Generator, optional + Random number generator used for any stochastic components of + the simulation. Defaults to a new NumPy Generator instance + created via ``np.random.default_rng()``. + verbose : bool Print useful info. + **override_sim_kwargs + Additional keyword arguments that override values specified + in the .ini file when constructing the SimulationProperties + instance. + Returns ------- SimulationProperties @@ -265,6 +276,7 @@ def from_ini(cls, path, metallicity = None, load_steps=False, verbose=False, **o if load_steps: # Load the steps and required data new_instance.load_steps(metallicity=metallicity, + RNG=RNG, verbose=verbose) return new_instance From 8cfb9bc6af73a547bb58127594cd5f1c5b227eba Mon Sep 17 00:00:00 2001 From: Seth Gossage Date: Thu, 19 Mar 2026 13:44:05 -0500 Subject: [PATCH 6/7] update bondi_hoyle unit test --- .../unit_tests/utils/test_common_functions.py | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/posydon/unit_tests/utils/test_common_functions.py b/posydon/unit_tests/utils/test_common_functions.py index c66229fdd..035ab3374 100644 --- a/posydon/unit_tests/utils/test_common_functions.py +++ b/posydon/unit_tests/utils/test_common_functions.py @@ -696,10 +696,12 @@ def test_beaming(self, binary): assert totest.beaming(binary) == r def test_bondi_hoyle(self, binary, monkeypatch): - def mock_rand(shape): - return np.zeros(shape) - def mock_rand2(shape): - return np.full(shape, 0.1) + class MockRNG: + def random(self, shape): + return np.zeros(shape) + class MockRNG2: + def random(self, shape): + return np.full(shape, 0.1) # missing argument with raises(TypeError, match="missing 3 required positional "\ +"arguments: 'binary', 'accretor', and "\ @@ -725,32 +727,32 @@ def mock_rand2(shape): +"associated with a value"): # undefined scheme totest.bondi_hoyle(binary, binary.star_1, binary.star_2, scheme='') - monkeypatch.setattr(np.random, "rand", mock_rand) - assert totest.bondi_hoyle(binary, binary.star_1, binary.star_2) ==\ + rng = MockRNG() + assert totest.bondi_hoyle(binary, binary.star_1, binary.star_2, RNG=rng) ==\ approx(3.92668160462e-17, abs=6e-29) assert totest.bondi_hoyle(binary, binary.star_1, binary.star_2,\ - scheme='Kudritzki+2000') ==\ + RNG=rng, scheme='Kudritzki+2000') ==\ approx(3.92668160462e-17, abs=6e-29) binary.star_2.log_R = 1.5 #donor's radius is 10^{1.5}Rsun assert totest.bondi_hoyle(binary, binary.star_1, binary.star_2,\ - scheme='Kudritzki+2000') ==\ + RNG=rng, scheme='Kudritzki+2000') ==\ approx(3.92668160462e-17, abs=6e-29) binary.star_2.log_R = -1.5 #donor's radius is 10^{-1.5}Rsun assert totest.bondi_hoyle(binary, binary.star_1, binary.star_2,\ - scheme='Kudritzki+2000') == 1e-99 + RNG=rng, scheme='Kudritzki+2000') == 1e-99 binary.star_2.surface_h1 = 0.25 #donor's X_surf=0.25 - assert totest.bondi_hoyle(binary, binary.star_1, binary.star_2) ==\ + assert totest.bondi_hoyle(binary, binary.star_1, binary.star_2, RNG=rng) ==\ 1e-99 binary.star_2.lg_wind_mdot = -4.0 #donor's wind is 10^{-4}Msun/yr - assert totest.bondi_hoyle(binary, binary.star_1, binary.star_2) ==\ + assert totest.bondi_hoyle(binary, binary.star_1, binary.star_2, RNG=rng) ==\ 1e-99 assert totest.bondi_hoyle(binary, binary.star_1, binary.star_2,\ - wind_disk_criteria=False) ==\ + RNG=rng, wind_disk_criteria=False) ==\ approx(5.34028698228e-17, abs=6e-29) # form always a disk - monkeypatch.setattr(np.random, "rand", mock_rand2) # other angle + rng = MockRNG2() # other angle binary.star_1.state = 'BH' #accretor is BH assert totest.bondi_hoyle(binary, binary.star_1, binary.star_2,\ - wind_disk_criteria=False) ==\ + wind_disk_criteria=False, RNG=rng) ==\ approx(5.13970075150e-8, abs=6e-20) def test_rejection_sampler(self, monkeypatch): From 8e267c23935c7ae5e8823fef422e91b2ed5e8227 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 19 Mar 2026 19:24:05 +0000 Subject: [PATCH 7/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- posydon/binary_evol/DT/step_detached.py | 8 ++++---- posydon/binary_evol/track_match.py | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/posydon/binary_evol/DT/step_detached.py b/posydon/binary_evol/DT/step_detached.py index 238a8424d..73907fddf 100644 --- a/posydon/binary_evol/DT/step_detached.py +++ b/posydon/binary_evol/DT/step_detached.py @@ -25,10 +25,6 @@ from posydon.binary_evol.DT.gravitational_radiation.default_gravrad import ( default_gravrad, ) -from posydon.utils.key_library import ( - DEFAULT_TRANSLATED_KEYS, - DEFAULT_TRANSLATION, -) from posydon.binary_evol.DT.magnetic_braking.prescriptions import ( CARB_braking, G18_braking, @@ -58,6 +54,10 @@ set_binary_to_failed, zero_negative_values, ) +from posydon.utils.key_library import ( + DEFAULT_TRANSLATED_KEYS, + DEFAULT_TRANSLATION, +) from posydon.utils.posydonerror import ( ClassificationError, FlowError, diff --git a/posydon/binary_evol/track_match.py b/posydon/binary_evol/track_match.py index 8eb599010..5a7c0297e 100644 --- a/posydon/binary_evol/track_match.py +++ b/posydon/binary_evol/track_match.py @@ -22,12 +22,6 @@ from scipy.optimize import minimize, root import posydon.utils.constants as const -from posydon.utils.key_library import ( - DEFAULT_FINAL_KEYS, - DEFAULT_PROFILE_KEYS, - DEFAULT_TRANSLATED_KEYS, - KEYS_POSITIVE, -) from posydon.binary_evol.flow_chart import ( STAR_STATES_CO, STAR_STATES_FOR_HMS_MATCHING, @@ -44,6 +38,12 @@ set_binary_to_failed, ) from posydon.utils.interpolators import SingleStarInterpolator +from posydon.utils.key_library import ( + DEFAULT_FINAL_KEYS, + DEFAULT_PROFILE_KEYS, + DEFAULT_TRANSLATED_KEYS, + KEYS_POSITIVE, +) from posydon.utils.posydonerror import MatchingError, NumericalError, POSYDONError from posydon.utils.posydonwarning import Pwarn