Skip to content

Commit 6fbddb0

Browse files
committed
fix tests and remove SSEDict from setreff for now
1 parent d512661 commit 6fbddb0

File tree

5 files changed

+23
-25
lines changed

5 files changed

+23
-25
lines changed

src/cosmic/evolve.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,11 @@ def evolve(cls, initialbinarytable, pool=None, **kwargs):
246246
# in order to verify that the values in the table
247247
# are valid
248248
utils.error_check(BSEDict, SSEDict)
249-
249+
250250
# check the initial conditions of the system and warn user if
251251
# anything is weird about them, such as the star starts
252252
# in Roche Lobe overflow
253-
utils.check_initial_conditions(initialbinarytable,SSEDict)
253+
utils.check_initial_conditions(initialbinarytable)
254254

255255
# assign some columns based on keyword arguments but that
256256
# can be overwritten by the params or BSEDict
@@ -372,6 +372,7 @@ def evolve(cls, initialbinarytable, pool=None, **kwargs):
372372

373373
if (pd.Series(ACCLIM_COLUMNS).isin(initialbinarytable.keys()).all()) and ('acc_lim' not in BSEDict):
374374
initialbinarytable = initialbinarytable.assign(acc_lim=initialbinarytable[ACCLIM_COLUMNS].values.tolist())
375+
375376

376377
# need to ensure that the order of parameters that we pass to BSE
377378
# is correct

src/cosmic/sample/sampler/independent.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ def get_independent_sampler(
123123
met : `float`
124124
Sets the metallicity of the binary population where solar metallicity is zsun
125125
126+
SSEDict: `Dict`
127+
Sets the engine to use for individual stellar evolution
128+
126129
size : `int`
127130
Size of the population to sample
128131
@@ -287,8 +290,8 @@ def get_independent_sampler(
287290

288291
zsun = kwargs.pop("zsun", 0.02)
289292

290-
rad1 = initconditions.set_reff(SSEDict, mass1_binary, metallicity=met, zsun=zsun)
291-
rad2 = initconditions.set_reff(SSEDict, mass2_binary, metallicity=met, zsun=zsun)
293+
rad1 = initconditions.set_reff(mass1_binary, metallicity=met, zsun=zsun, SSEDict=SSEDict)
294+
rad2 = initconditions.set_reff(mass2_binary, metallicity=met, zsun=zsun, SSEDict=SSEDict)
292295

293296
# sample periods and eccentricities
294297
# if the porb_model is moe19, the metallicity needs to be supplied
@@ -1075,7 +1078,7 @@ def set_kstar(self, mass):
10751078

10761079
return kstar
10771080

1078-
def set_reff(self, SSEDict ,mass, metallicity, zsun=0.02):
1081+
def set_reff(self ,mass, metallicity, zsun=0.02, SSEDict=None):
10791082
"""
10801083
Better way to set the radii from BSE, by calling it directly
10811084

src/cosmic/tests/test_sample.py

+1
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ def test_sample_porb(self):
236236
mass2 = SAMPLECLASS.sample_secondary(primary_mass = mass1, qmin=0.1)
237237
rad1 = SAMPLECLASS.set_reff(mass=mass1, metallicity=0.02)
238238
rad2 = SAMPLECLASS.set_reff(mass=mass2, metallicity=0.02)
239+
print(rad1,rad2)
239240
porb,aRL_over_a = SAMPLECLASS.sample_porb(
240241
mass1, mass2, rad1, rad2, 'sana12', size=mass1.size
241242
)

src/cosmic/tests/test_utils.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,15 @@ def test_binwidth_selector(self):
144144
self.assertTrue(bw.round(3) == BW_KNUTH)
145145

146146
def test_error_check(self):
147-
BSEDict = {'xi': 0.5, 'bhflag': 1, 'neta': 0.5, 'windflag': 3, 'rtmsflag' : 0, 'wdflag': 0, 'alpha1': 1.0, 'pts1': 0.05, 'pts3': 0.02, 'pts2': 0.01, 'epsnov': 0.001, 'hewind': 1.0, 'ck': 1000, 'bwind': 0.0, 'lambdaf': 0.5, 'mxns': 3.0, 'beta': -1.0, 'tflag': 1, 'acc2': 1.5, 'nsflag': 4, 'ceflag': 0, 'eddfac': 1.0, 'ifflag': 0, 'bconst': 3000, 'sigma': 265.0, 'gamma': -2.0, 'pisn': 45.0, 'natal_kick_array' :[[-100.0,-100.0,-100.0,-100.0,0.0], [-100.0,-100.0,-100.0,-100.0,0.0]], 'bhsigmafrac' : 1.0, 'polar_kick_angle' : 90, 'qcrit_array' : [0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0], 'cekickflag' : 2, 'cehestarflag' : 0, 'cemergeflag' : 0, 'ecsn' : 2.5, 'ecsn_mlow' : 1.4, 'aic' : 1, 'ussn' : 0, 'sigmadiv' :-20.0, 'qcflag' : 3, 'eddlimflag' : 0, 'fprimc_array' : [2.0/21.0,2.0/21.0,2.0/21.0,2.0/21.0,2.0/21.0,2.0/21.0,2.0/21.0,2.0/21.0,2.0/21.0,2.0/21.0,2.0/21.0,2.0/21.0,2.0/21.0,2.0/21.0,2.0/21.0,2.0/21.0], 'rembar_massloss' : 0.5, 'zsun' : 0.02, 'kickflag' : 0, 'grflag' : 1, 'acc_lim' : -1, 'don_lim' : -1}
147+
BSEDict = {'xi': 0.5, 'bhflag': 1, 'neta': 0.5, 'windflag': 3, 'rtmsflag' : 0, 'wdflag': 0, 'alpha1': [1.0, 1.0], 'pts1': 0.05, 'pts3': 0.02, 'pts2': 0.01, 'epsnov': 0.001, 'hewind': 1.0, 'ck': 1000, 'bwind': 0.0, 'lambdaf': 0.5, 'mxns': 3.0, 'beta': -1.0, 'tflag': 1, 'acc2': 1.5, 'nsflag': 4, 'ceflag': 0, 'eddfac': 1.0, 'ifflag': 0, 'bconst': 3000, 'sigma': 265.0, 'gamma': -2.0, 'pisn': 45.0, 'natal_kick_array' :[[-100.0,-100.0,-100.0,-100.0,0.0], [-100.0,-100.0,-100.0,-100.0,0.0]], 'bhsigmafrac' : 1.0, 'polar_kick_angle' : 90, 'qcrit_array' : [0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0], 'cekickflag' : 2, 'cehestarflag' : 0, 'cemergeflag' : 0, 'ecsn' : 2.5, 'ecsn_mlow' : 1.4, 'aic' : 1, 'ussn' : 0, 'sigmadiv' :-20.0, 'qcflag' : 3, 'eddlimflag' : 0, 'fprimc_array' : [2.0/21.0,2.0/21.0,2.0/21.0,2.0/21.0,2.0/21.0,2.0/21.0,2.0/21.0,2.0/21.0,2.0/21.0,2.0/21.0,2.0/21.0,2.0/21.0,2.0/21.0,2.0/21.0,2.0/21.0,2.0/21.0], 'rembar_massloss' : 0.5, 'zsun' : 0.02, 'kickflag' : 0, 'grflag' : 1, 'acc_lim' : [-1, -1], 'don_lim' : -1}
148+
SSEDict = {'stellar_engine': 'sse'}
148149
filters = {'binary_state': [0], 'timestep_conditions' : 'dtp=None'}
149150
convergence = {'convergence_params': ['mass_1', 'mass_2', 'sep', 'ecc'], 'pop_select': 'formation',\
150151
'match': -5.0, 'convergence_limits' : {"sep" : [0,1000]}, 'match' : -3.0,\
151152
'apply_convergence_limits' : True}
152153
sampling = {'sampling_method': 'multidim', 'SF_start': '13700.0', 'SF_duration' : 0.0, 'metallicity': 0.02, 'keep_singles': False}
153-
utils.error_check(BSEDict,filters,convergence,sampling)
154-
utils.error_check(BSEDict)
154+
utils.error_check(BSEDict,SSEDict,filters,convergence,sampling)
155+
utils.error_check(BSEDict,SSEDict)
155156
assert 1==1
156157

157158
def test_warning_check(self):
@@ -160,7 +161,7 @@ def test_warning_check(self):
160161

161162
def test_no_RL_check_for_singles(self):
162163
"""Make sure you don't get a divide by zero error when checking for Roche Lobe Overflow"""
163-
BSEDict = {'xi': 1.0, 'bhflag': 1, 'neta': 0.5, 'windflag': 3, 'wdflag': 1, 'alpha1': 1.0,
164+
BSEDict = {'xi': 1.0, 'bhflag': 1, 'neta': 0.5, 'windflag': 3, 'wdflag': 1, 'alpha1': [1.0,1.0],
164165
'pts1': 0.001, 'pts3': 0.02, 'pts2': 0.01, 'epsnov': 0.001, 'hewind': 0.5,
165166
'ck': 1000, 'bwind': 0.0, 'lambdaf': 0.0, 'mxns': 3.0, 'beta': -1.0, 'tflag': 1,
166167
'acc2': 1.5, 'grflag': 1, 'remnantflag': 4, 'ceflag': 0, 'eddfac': 1.0,
@@ -177,8 +178,10 @@ def test_no_RL_check_for_singles(self):
177178
2.0/21.0, 2.0/21.0, 2.0/21.0, 2.0/21.0],
178179
'bhspinflag': 0, 'bhspinmag': 0.0, 'rejuv_fac': 1.0, 'rejuvflag': 0, 'htpmb': 1,
179180
'ST_cr': 1, 'ST_tide': 1, 'bdecayfac': 1, 'rembar_massloss': 0.5, 'kickflag': 0,
180-
'zsun': 0.014, 'bhms_coll_flag': 0, 'don_lim': -1, 'acc_lim': -1,
181+
'zsun': 0.014, 'bhms_coll_flag': 0, 'don_lim': -1, 'acc_lim': [-1,-1],
181182
'rtmsflag': 0, 'wd_mass_lim': 1}
183+
184+
SSEDict = {'stellar_engine': 'sse'}
182185

183186
initial_binaries = InitialBinaryTable.sampler('independent', np.linspace(0, 15, 16), np.linspace(0, 15, 16),
184187
binfrac_model=0.5, SF_start=10.0,
@@ -188,7 +191,7 @@ def test_no_RL_check_for_singles(self):
188191

189192
with warnings.catch_warnings():
190193
warnings.simplefilter("error")
191-
Evolve.evolve(initialbinarytable=initial_binaries, BSEDict=BSEDict)
194+
Evolve.evolve(initialbinarytable=initial_binaries, BSEDict=BSEDict, SSEDict=SSEDict)
192195

193196
def test_convert_kstar_evol_type(self):
194197
# convert to string

src/cosmic/utils.py

+4-14
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ def error_check(BSEDict, SSEDict, filters=None, convergence=None, sampling=None)
930930

931931
if not isinstance(SSEDict, dict):
932932
raise ValueError("SSE flags must be supplied via a dictionary")
933-
933+
934934
if filters is not None:
935935
if not isinstance(filters, dict):
936936
raise ValueError("Filters criteria must be supplied via a dictionary")
@@ -1604,13 +1604,13 @@ def error_check(BSEDict, SSEDict, filters=None, convergence=None, sampling=None)
16041604
return
16051605

16061606

1607-
def check_initial_conditions(full_initial_binary_table, SSEDict):
1607+
def check_initial_conditions(full_initial_binary_table):
16081608
"""Checks initial conditions and reports warnings
16091609
16101610
Only warning provided right now is if star begins in Roche lobe
16111611
overflow
16121612
"""
1613-
from cosmic import _evolvebin
1613+
#from cosmic import _evolvebin
16141614

16151615
def rzamsf(m):
16161616
"""A function to evaluate Rzams
@@ -1638,20 +1638,10 @@ def rzamsf(m):
16381638

16391639
if np.all(mass2 == 0.0):
16401640
return
1641-
elif (SSEDict["stellar_engine"] == "sse"):
1641+
else:
16421642
rzams1 = rzamsf(mass1)
16431643
rzams2 = rzamsf(mass2)
16441644

1645-
# TODO: the following section with METISSE is incomplete
1646-
# elif (SSEDict["stellar_engine"] == "metisse"):
1647-
# _evolvebin.se_flags.using_sse = False
1648-
# _evolvebin.se_flags.using_metisse = True
1649-
# path_to_tracks = SSEDict["path_to_tracks"]
1650-
# path_to_he_tracks = SSEDict["path_to_he_tracks"]
1651-
1652-
# rzams1 = _evolvebin.compute_r(mass1,z,len(mass1),path_to_tracks,path_to_he_tracks)
1653-
# rzams1 = _evolvebin.compute_r(mass2,z,len(mass2),path_to_tracks,path_to_he_tracks)
1654-
16551645
# assume some time step in order to calculate sep
16561646
yeardy = 365.24
16571647
aursun = 214.95

0 commit comments

Comments
 (0)