From 66cc712c1fbb4b3a51ed038f5d7c2e8f51e1169a Mon Sep 17 00:00:00 2001 From: poojanagrawal Date: Thu, 6 Jun 2024 16:08:46 -0400 Subject: [PATCH 1/4] METISSE now returns error instead of stopping the code --- src/cosmic/evolve.py | 20 ++++++++++++-------- src/cosmic/src/assign_commons_COSMIC.f90 | 17 +++++++++++++++-- src/cosmic/src/evolv2.f | 20 ++++++++++++++++++-- src/cosmic/src/zcnsts.f | 6 ++++-- src/cosmic/utils.py | 3 ++- 5 files changed, 51 insertions(+), 15 deletions(-) diff --git a/src/cosmic/evolve.py b/src/cosmic/evolve.py index 1ab8680fa..f04ac81b3 100644 --- a/src/cosmic/evolve.py +++ b/src/cosmic/evolve.py @@ -512,14 +512,18 @@ def _evolve_single_system(f): f["kick_info"], path_to_tracks, path_to_he_tracks) - bcm = _evolvebin.binary.bcm[:bcm_index].copy() - bpp = _evolvebin.binary.bpp[:bpp_index].copy() - _evolvebin.binary.bpp[:bpp_index] = np.zeros(bpp.shape) - _evolvebin.binary.bcm[:bcm_index] = np.zeros(bcm.shape) - - bpp = np.hstack((bpp, np.ones((bpp.shape[0], 1))*f["bin_num"])) - bcm = np.hstack((bcm, np.ones((bcm.shape[0], 1))*f["bin_num"])) - kick_info = np.hstack((kick_info, np.ones((kick_info.shape[0], 1))*f["bin_num"])) + + if bpp_index<0: + raise ValueError("Failed in METISSE_zcnsts") + else: + bcm = _evolvebin.binary.bcm[:bcm_index].copy() + bpp = _evolvebin.binary.bpp[:bpp_index].copy() + _evolvebin.binary.bpp[:bpp_index] = np.zeros(bpp.shape) + _evolvebin.binary.bcm[:bcm_index] = np.zeros(bcm.shape) + + bpp = np.hstack((bpp, np.ones((bpp.shape[0], 1))*f["bin_num"])) + bcm = np.hstack((bcm, np.ones((bcm.shape[0], 1))*f["bin_num"])) + kick_info = np.hstack((kick_info, np.ones((kick_info.shape[0], 1))*f["bin_num"])) return f, bpp, bcm, kick_info, _evolvebin.snvars.natal_kick_array.copy() diff --git a/src/cosmic/src/assign_commons_COSMIC.f90 b/src/cosmic/src/assign_commons_COSMIC.f90 index 5d00046fa..cb3c33093 100644 --- a/src/cosmic/src/assign_commons_COSMIC.f90 +++ b/src/cosmic/src/assign_commons_COSMIC.f90 @@ -9,7 +9,6 @@ subroutine assign_commons() real(dp) :: d - if(front_end == COSMIC) then ! use inputs from COSMIC @@ -25,11 +24,25 @@ subroutine assign_commons() end subroutine subroutine get_bhspin(bhspin,id) - use track_support + use track_support, only: tarr,dp implicit none integer, intent(in) :: id real(dp), intent(out) :: bhspin bhspin = tarr(id)% pars% bhspin end subroutine + + subroutine check_error(err) + use track_support, only: code_error + integer, intent(out) :: err + err = 0 + if(code_error) err = 1 + end subroutine + + + subroutine assign_error() + use track_support, only: code_error + code_error = .true. + end subroutine + diff --git a/src/cosmic/src/evolv2.f b/src/cosmic/src/evolv2.f index 5578dee36..11faab966 100644 --- a/src/cosmic/src/evolv2.f +++ b/src/cosmic/src/evolv2.f @@ -218,6 +218,7 @@ SUBROUTINE evolv2(kstar,mass,tb,ecc,z,tphysf, * REAL*8 qc_fixed LOGICAL switchedCE,disrupt + integer err Cf2py intent(in) kstar Cf2py intent(in) mass @@ -255,8 +256,6 @@ SUBROUTINE evolv2(kstar,mass,tb,ecc,z,tphysf, endif if(using_METISSE) CALL initialize_front_end('cosmic') - if(using_METISSE) call allocate_track(2,mass0) - * * Save the initial state. * @@ -340,10 +339,20 @@ SUBROUTINE evolv2(kstar,mass,tb,ecc,z,tphysf, * * Set the collision matrix. * + err = 0 if(using_cmc.eq.0)then * for SSE path_to_tracks and path_to_he_tracks are empty ('') CALL zcnsts(z,zpars,path_to_tracks,path_to_he_tracks) + if(using_METISSE) then + call check_error(err) + if (err>0) then + bpp_index_out = -1 + return + endif + endif endif + + if(using_METISSE) call allocate_track(2,mass0) kmin = 1 kmax = 2 @@ -4405,6 +4414,10 @@ SUBROUTINE evolv2(kstar,mass,tb,ecc,z,tphysf, evolve_type = 10.0 !added by PA for systems that stop evolving halfway if(iter.ge.loop) evolve_type = 100.0 + if (using_METISSE) then + call check_error(err) + if (err>0) evolve_type = 101.0 + end if rrl1 = rad(1)/rol(1) rrl2 = rad(2)/rol(2) teff1 = 1000.d0*((1130.d0*lumin(1)/ @@ -4537,6 +4550,7 @@ SUBROUTINE evolv2(kstar,mass,tb,ecc,z,tphysf, * CALL exit(0) * STOP endif + bcm(ip+1,1) = -1.0 bpp(jp+1,1) = -1.0 @@ -4546,6 +4560,8 @@ SUBROUTINE evolv2(kstar,mass,tb,ecc,z,tphysf, kick_info_out = kick_info endif if (using_METISSE) call dealloc_track() + + print*, 'bpp_index',bpp_index_out * END SUBROUTINE evolv2 diff --git a/src/cosmic/src/zcnsts.f b/src/cosmic/src/zcnsts.f index 40bd3af6b..aab51271a 100644 --- a/src/cosmic/src/zcnsts.f +++ b/src/cosmic/src/zcnsts.f @@ -4,11 +4,13 @@ SUBROUTINE zcnsts(z,zpars,path_to_tracks,path_to_he_tracks) real*8 z,zpars(20) CHARACTER*256 path_to_tracks,path_to_he_tracks - + integer :: ierr if (using_METISSE) then !WRITE(*,*) 'Calling METISSE_zcnsts',using_METISSE - CALL METISSE_zcnsts(z,zpars,path_to_tracks,path_to_he_tracks) + CALL METISSE_zcnsts(z,zpars,path_to_tracks, + & path_to_he_tracks,ierr) + if (ierr/=0) call assign_error() elseif (using_SSE) then !WRITE(*,*) 'Calling SSE_zcnsts' diff --git a/src/cosmic/utils.py b/src/cosmic/utils.py index 97fe6335c..1b69287df 100644 --- a/src/cosmic/utils.py +++ b/src/cosmic/utils.py @@ -1724,7 +1724,8 @@ def convert_kstar_evol_type(bpp): 14: "blue straggler", 15: "supernova of primary", 16: "supernova of secondary", - 100: "RLOF interpolation timeout error" + 100: "RLOF interpolation timeout error", + 101: "METISSE error" } evolve_type_string_to_int_dict = { From 8410e5e64a6bf25d5ca8c982f8d4e3afc40077df Mon Sep 17 00:00:00 2001 From: poojanagrawal Date: Thu, 6 Jun 2024 16:14:24 -0400 Subject: [PATCH 2/4] added back meson.build and .gitignore --- .gitignore | 104 +++++++++++++++++++++++++++++++++++++++++++++++++ meson.build | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 213 insertions(+) create mode 100644 .gitignore create mode 100644 meson.build diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..2a54457eb --- /dev/null +++ b/.gitignore @@ -0,0 +1,104 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so* + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ +docs/api/ +docs/input.hdf5 +docs/input.fits + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# dotenv +.env + +# virtualenv +.venv +venv/ +ENV/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ diff --git a/meson.build b/meson.build new file mode 100644 index 000000000..c6e2eee8b --- /dev/null +++ b/meson.build @@ -0,0 +1,109 @@ +project('cosmic', + 'c', + 'fortran', + version : '3.4.10', + default_options: ['warning_level=0', 'optimization=3'], +) + +# Enable fortran and check arguments +# add_languages('fortran', native: false) +ff = meson.get_compiler('fortran') +f_args = ff.get_supported_arguments('-fPIC') +add_project_arguments(f_args, language: 'fortran') + +py3 = import('python').find_installation() + +numpy_include_dir = run_command(py3, ['-c', 'import numpy; print(numpy.get_include())'], check: true).stdout().strip() +f2py_include_dir = run_command(py3, ['-c', 'import numpy.f2py; print(numpy.f2py.get_include())'], check: true).stdout().strip() +inc_np = include_directories(numpy_include_dir, f2py_include_dir) + +f2py_source = custom_target( + 'evolvebin-target', + input : ['src/cosmic/src/evolv2.f', 'src/cosmic/src/comprad.f'], + output : ['_evolvebinmodule.c', '_evolvebin-f2pywrappers.f'], + command : [py3, '-m', 'numpy.f2py', '@INPUT@', '-m', '_evolvebin', '--lower', '@OUTDIR'] +) + +lib_source = [ + '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/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/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/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/comenv_lambda.f90', + 'src/cosmic/src/METISSE/src/METISSE_miscellaneous.f90', + 'src/cosmic/src/assign_commons_COSMIC.f90'] + +# Detect operating system and set appropriate linker flags +host_system = host_machine.system() + +if host_system == 'darwin' + ldflags = ['-Wl,-no_compact_unwind'] +else + ldflags = [] # No special flags for other systems +endif + +evolvebin_module = py3.extension_module('_evolvebin', + f2py_source, + lib_source, + f2py_include_dir / 'fortranobject.c', + include_directories: inc_np, + link_args: ldflags, + install : true, + install_dir : py3.get_install_dir() / 'cosmic' +) + + +module_dirs = ['src/cosmic', 'src/cosmic/bse_utils', + 'src/cosmic/sample', 'src/cosmic/tests'] + +# Install modules +foreach mod_dir: module_dirs + install_subdir(mod_dir, + install_dir: py3.get_install_dir()) +endforeach + + +python_script = 'bin/cosmic-pop' +install_data(python_script, install_dir: get_option('bindir')) From 5c2a257a97050cbd20ab0e6d074c720687e1d931 Mon Sep 17 00:00:00 2001 From: poojanagrawal Date: Thu, 6 Jun 2024 17:09:13 -0400 Subject: [PATCH 3/4] updated metisse --- src/cosmic/src/METISSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cosmic/src/METISSE b/src/cosmic/src/METISSE index e6798b953..d08997883 160000 --- a/src/cosmic/src/METISSE +++ b/src/cosmic/src/METISSE @@ -1 +1 @@ -Subproject commit e6798b953a8beda86e2ea640b94aeb051f55ffbc +Subproject commit d08997883d42e3b3f89f139f97c497cf2b9c1447 From 1959112acf0d6132fa63b52093823918ab566d6a Mon Sep 17 00:00:00 2001 From: poojanagrawal Date: Thu, 6 Jun 2024 17:13:45 -0400 Subject: [PATCH 4/4] removed print statement --- src/cosmic/src/evolv2.f | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cosmic/src/evolv2.f b/src/cosmic/src/evolv2.f index c4711254c..e6ef134a4 100644 --- a/src/cosmic/src/evolv2.f +++ b/src/cosmic/src/evolv2.f @@ -4561,7 +4561,6 @@ SUBROUTINE evolv2(kstar,mass,tb,ecc,z,tphysf, endif if (using_METISSE) call dealloc_track() - print*, 'bpp_index',bpp_index_out * END SUBROUTINE evolv2