Skip to content

Commit 90c2f56

Browse files
committed
fixing tests with SSEDict
1 parent 0b79526 commit 90c2f56

File tree

4 files changed

+57
-36
lines changed

4 files changed

+57
-36
lines changed

src/cosmic/evolve.py

+22-26
Original file line numberDiff line numberDiff line change
@@ -261,24 +261,24 @@ def evolve(cls, initialbinarytable, pool=None, **kwargs):
261261
initialbinarytable = initialbinarytable.assign(randomseed=kwargs.pop('randomseed', seed))
262262
if 'bin_num' not in initialbinarytable.keys():
263263
initialbinarytable = initialbinarytable.assign(bin_num=np.arange(idx, idx + len(initialbinarytable)))
264-
265-
if SSEDict['stellar_engine'] == 'metisse':
266-
for k, v in SSEDict.items():
267-
if k in initialbinarytable.keys():
268-
warnings.warn("The value for {0} in initial binary table is being "
269-
"overwritten by the value of {0} from either the params "
270-
"file or the SSEDict.".format(k))
271-
# assigning values this way work for most of the parameters.:
272264

273-
kwargs1 = {k: v}
265+
if SSEDict:
266+
if SSEDict['stellar_engine'] == 'metisse':
267+
for k, v in SSEDict.items():
268+
if k in initialbinarytable.keys():
269+
warnings.warn("The value for {0} in initial binary table is being "
270+
"overwritten by the value of {0} from either the params "
271+
"file or the SSEDict.".format(k))
272+
# assigning values this way work for most of the parameters.:
273+
274+
kwargs1 = {k: v}
275+
initialbinarytable = initialbinarytable.assign(**kwargs1)
276+
elif SSEDict['stellar_engine'] == 'sse':
277+
kwargs1 = {'stellar_engine': 'sse'}
274278
initialbinarytable = initialbinarytable.assign(**kwargs1)
275-
elif SSEDict['stellar_engine'] == 'sse':
276-
kwargs1 = {'stellar_engine': 'sse'}
277-
initialbinarytable = initialbinarytable.assign(**kwargs1)
278-
for col in ['path_to_tracks', 'path_to_he_tracks']:
279-
INITIAL_BINARY_TABLE_SAVE_COLUMNS.remove(col)
280-
INITIAL_CONDITIONS_PASS_COLUMNS.remove(col)
281-
279+
for col in ['path_to_tracks', 'path_to_he_tracks']:
280+
kwargs1 = {col: ''}
281+
initialbinarytable = initialbinarytable.assign(**kwargs1)
282282

283283
for k, v in BSEDict.items():
284284
if k in initialbinarytable.keys():
@@ -338,7 +338,7 @@ def evolve(cls, initialbinarytable, pool=None, **kwargs):
338338
# and either a dictionary or an inifile was not provided
339339
# then we need to raise an ValueError and tell the user to provide
340340
# either a dictionary or an inifile or add more columns
341-
if not BSEDict:
341+
if BSEDict and SSEDict is None:
342342
if ((not set(INITIAL_BINARY_TABLE_SAVE_COLUMNS).issubset(initialbinarytable.columns)) and
343343
(not set(INITIAL_CONDITIONS_PASS_COLUMNS).issubset(initialbinarytable.columns))):
344344
raise ValueError("You are passing BSE parameters as columns in the "
@@ -347,14 +347,10 @@ def evolve(cls, initialbinarytable, pool=None, **kwargs):
347347
"you have all BSE parameters as columns {0} or {1}.".format(
348348
INITIAL_BINARY_TABLE_SAVE_COLUMNS, INITIAL_CONDITIONS_PASS_COLUMNS))
349349

350-
if not SSEDict:
351-
if ((not set(INITIAL_BINARY_TABLE_SAVE_COLUMNS).issubset(initialbinarytable.columns)) and
352-
(not set(INITIAL_CONDITIONS_PASS_COLUMNS).issubset(initialbinarytable.columns))):
353-
raise ValueError("You are passing BSE parameters as columns in the "
354-
"initial binary table but not all BSE parameters are defined. "
355-
"Please pass a BSEDict or a params file or make sure "
356-
"you have all BSE parameters as columns {0} or {1}.".format(
357-
INITIAL_BINARY_TABLE_SAVE_COLUMNS, INITIAL_CONDITIONS_PASS_COLUMNS))
350+
if (BSEDict and not SSEDict) or (SSEDict and not BSEDict):
351+
raise ValueError("If you are passing BSE parameters as columns in the "
352+
"initial binary table you must also pass SSE parameters "
353+
"in the initial binary table.")
358354

359355
# If you did not supply the natal kick or qcrit_array or fprimc_array in the BSEdict then we construct
360356
# it from the initial conditions table
@@ -372,7 +368,7 @@ def evolve(cls, initialbinarytable, pool=None, **kwargs):
372368
initialbinarytable = initialbinarytable.assign(fprimc_array=initialbinarytable[FPRIMC_COLUMNS].values.tolist())
373369

374370
if (pd.Series(ALPHA_COLUMNS).isin(initialbinarytable.keys()).all()) and ('alpha1' not in BSEDict):
375-
initialbinarytable = initialbinarytable.assign(alpha=initialbinarytable[ALPHA_COLUMNS].values.tolist())
371+
initialbinarytable = initialbinarytable.assign(alpha1=initialbinarytable[ALPHA_COLUMNS].values.tolist())
376372

377373
if (pd.Series(ACCLIM_COLUMNS).isin(initialbinarytable.keys()).all()) and ('acc_lim' not in BSEDict):
378374
initialbinarytable = initialbinarytable.assign(acc_lim=initialbinarytable[ACCLIM_COLUMNS].values.tolist())

src/cosmic/tests/data/Params.ini

+29-3
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,29 @@ bcm_bpp_initCond_filter = False
7474
seed = 42
7575

7676

77+
[sse]
78+
79+
; stellar_engine specifies which engine to use for individual single star
80+
; evolution. There are two choices: metisse and sse where sse uses the
81+
; 'Hurley' tracks fits to the Pols+1998 grid. All results run with COSMIC
82+
; prior to version 3.5 are equivalent to using sse as the enine
83+
84+
stellar_engine = 'sse'
85+
86+
; path_to_tracks specifies the path to hydrogen rich stellar evolution tracks
87+
; specified as EEPs (equivalent evolutionary points). If stellar_engine is not
88+
; metisse, leave the path as an empty string
89+
90+
path_to_tracks = ''
91+
92+
; path_to_tracks specifies the path to helium-star stellar evolution tracks
93+
; specified as EEPs (equivalent evolutionary points). If stellar_engine is not
94+
; metisse, leave the path as an empty string
95+
96+
path_to_he_tracks = ''
97+
98+
99+
77100
[bse]
78101

79102
;;;;;;;;;;;;;;;;;;;;;;
@@ -154,8 +177,10 @@ acc2=1.5
154177
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
155178

156179
; alpha1 is the common-envelope efficiency parameter
157-
; default=1.0
158-
alpha1 = 1.0
180+
; It is a list so we can specify a different ejection efficiencies
181+
; for the primary and secondary
182+
; default=[1.0, 1.0]
183+
alpha1 = [1.0, 1.0]
159184

160185
; lambdaf is the binding energy factor for common envelope evolution
161186
; lambdaf>0.0 uses variable lambda prescription written by Onno Pols
@@ -366,7 +391,8 @@ don_lim = -1
366391
; acc_lim = -2: assumes the accretion is limited to tkh_acc for MS/CHeB
367392
; acc_lim = -3: assumes the accretion is limited by 10*tkh_acc for all fusing stars
368393
; acc_lim = -4: assumes the accretion is limited by tkh_for all fusing stars
369-
acc_lim = -1
394+
; it is a list so we can specify different accretion limits for the primary and secondary
395+
acc_lim = [-1, -1]
370396

371397
;;;;;;;;;;;;;;;;;;;
372398
;;; TIDES FLAGS ;;;
Binary file not shown.

src/cosmic/tests/test_evolve.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
INIT_CONDITIONS = pd.read_hdf(os.path.join(TEST_DATA_DIR, 'initial_conditions_for_testing.hdf5'), key='initC')
2222

2323
init_conds_columns = initialbinarytable.INITIAL_CONDITIONS_COLUMNS_ALL
24-
2524
INIT_CONDITIONS_NO_BSE_COLUMNS = INIT_CONDITIONS[init_conds_columns]
2625
BPP_DF = pd.read_hdf(os.path.join(TEST_DATA_DIR, 'unit_tests_results.hdf5'), key='bpp')
2726
BCM_DF = pd.read_hdf(os.path.join(TEST_DATA_DIR, 'unit_tests_results.hdf5'), key='bcm')
@@ -34,7 +33,7 @@
3433
2.0/21.0,2.0/21.0,2.0/21.0,2.0/21.0,2.0/21.0,2.0/21.0]
3534
BSEDict['grflag'] = 1
3635
BSEDict['don_lim'] = -1
37-
BSEDict['acc_lim'] = -1
36+
BSEDict['acc_lim'] = [-1, -1]
3837
BSEDict['wd_mass_lim'] = 0
3938
SSEDict = {'stellar_engine': 'sse'}
4039

@@ -46,14 +45,14 @@ def test_single_evolve_with_table(self):
4645

4746
# Check that the sample_primary function samples mass correctly
4847
EvolvedBinaryBPP, EvolvedBinaryBCM, initCond, kick_info = Evolve.evolve(
49-
initialbinarytable=INIT_CONDITIONS, randomseed=523574, SSEDict=SSEDict)
48+
initialbinarytable=INIT_CONDITIONS, randomseed=523574)
5049

5150
pd.testing.assert_frame_equal(EvolvedBinaryBPP, BPP_DF, check_dtype=False, check_exact=False)
5251
pd.testing.assert_frame_equal(EvolvedBinaryBCM, BCM_DF, check_dtype=False, check_exact=False)
5352

5453
def test_single_evolve_with_dict(self):
5554
EvolvedBinaryBPP, EvolvedBinaryBCM, initCond, kick_info = Evolve.evolve(
56-
initialbinarytable=INIT_CONDITIONS_NO_BSE_COLUMNS, BSEDict=BSEDict, randomseed=523574)
55+
initialbinarytable=INIT_CONDITIONS_NO_BSE_COLUMNS, BSEDict=BSEDict, SSEDict=SSEDict, randomseed=523574)
5756

5857
pd.testing.assert_frame_equal(EvolvedBinaryBPP, BPP_DF, check_dtype=False, check_exact=False)
5958
pd.testing.assert_frame_equal(EvolvedBinaryBCM, BCM_DF, check_dtype=False, check_exact=False)
@@ -67,7 +66,7 @@ def test_single_evolve_with_inifile(self):
6766

6867
def test_single_evolve_with_dict_and_table(self):
6968
EvolvedBinaryBPP, EvolvedBinaryBCM, initCond, kick_info = Evolve.evolve(
70-
initialbinarytable=INIT_CONDITIONS, BSEDict=BSEDict, randomseed=523574)
69+
initialbinarytable=INIT_CONDITIONS, BSEDict=BSEDict, SSEDict=SSEDict, randomseed=523574)
7170

7271
pd.testing.assert_frame_equal(EvolvedBinaryBPP, BPP_DF, check_dtype=False, check_exact=False)
7372
pd.testing.assert_frame_equal(EvolvedBinaryBCM, BCM_DF, check_dtype=False, check_exact=False)
@@ -82,7 +81,7 @@ def test_multi_evolve_with_table(self):
8281

8382
def test_multi_evolve_with_dict(self):
8483
EvolvedBinaryBPP, EvolvedBinaryBCM, initCond, kick_info = Evolve.evolve(
85-
initialbinarytable=INIT_CONDITIONS_NO_BSE_COLUMNS, BSEDict=BSEDict, randomseed=523574, n_per_block=100)
84+
initialbinarytable=INIT_CONDITIONS_NO_BSE_COLUMNS, BSEDict=BSEDict, SSEDict=SSEDict, randomseed=523574, n_per_block=100)
8685

8786
pd.testing.assert_frame_equal(EvolvedBinaryBPP, BPP_DF, check_dtype=False, check_exact=False)
8887
pd.testing.assert_frame_equal(EvolvedBinaryBCM, BCM_DF, check_dtype=False, check_exact=False)
@@ -96,7 +95,7 @@ def test_multi_evolve_with_inifile(self):
9695

9796
def test_multi_evolve_with_dict_and_table(self):
9897
EvolvedBinaryBPP, EvolvedBinaryBCM, initCond, kick_info = Evolve.evolve(
99-
initialbinarytable=INIT_CONDITIONS, BSEDict=BSEDict, randomseed=523574, n_per_block=100)
98+
initialbinarytable=INIT_CONDITIONS, BSEDict=BSEDict, SSEDict=SSEDict, randomseed=523574, n_per_block=100)
10099

101100
pd.testing.assert_frame_equal(EvolvedBinaryBPP, BPP_DF, check_dtype=False, check_exact=False)
102101
pd.testing.assert_frame_equal(EvolvedBinaryBCM, BCM_DF, check_dtype=False, check_exact=False)

0 commit comments

Comments
 (0)