Skip to content

Commit d54bd83

Browse files
authored
Kb metisse add ce facc split (#630)
* trying to add git submodules to actions * splitting alphas and accretion limits for primary and secondary * forgot to add cosnt * fixing SSEDict columns in initial binary table * add in correct gfortran compilation * fixing benchmark to work with SSE, removing repeated compilation arguments * fixing tests with SSEDict * add ignore back in * fix tests and remove SSEDict from setreff for now
1 parent b3b9518 commit d54bd83

16 files changed

+635
-96
lines changed

.github/workflows/python-package.yml

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ jobs:
1616

1717
steps:
1818
- uses: actions/checkout@v2
19+
with:
20+
submodules: true
1921
- name: Set up Python ${{ matrix.python-version }}
2022
uses: actions/setup-python@v4
2123
with:

.gitignore

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so*
8+
9+
# Distribution / packaging
10+
.Python
11+
env/
12+
build/
13+
develop-eggs/
14+
dist/
15+
downloads/
16+
eggs/
17+
.eggs/
18+
lib/
19+
lib64/
20+
parts/
21+
sdist/
22+
var/
23+
wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
28+
# PyInstaller
29+
# Usually these files are written by a python script from a template
30+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
31+
*.manifest
32+
*.spec
33+
34+
# Installer logs
35+
pip-log.txt
36+
pip-delete-this-directory.txt
37+
38+
# Unit test / coverage reports
39+
htmlcov/
40+
.tox/
41+
.coverage
42+
.coverage.*
43+
.cache
44+
nosetests.xml
45+
coverage.xml
46+
*.cover
47+
.hypothesis/
48+
49+
# Translations
50+
*.mo
51+
*.pot
52+
53+
# Django stuff:
54+
*.log
55+
local_settings.py
56+
57+
# Flask stuff:
58+
instance/
59+
.webassets-cache
60+
61+
# Scrapy stuff:
62+
.scrapy
63+
64+
# Sphinx documentation
65+
docs/_build/
66+
docs/api/
67+
docs/input.hdf5
68+
docs/input.fits
69+
70+
# PyBuilder
71+
target/
72+
73+
# Jupyter Notebook
74+
.ipynb_checkpoints
75+
76+
# pyenv
77+
.python-version
78+
79+
# celery beat schedule file
80+
celerybeat-schedule
81+
82+
# SageMath parsed files
83+
*.sage.py
84+
85+
# dotenv
86+
.env
87+
88+
# virtualenv
89+
.venv
90+
venv/
91+
ENV/
92+
93+
# Spyder project settings
94+
.spyderproject
95+
.spyproject
96+
97+
# Rope project settings
98+
.ropeproject
99+
100+
# mkdocs documentation
101+
/site
102+
103+
# mypy
104+
.mypy_cache/

ci/compile_benchmark.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
gfortran -coverage -fprofile-arcs -ftest-coverage -O0 src/cosmic/src/assign_remnant.f src/cosmic/src/benchmarkevolv2.f src/cosmic/src/comenv.f src/cosmic/src/corerd.f src/cosmic/src/deltat.f src/cosmic/src/dgcore.f src/cosmic/src/evolv2.f src/cosmic/src/gntage.f src/cosmic/src/hrdiag.f src/cosmic/src/hrdiag_remnant.f src/cosmic/src/instar.f src/cosmic/src/kick.f src/cosmic/src/mix.f src/cosmic/src/mlwind.f src/cosmic/src/mrenv.f src/cosmic/src/ran3.f src/cosmic/src/rl.f src/cosmic/src/star.f src/cosmic/src/zcnsts.f src/cosmic/src/zfuncs.f src/cosmic/src/concatkstars.f src/cosmic/src/bpp_array.f src/cosmic/src/checkstate.f -o benchmarkevolv2.exe -I src/cosmic/src -Wl,-rpath,${CONDA_PREFIX}/lib
2-
./benchmarkevolv2.exe
1+
gfortran -coverage -fprofile-arcs -ftest-coverage -O0 src/cosmic/src/hrdiag_remnant.f src/cosmic/src/assign_remnant.f src/cosmic/src/benchmarkevolv2.f src/cosmic/src/corerd.f src/cosmic/src/comenv.f src/cosmic/src/dgcore.f src/cosmic/src/evolv2.f src/cosmic/src/gntage.f src/cosmic/src/instar.f src/cosmic/src/kick.f src/cosmic/src/mix.f src/cosmic/src/mrenv.f src/cosmic/src/ran3.f src/cosmic/src/rl.f src/cosmic/src/concatkstars.f src/cosmic/src/comprad.f src/cosmic/src/bpp_array.f src/cosmic/src/checkstate.f src/cosmic/src/deltat.f src/cosmic/src/mlwind.f src/cosmic/src/hrdiag.f src/cosmic/src/star.f src/cosmic/src/zcnsts.f src/cosmic/src/SSE/SSE_deltat.f src/cosmic/src/SSE/SSE_mlwind.f src/cosmic/src/SSE/SSE_hrdiag.f src/cosmic/src/SSE/SSE_star.f src/cosmic/src/SSE/SSE_zcnsts.f src/cosmic/src/SSE/SSE_zfuncs.f src/cosmic/src/SSE/SSE_gntage.f src/cosmic/src/METISSE/src/track_support.f90 src/cosmic/src/METISSE/src/z_support.f90 src/cosmic/src/METISSE/src/sse_support.f90 src/cosmic/src/METISSE/src/remnant_support.f90 src/cosmic/src/METISSE/src/interp_support.f90 src/cosmic/src/METISSE/src/METISSE_gntage.f90 src/cosmic/src/METISSE/src/METISSE_deltat.f90 src/cosmic/src/METISSE/src/METISSE_mlwind.f90 src/cosmic/src/METISSE/src/METISSE_hrdiag.f90 src/cosmic/src/METISSE/src/METISSE_star.f90 src/cosmic/src/METISSE/src/METISSE_zcnsts.f90 src/cosmic/src/METISSE/src/comenv_lambda.f90 src/cosmic/src/METISSE/src/METISSE_miscellaneous.f90 src/cosmic/src/assign_commons_COSMIC.f90 -o benchmarkevolv2.exe -I src/cosmic/src -Wl,-rpath,${CONDA_PREFIX}/lib
2+
./benchmarkevolv2.exe

meson.build

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
project('cosmic',
2+
'c',
3+
'fortran',
4+
version : '3.4.10',
5+
default_options: ['warning_level=0', 'optimization=3'],
6+
)
7+
8+
# Enable fortran and check arguments
9+
# add_languages('fortran', native: false)
10+
ff = meson.get_compiler('fortran')
11+
f_args = ff.get_supported_arguments('-fPIC')
12+
add_project_arguments(f_args, language: 'fortran')
13+
14+
py3 = import('python').find_installation()
15+
16+
numpy_include_dir = run_command(py3, ['-c', 'import numpy; print(numpy.get_include())'], check: true).stdout().strip()
17+
f2py_include_dir = run_command(py3, ['-c', 'import numpy.f2py; print(numpy.f2py.get_include())'], check: true).stdout().strip()
18+
inc_np = include_directories(numpy_include_dir, f2py_include_dir)
19+
20+
f2py_source = custom_target(
21+
'evolvebin-target',
22+
input : ['src/cosmic/src/evolv2.f', 'src/cosmic/src/comprad.f'],
23+
output : ['_evolvebinmodule.c', '_evolvebin-f2pywrappers.f'],
24+
command : [py3, '-m', 'numpy.f2py', '@INPUT@', '-m', '_evolvebin', '--lower', '@OUTDIR']
25+
)
26+
27+
lib_source = [
28+
'src/cosmic/src/hrdiag_remnant.f',
29+
'src/cosmic/src/assign_remnant.f',
30+
'src/cosmic/src/benchmarkevolv2.f',
31+
'src/cosmic/src/corerd.f',
32+
'src/cosmic/src/comenv.f',
33+
'src/cosmic/src/dgcore.f',
34+
'src/cosmic/src/evolv2.f',
35+
'src/cosmic/src/gntage.f',
36+
'src/cosmic/src/instar.f',
37+
'src/cosmic/src/kick.f',
38+
'src/cosmic/src/mix.f',
39+
'src/cosmic/src/mrenv.f',
40+
'src/cosmic/src/ran3.f',
41+
'src/cosmic/src/rl.f',
42+
'src/cosmic/src/concatkstars.f',
43+
'src/cosmic/src/comprad.f',
44+
'src/cosmic/src/bpp_array.f',
45+
'src/cosmic/src/checkstate.f',
46+
'src/cosmic/src/deltat.f',
47+
'src/cosmic/src/mlwind.f',
48+
'src/cosmic/src/hrdiag.f',
49+
'src/cosmic/src/star.f',
50+
'src/cosmic/src/zcnsts.f',
51+
'src/cosmic/src/SSE/SSE_deltat.f',
52+
'src/cosmic/src/SSE/SSE_mlwind.f',
53+
'src/cosmic/src/SSE/SSE_hrdiag.f',
54+
'src/cosmic/src/SSE/SSE_star.f',
55+
'src/cosmic/src/SSE/SSE_zcnsts.f',
56+
'src/cosmic/src/SSE/SSE_zfuncs.f',
57+
'src/cosmic/src/SSE/SSE_gntage.f',
58+
'src/cosmic/src/METISSE/src/METISSE_gntage.f90',
59+
'src/cosmic/src/METISSE/src/METISSE_deltat.f90',
60+
'src/cosmic/src/METISSE/src/METISSE_mlwind.f90',
61+
'src/cosmic/src/METISSE/src/METISSE_hrdiag.f90',
62+
'src/cosmic/src/METISSE/src/METISSE_star.f90',
63+
'src/cosmic/src/METISSE/src/METISSE_zcnsts.f90',
64+
'src/cosmic/src/METISSE/src/track_support.f90',
65+
'src/cosmic/src/METISSE/src/z_support.f90',
66+
'src/cosmic/src/METISSE/src/sse_support.f90',
67+
'src/cosmic/src/METISSE/src/remnant_support.f90',
68+
'src/cosmic/src/METISSE/src/interp_support.f90',
69+
'src/cosmic/src/METISSE/src/comenv_lambda.f90',
70+
'src/cosmic/src/METISSE/src/METISSE_miscellaneous.f90',
71+
'src/cosmic/src/assign_commons_COSMIC.f90']
72+
73+
# Detect operating system and set appropriate linker flags
74+
host_system = host_machine.system()
75+
76+
if host_system == 'darwin'
77+
ldflags = ['-Wl,-no_compact_unwind']
78+
else
79+
ldflags = [] # No special flags for other systems
80+
endif
81+
82+
evolvebin_module = py3.extension_module('_evolvebin',
83+
f2py_source,
84+
lib_source,
85+
f2py_include_dir / 'fortranobject.c',
86+
include_directories: inc_np,
87+
link_args: ldflags,
88+
install : true,
89+
install_dir : py3.get_install_dir() / 'cosmic'
90+
)
91+
92+
93+
module_dirs = ['src/cosmic', 'src/cosmic/bse_utils',
94+
'src/cosmic/sample', 'src/cosmic/tests']
95+
96+
# Install modules
97+
foreach mod_dir: module_dirs
98+
install_subdir(mod_dir,
99+
install_dir: py3.get_install_dir())
100+
endforeach
101+
102+
103+
python_script = 'bin/cosmic-pop'
104+
install_data(python_script, install_dir: get_option('bindir'))

src/cosmic/evolve.py

+54-13
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
else:
108108
INITIAL_BINARY_TABLE_SAVE_COLUMNS = INITIAL_CONDITIONS_PASS_COLUMNS.copy()
109109

110-
for col in ['natal_kick_array', 'qcrit_array', 'fprimc_array']:
110+
for col in ['natal_kick_array', 'qcrit_array', 'fprimc_array', 'alpha1', 'acc_lim']:
111111
INITIAL_BINARY_TABLE_SAVE_COLUMNS.remove(col)
112112

113113
NATAL_KICK_COLUMNS = ['natal_kick',
@@ -123,10 +123,14 @@
123123

124124
QCRIT_COLUMNS = ['qcrit_{0}'.format(kstar) for kstar in range(0, 16)]
125125
FPRIMC_COLUMNS = ['fprimc_{0}'.format(kstar) for kstar in range(0, 16)]
126+
ALPHA_COLUMNS = ['alpha1_{0}'.format(star) for star in range(0, 2)]
127+
ACCLIM_COLUMNS = ['acc_lim_{0}'.format(star) for star in range(0, 2)]
126128

127129
INITIAL_BINARY_TABLE_SAVE_COLUMNS.extend(FLATTENED_NATAL_KICK_COLUMNS)
128130
INITIAL_BINARY_TABLE_SAVE_COLUMNS.extend(QCRIT_COLUMNS)
129131
INITIAL_BINARY_TABLE_SAVE_COLUMNS.extend(FPRIMC_COLUMNS)
132+
INITIAL_BINARY_TABLE_SAVE_COLUMNS.extend(ALPHA_COLUMNS)
133+
INITIAL_BINARY_TABLE_SAVE_COLUMNS.extend(ACCLIM_COLUMNS)
130134

131135
# BSE doesn't need the binary fraction, so just add to columns for saving
132136
INITIAL_BINARY_TABLE_SAVE_COLUMNS.insert(7, 'binfrac')
@@ -242,11 +246,11 @@ def evolve(cls, initialbinarytable, pool=None, **kwargs):
242246
# in order to verify that the values in the table
243247
# are valid
244248
utils.error_check(BSEDict, SSEDict)
245-
249+
246250
# check the initial conditions of the system and warn user if
247251
# anything is weird about them, such as the star starts
248252
# in Roche Lobe overflow
249-
utils.check_initial_conditions(initialbinarytable,SSEDict)
253+
utils.check_initial_conditions(initialbinarytable)
250254

251255
# assign some columns based on keyword arguments but that
252256
# can be overwritten by the params or BSEDict
@@ -257,15 +261,24 @@ def evolve(cls, initialbinarytable, pool=None, **kwargs):
257261
initialbinarytable = initialbinarytable.assign(randomseed=kwargs.pop('randomseed', seed))
258262
if 'bin_num' not in initialbinarytable.keys():
259263
initialbinarytable = initialbinarytable.assign(bin_num=np.arange(idx, idx + len(initialbinarytable)))
260-
261-
for k, v in SSEDict.items():
262-
if k in initialbinarytable.keys():
263-
warnings.warn("The value for {0} in initial binary table is being "
264-
"overwritten by the value of {0} from either the params "
265-
"file or the SSEDict.".format(k))
266-
# assigning values this way work for most of the parameters.
267-
kwargs1 = {k: v}
268-
initialbinarytable = initialbinarytable.assign(**kwargs1)
264+
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'}
278+
initialbinarytable = initialbinarytable.assign(**kwargs1)
279+
for col in ['path_to_tracks', 'path_to_he_tracks']:
280+
kwargs1 = {col: ''}
281+
initialbinarytable = initialbinarytable.assign(**kwargs1)
269282

270283
for k, v in BSEDict.items():
271284
if k in initialbinarytable.keys():
@@ -299,6 +312,22 @@ def evolve(cls, initialbinarytable, pool=None, **kwargs):
299312
index=initialbinarytable.index,
300313
name='fprimc_{0}'.format(kstar))
301314
initialbinarytable.loc[:, 'fprimc_{0}'.format(kstar)] = columns_values
315+
elif k == 'alpha1':
316+
columns_values = [BSEDict['alpha1']] * len(initialbinarytable)
317+
initialbinarytable = initialbinarytable.assign(alpha1=columns_values)
318+
for kstar in range(0, 2):
319+
columns_values = pd.Series([BSEDict['alpha1'][kstar]] * len(initialbinarytable),
320+
index=initialbinarytable.index,
321+
name='alpha1_{0}'.format(kstar))
322+
initialbinarytable.loc[:, 'alpha1_{0}'.format(kstar)] = columns_values
323+
elif k == 'acc_lim':
324+
columns_values = [BSEDict['acc_lim']] * len(initialbinarytable)
325+
initialbinarytable = initialbinarytable.assign(acc_lim=columns_values)
326+
for kstar in range(0,2):
327+
columns_values = pd.Series([BSEDict['acc_lim'][kstar]] * len(initialbinarytable),
328+
index=initialbinarytable.index,
329+
name='acc_lim_{0}'.format(kstar))
330+
initialbinarytable.loc[:, 'acc_lim_{0}'.format(kstar)] = columns_values
302331
else:
303332
# assigning values this way work for most of the parameters.
304333
kwargs1 = {k: v}
@@ -309,14 +338,19 @@ def evolve(cls, initialbinarytable, pool=None, **kwargs):
309338
# and either a dictionary or an inifile was not provided
310339
# then we need to raise an ValueError and tell the user to provide
311340
# either a dictionary or an inifile or add more columns
312-
if not BSEDict:
341+
if BSEDict and SSEDict is None:
313342
if ((not set(INITIAL_BINARY_TABLE_SAVE_COLUMNS).issubset(initialbinarytable.columns)) and
314343
(not set(INITIAL_CONDITIONS_PASS_COLUMNS).issubset(initialbinarytable.columns))):
315344
raise ValueError("You are passing BSE parameters as columns in the "
316345
"initial binary table but not all BSE parameters are defined. "
317346
"Please pass a BSEDict or a params file or make sure "
318347
"you have all BSE parameters as columns {0} or {1}.".format(
319348
INITIAL_BINARY_TABLE_SAVE_COLUMNS, INITIAL_CONDITIONS_PASS_COLUMNS))
349+
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.")
320354

321355
# If you did not supply the natal kick or qcrit_array or fprimc_array in the BSEdict then we construct
322356
# it from the initial conditions table
@@ -333,6 +367,13 @@ def evolve(cls, initialbinarytable, pool=None, **kwargs):
333367
if (pd.Series(FPRIMC_COLUMNS).isin(initialbinarytable.keys()).all()) and ('fprimc_array' not in BSEDict):
334368
initialbinarytable = initialbinarytable.assign(fprimc_array=initialbinarytable[FPRIMC_COLUMNS].values.tolist())
335369

370+
if (pd.Series(ALPHA_COLUMNS).isin(initialbinarytable.keys()).all()) and ('alpha1' not in BSEDict):
371+
initialbinarytable = initialbinarytable.assign(alpha1=initialbinarytable[ALPHA_COLUMNS].values.tolist())
372+
373+
if (pd.Series(ACCLIM_COLUMNS).isin(initialbinarytable.keys()).all()) and ('acc_lim' not in BSEDict):
374+
initialbinarytable = initialbinarytable.assign(acc_lim=initialbinarytable[ACCLIM_COLUMNS].values.tolist())
375+
376+
336377
# need to ensure that the order of parameters that we pass to BSE
337378
# is correct
338379
initial_conditions = initialbinarytable[INITIAL_CONDITIONS_PASS_COLUMNS].to_dict('records')

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

0 commit comments

Comments
 (0)