Skip to content

Commit

Permalink
Metisse integrate kb (#674)
Browse files Browse the repository at this point in the history
* offner22 primary mass dependent binary fraction (#644)

* added offner22 primary mass dependent binary fraction

* pinning numpy version because of new numpy version released on june 16 (https://stackoverflow.com/questions/78634235/numpy-dtype-size-changed-may-indicate-binary-incompatibility-expected-96-from)

* pinned numpy version so 3.7 works

---------

Co-authored-by: katiebreivik <kbreivik@flatironinstitute.org>

* Update utils.py (#648)

* Update utils.py

fix trapezoid import

* Update utils.py

missed one trapz

* version bump and dropping below python3.9 (#653)

* version bump and dropping below python3.9

* forward to numpy 1.26.0

* trying a different version

* fix trapz import

* Update build_wheels_and_publish.yml

explicitly install gcc

* Update build_wheels_and_publish.yml

trying to fix gfortran

* Update build_wheels_and_publish.yml

specifying path with symlink, checking path

* Update build_wheels_and_publish.yml (#654)

* Update build_wheels_and_publish.yml

* Update _version.py

* Update meson.build

* Update pyproject.toml (#655)

* Version bump for pip (#656)

* Update meson.build

* Update _version.py

* Add power law sampling options for ``porb`` and ``q`` (#651)

* add `q_power_law` parameter to change the power law of the mass ratio distribution

* allow custom power laws for orbital periods

* add mass ratio sampling test

* add test for custom porb power laws

* add to changelog

* New ``gamma`` option for circumbinary discs (#652)

* add new gamma prescription, add some int() statements

* add  details to docs page

* update ini files

* * Modifying the init file to include the commit hash. (#659)

*Created get_commit_hash file that finds the commit hash.

*Modified the meson.build file to run get_commit_hash when cosmic is installed.

* Created maximum wall time option (#620)

* Added compression options for pandas

* Created maximum wall time argument

* Add debugging setup, avoid NaNs from timestep issue (#647)

* setup debugging environment

* ignore a bunch of files

* add a testing fortran script

* move debugging to its own folder

* add a python script for creating the input

* add a simple makefile for testing

* important change: use `loop` instead of `1000` for timestep condition

* add a note about settings

* clean up vscode setup

* I can't count 🙃

* added new test suite location

* fixing numpy pinned version

* forcing numpy version I guess

---------

Co-authored-by: katiebreivik <kbreivik@flatironinstitute.org>
Co-authored-by: Katie Breivik <kbreivik@andrew.cmu.edu>

* allow a gamma of -3 in error_check (#661)

* fixing wheel build for pypi, hopefully

* tiny version bump (#665)

* Update _version.py

* Update pyproject.toml

add @TomWagg as dev

* Update meson.build

bump version

* Update build_wheels_and_publish.yml

* Update build_wheels_and_publish.yml

removing gfortran symlink

* Update build_wheels_and_publish.yml

* Update build_wheels_and_publish.yml (#666)

* Update build_wheels_and_publish.yml

* this should be a working build.

* add meson to requirements

* Fixing linux only wheel  (#667)

* Update build_wheels_and_publish.yml

* adding in python versions

* Update build_wheels_and_publish.yml

* Update meson.build

* Update meson.build

* Update pyproject.toml

* Pip fix (#669)

* add DS_Store to ignore

* finalllllly got the platform specific wheels built with a pure: false

* tiny bump in version for tag

* Update build_wheels_and_publish.yml

need to repair linux build with cibuildwheel for PyPI

* Update meson.build

forgot to bump version here

* build wheels and publish fix (#670)

* pins cibuildwheel==2.17.0 so that we can build across macOS versions.
* allow push to pypi

* add x_86 and arch compatibility for wheels (#671)

* Update build_wheels_and_publish.yml

* Update build_wheels_and_publish.yml

* Update meson.build version

* Update _version.py version

* Update pyproject.toml version

* Bump actions/download-artifact from 3 to 4.1.7 in /.github/workflows (#672)

Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 3 to 4.1.7.
- [Release notes](https://github.com/actions/download-artifact/releases)
- [Commits](actions/download-artifact@v3...v4.1.7)

---
updated-dependencies:
- dependency-name: actions/download-artifact
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: MarkGM02 <90350113+MarkGM02@users.noreply.github.com>
Co-authored-by: Tom Wagg <tomjwagg@gmail.com>
Co-authored-by: elenagonzalez870 <52000594+elenagonzalez870@users.noreply.github.com>
Co-authored-by: Vera Eris Del Favero <77068792+xevra@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
6 people authored Sep 11, 2024
1 parent fdd418b commit 2159a11
Show file tree
Hide file tree
Showing 28 changed files with 725 additions and 99 deletions.
67 changes: 29 additions & 38 deletions .github/workflows/build_wheels_and_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,19 @@ env:
CIBW_BUILD: "cp39-* cp310-*"
CIBW_SKIP: "*-win32 *musllinux*"
CIBW_MANYLINUX_X86_64_IMAGE: manylinux2014
CIBW_ARCHS_MACOS: "x86_64 arm64"
CIBW_BEFORE_BUILD: pip install numpy --config-settings=setup-args="-Dallow-noblas=true"
CIBW_BUILD_VERBOSITY: "1"
CIBW_ENVIRONMENT_MACOS: "FC=gfortran"

jobs:
build-wheels:
build-wheels-and-dist:
name: Build ${{ matrix.python-version }} wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
python-version: [3.9, "3.10"]

steps:
- uses: actions/checkout@v3
Expand All @@ -30,51 +33,39 @@ jobs:
with:
python-version: "3.10"

- name: Setup Mac
- name: link gfortran and hdf5
if: runner.os == 'macOS'
run: |
python -m pip install numpy h5py versioneer
sudo ln -s /opt/homebrew/bin/gfortran-12 /usr/local/bin/gfortran
brew reinstall hdf5
- name: Setup Linux
if: runner.os == 'Linux'
- name: Install numpy
run: |
python -m pip install numpy h5py versioneer
- name: Build wheels
python -m pip install --upgrade pip
python -m pip install numpy h5py versioneer
- name: Install dependencies
run: |
python -m pip install cibuildwheel==2.17.0 setuptools wheel build meson-python ninja meson
- name: Build source distribution (sdist)
run: |
python -m build --sdist --outdir dist
- name: Build wheels using cibuildwheel
run: |
sudo ln -s /opt/homebrew/bin/gfortran-11 /opt/homebrew/bin/gfortran || true
python -m pip install meson ninja build
meson setup build
meson compile -C build
python -m build --wheel --outdir wheelhouse
python -m cibuildwheel --output-dir dist
- uses: actions/upload-artifact@v3
with:
path: ./wheelhouse/*.whl

build-source-dist:
name: Build source dist
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-python@v4
name: Install Python
with:
python-version: "3.10"

- name: Build dist
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine numpy build meson ninja
pip install .
python -m build
- uses: actions/upload-artifact@v3
with:
path: ./dist/*.tar.gz
path: ./dist/*.tar.gz

- uses: actions/upload-artifact@v3
with:
path: ./dist/*.whl

publish:
needs: [build-wheels, build-source-dist]
needs: [build-wheels-and-dist]
name: Publish Python 🐍 distributions 📦 to PyPI and TestPyPI
runs-on: ${{ matrix.os }}
strategy:
Expand All @@ -90,7 +81,7 @@ jobs:
python-version: ${{ matrix.python-version }}

- name: Download builds
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4.1.7
with:
name: artifact
path: dist
Expand Down
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# ignore files without extensions
*
!/**/
!*.*

.DS_Store

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down Expand Up @@ -102,3 +109,9 @@ ENV/

# mypy
.mypy_cache/

*.o
binary.in
binary.dat
*.h5
fort.99
30 changes: 30 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/debug/test",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}/debug",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"preLaunchTask": "make",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
},
]
}
13 changes: 13 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "make",
"type": "shell",
"command": "make test",
"options": {
"cwd": "${workspaceFolder}/cosmic/src"
},
}
]
}
4 changes: 3 additions & 1 deletion bin/cosmic-pop
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ def parse_commandline():
help="Number of binaries to try before checking for "
"convergence, it will check ever Nstep binaries until "
"it reach Niter binaries", type=int, default=10000)
parser.add_argument("--max-wall-time", type=int, default=3155760,
help="Maximum wall time (seconds) for sampling binaries")
parser.add_argument("--binary_state", nargs='+', type=int)
parser.add_argument("--sampling_method")
parser.add_argument("--primary_model", help="Chooses the initial primary mass function from: salpeter55, kroupa93, kroupa01", type=str)
Expand Down Expand Up @@ -288,7 +290,7 @@ if __name__ == '__main__':
log_file.write("You have specified both qmin and m2_min.\n")
log_file.write("COSMIC will use qmin={} to determine the secondary masses in the initial sample.\n".format(args.qmin))

while (Nstep < args.Niter) & (np.max(match) > convergence['match']):
while (Nstep < args.Niter) & (np.max(match) > convergence['match']) & ((time.time() - start_time) < args.max_wall_time):
# Set random seed such that each iteration gets a unique, determinable seed
rand_seed = seed_int + Nstep
np.random.seed(rand_seed)
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@ See the discussed changes in our previous releases here: https://github.com/COSM
- Add `teff_1` and `teff_2` as variables that can be used to set `timestep_conditions`
- Add in `-1` option to turn off Magnetic Braking in htmb
- Added `central_bh` and `scale_with_central_bh` as options to the CMC sampler, in order to add central massive black holes to CMC initial conditions


## 3.4.11
- Added sampling options to ``independent`` sampler to allow for custom power law distributions for ``porb`` and ``q``
66 changes: 66 additions & 0 deletions debug/create_binary_in.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import pandas as pd

BSE_settings = {'xi': 1.0, 'bhflag': 1, 'neta': 0.5, 'windflag': 3, 'wdflag': 1, 'alpha1': 1.0,
'pts1': 0.001, 'pts3': 0.02, 'pts2': 0.01, 'epsnov': 0.001, 'hewind': 0.5,
'ck': 1000, 'bwind': 0.0, 'lambdaf': 0.0, 'mxns': 3.0, 'beta': -1.0, 'tflag': 1,
'acc2': 1.5, 'grflag': 1, 'remnantflag': 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.25,
'ecsn_mlow': 1.6, 'aic': 1, 'ussn': 0, 'sigmadiv': -20.0, 'qcflag': 5,
'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],
'bhspinflag': 0, 'bhspinmag': 0.0, 'rejuv_fac': 1.0, 'rejuvflag': 0, 'htpmb': 1,
'ST_cr': 1, 'ST_tide': 1, 'bdecayfac': 1, 'rembar_massloss': 0.5, 'kickflag': 0,
'zsun': 0.014, 'bhms_coll_flag': 0, 'don_lim': -1, 'acc_lim': -1, 'binfrac': 0.5,
'rtmsflag': 0, 'wd_mass_lim': 1, 'idum': 100}


def create_binary_in(mass0, tphysf, tb, kstar, Z, ecc, BSE_settings):
"""Create a binary.in file based on the given parameters
This follows the format in cosmic/src/test_bse.f and changes there would need to be reflected here.
"""
with open('binary.in', 'w') as f:
f.write(f'{mass0[0]} {mass0[1]} {tphysf} {tb} {kstar[0]} {kstar[1]} {Z} {ecc}\n')

lines = [
['neta', 'bwind', 'hewind', 'alpha1', 'lambdaf', 'windflag', 'rtmsflag'],
['ceflag', 'tflag', 'ifflag', 'wdflag', 'bhflag', 'remnantflag', 'mxns', 'idum'],
['pts1', 'pts2', 'pts3'],
['sigma', 'beta', 'xi', 'acc2', 'epsnov', 'eddfac', 'gamma']
]

for line in lines:
f.write(' '.join([str(BSE_settings[key]) for key in line]) + '\n')


def convert_initC_row_to_binary_in(initC_file, bin_num):
"""Convert a row from an initC file to a binary.in file
Parameters
----------
initC_file : `str`
Path to the initC file
bin_num : `int`
The binary number to convert
"""
# get binary from initC
initC = pd.read_hdf(initC_file, key="initC")
r = initC.loc[bin_num]

# update BSE settings with those in the binary
BSE_settings['idum'] = r['randomseed'].astype(int)
for key in BSE_settings:
if key in r:
BSE_settings[key] = r[key]

# create binary.in file
create_binary_in([r['mass_1'], r['mass_2']], r['tphysf'], r['porb'],
[r['kstar_1'].astype(int), r['kstar_2'].astype(int)],
r['metallicity'], r['ecc'], BSE_settings)
6 changes: 6 additions & 0 deletions docs/inifile/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,11 @@ common envelope occurs regardless of the choices below:
``-2`` : assumes material is lost from the system as
if it is a wind from the secondary

``-3`` : assumes mass is lost through the outer Lagrangian point,
forming a circumbinary disk. See Zapartas+17 Eq. 9 and
Artymowicz & Lubow (1994).


``>0`` : assumes that the lost material takes away a
fraction *gamma* of the orbital angular momentum

Expand Down Expand Up @@ -1104,6 +1109,7 @@ common envelope occurs regardless of the choices below:
eddfac = 1.0
; gamma is the angular momentum factor for mass lost during Roche-lobe overflow
; gamma=-3: assumes mass is lost through the outer Lagrangian point, forming a circumbinary disk. See Zapartas+17 Eq. 9 and Artymowicz & Lubow (1994).
; gamma=-2: assumes material is lost from the system as if it is a wind from the secondary (for super-Eddington mass transfer rates)
; gamma=-1: assumes the lost material carries with is the specific angular momentum of the primary
; gamma>0: assumes that the lost material take away a fraction (gamma) of the orbital angular momentum
Expand Down
1 change: 1 addition & 0 deletions examples/CMC_Params.ini
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ bhspinmag = 0.0
eddfac = 1.0

; gamma is the angular momentum factor for mass lost during RLO
; gamma=-3: assumes mass is lost through the outer Lagrangian point, forming a circumbinary disk. See Zapartas+17 Eq. 9 and Artymowicz & Lubow (1994).
; gamma=-2: assumes material is lost from the system as if it is a wind from the secondary (for super-Eddington mass transfer rates)
; gamma=-1: assumes the lost material carries with is the specific angular momentum of the primary
; gamma>0: assumes that the lost material take away a fraction (gamma) of the orbital angular momentum
Expand Down
1 change: 1 addition & 0 deletions examples/Params.ini
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ grflag = 1
eddfac = 1.0

; gamma is the angular momentum factor for mass lost during RLO
; gamma=-3: assumes mass is lost through the outer Lagrangian point, forming a circumbinary disk. See Zapartas+17 Eq. 9 and Artymowicz & Lubow (1994).
; gamma=-2: assumes material is lost from the system as if it is a wind from the secondary (for super-Eddington mass transfer rates)
; gamma=-1: assumes the lost material carries with is the specific angular momentum of the primary
; gamma>0: assumes that the lost material take away a fraction (gamma) of the orbital angular momentum
Expand Down
38 changes: 18 additions & 20 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
project('cosmic',
'c',
'fortran',
version : '3.4.13',
version : '3.4.16',
default_options: ['warning_level=0', 'optimization=3'],
)

Expand All @@ -11,23 +11,21 @@ ff = meson.get_compiler('fortran')
f_args = ff.get_supported_arguments('-fPIC')
add_project_arguments(f_args, language: 'fortran')

py3 = import('python').find_installation()

py3 = import('python').find_installation(pure: false)

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']
)
get_hash = run_command('python', './src/cosmic/get_commit_hash.py', check: true).stdout().strip()


lib_source = [
'src/cosmic/src/hrdiag_remnant.f',
'src/cosmic/src/assign_remnant.f',
'src/cosmic/src/benchmarkevolv2.f',
'src/cosmic/src/int64.f',
'src/cosmic/src/corerd.f',
'src/cosmic/src/comenv.f',
'src/cosmic/src/dgcore.f',
Expand Down Expand Up @@ -79,26 +77,26 @@ else
ldflags = [] # No special flags for other systems
endif


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']
)


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'
subdir : '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'))

subdir('src/cosmic')
Loading

0 comments on commit 2159a11

Please sign in to comment.