Skip to content

Commit da42e90

Browse files
authored
Merge pull request #692 from LiekeVanSon/Update_Mchirp_notebook
Update mchirp notebook
2 parents 9bed21c + 5303e19 commit da42e90

File tree

7 files changed

+387
-417
lines changed

7 files changed

+387
-417
lines changed

utils/example_plots/methods_paper_plots/chirpmass_distribution/chirpmass_dist.ipynb

Lines changed: 0 additions & 319 deletions
This file was deleted.

utils/example_plots/methods_paper_plots/chirpmass_distribution/COMPAS_Output_Definitions.txt renamed to utils/example_plots/methods_paper_plots/fig_16_Chirpmass_distribution/COMPAS_Output_Definitions.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ bse_sysparms_rec += { # set t
1616
BINARY_PROPERTY::OPTIMISTIC_COMMON_ENVELOPE, # Optimistic CE flag
1717
BINARY_PROPERTY::IMMEDIATE_RLOF_POST_COMMON_ENVELOPE, # Flag to indicate if either star overflows its Roche lobe immediately following common envelope event.
1818
BINARY_PROPERTY::COMMON_ENVELOPE_EVENT_COUNT,
19+
BINARY_PROPERTY::SYSTEMIC_SPEED,
1920
}
2021

2122

utils/example_plots/methods_paper_plots/chirpmass_distribution/pythonSubmit.py renamed to utils/example_plots/methods_paper_plots/fig_16_Chirpmass_distribution/Fig16_pythonSubmit.py

Lines changed: 35 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
11
import numpy as np
22
import sys
33
import os
4-
import pickle
5-
import itertools
4+
from subprocess import call
65
import re
76
import ntpath
8-
import subprocess
9-
from subprocess import call
10-
11-
#### DISCLAIMER: This script uses the `pythonSubmit.py` format
12-
#### that has been replaced by the `runSubmit.py` and
13-
#### `compasConfigDefault.yaml` combo as of v02.25.10.
14-
#### The `pythonSubmit.py` format will eventually become deprecated.
157

168
# Check if we are using python 3
179
python_version = sys.version_info[0]
1810
print("python_version =", python_version)
1911

12+
2013
class pythonProgramOptions:
2114
"""
2215
A class to store and access COMPAS program options in python
@@ -33,55 +26,32 @@ class pythonProgramOptions:
3326
# docker container (src, obj, bin), and the COMPAS executable resides
3427
# in the bin directory (rather than the src directory)
3528
compas_executable_override = os.environ.get('COMPAS_EXECUTABLE_PATH')
36-
29+
3730
if (compas_executable_override is None):
38-
39-
# we should fix this one day - we should not assume that the COMPAS executable
40-
# is in the 'src' directory. The standard is to put the object files created
41-
# by the compile into the 'obj' directory, and the executable files created by
42-
# the link in the 'bin' directory.
43-
#
44-
# for now though, because this is how everybody expects it to be, we'll just check
45-
# that the path to the root directory (the parent directory of the directory in
46-
# which we expect the executable to reside - for now, 'src') is set to something.
47-
48-
compas_root_dir = os.environ.get('COMPAS_ROOT_DIR')
49-
assert compas_root_dir is not None, "Unable to locate the COMPAS executable: check that the environment variable COMPAS_ROOT_DIR is set correctly, and the COMPAS executable exists."
50-
51-
# construct path to executable
52-
#
53-
# ideally we wouldn't have the 'src' directory name (or any other directory name)
54-
# prepended to the executable name - if we just execute the executable name on its
55-
# own, as long as the user navigates to the directory in which the executable resides
56-
# they don't need to set the COMPAS_ROOT_DIR environment variable
57-
58-
compas_executable = os.path.join(compas_root_dir, 'src/COMPAS')
31+
git_directory = os.environ.get('COMPAS_ROOT_DIR')
32+
compas_executable = os.path.join(git_directory, 'src/COMPAS')
5933
else:
6034
compas_executable = compas_executable_override
6135

62-
# check that a file with the correct name exists where we expect it to
63-
assert os.path.isfile(compas_executable), "Unable to locate the COMPAS executable: check that the environment variable COMPAS_ROOT_DIR is set correctly, and the COMPAS executable exists."
64-
65-
6636
enable_warnings = False # option to enable/disable warning messages
6737

68-
number_of_systems = int(1e2) # number of systems per batch
38+
number_of_systems = 10 #number of systems per batch
6939

7040
populationPrinting = False
7141

7242
randomSeedFileName = 'randomSeed.txt'
7343
if os.path.isfile(randomSeedFileName):
7444
random_seed = int(np.loadtxt(randomSeedFileName))
7545
else:
76-
random_seed = 0 # If you want a random seed, use: np.random.randint(2,2**63-1)
46+
random_seed = 0 # If you want a random seed, use: np.random.randint(2,2**63-1)
7747

7848
# environment variable COMPAS_LOGS_OUTPUT_DIR_PATH is used primarily for docker runs
7949
# if COMPAS_LOGS_OUTPUT_DIR_PATH is set (!= None) it is used as the value for the
8050
# --output-path option
8151
# if COMPAS_LOGS_OUTPUT_DIR_PATH is not set (== None) the current working directory
8252
# is used as the value for the --output-path option
8353
compas_logs_output_override = os.environ.get('COMPAS_LOGS_OUTPUT_DIR_PATH')
84-
54+
8555
if (compas_logs_output_override is None):
8656
output = os.getcwd()
8757
output_container = None # names the directory to be created and in which log files are created. Default in COMPAS is "COMPAS_Output"
@@ -95,7 +65,7 @@ class pythonProgramOptions:
9565
# if COMPAS_INPUT_DIR_PATH is not set (== None) the current working directory
9666
# is prepended to input filenames
9767
compas_input_path_override = os.environ.get('COMPAS_INPUT_DIR_PATH')
98-
68+
9969
#-- option to make a grid of hyperparameter values at which to produce populations.
10070
#-- If this is set to true, it will divide the number_of_binaries parameter equally
10171
#-- amoungst the grid points (as closely as possible). See the hyperparameterGrid method below
@@ -105,9 +75,6 @@ class pythonProgramOptions:
10575
hyperparameterList = False
10676
shareSeeds = False
10777

108-
notes_hdrs = None # no annotations header strings (no annotations)
109-
notes = None # no annotations
110-
11178
mode = 'BSE' # evolving single stars (SSE) or binaries (BSE)?
11279

11380
grid_filename = None # grid file name (e.g. 'mygrid.txt')
@@ -123,11 +90,11 @@ class pythonProgramOptions:
12390
else:
12491
grid_filename = compas_input_path_override + '/' + grid_filename.strip("'\"")
12592

126-
logfile_definitions = "COMPAS_Output_Definitions.txt" # logfile record definitions file name (e.g. 'logdefs.txt')
93+
logfile_definitions = None # logfile record definitions file name (e.g. 'logdefs.txt')
12794

12895
if logfile_definitions != None:
12996
# if the grid filename supplied is already fully-qualified, leave it as is
130-
head, tail = ntpath.split(logfile_definitions) # split into pathname and base filename
97+
head, tail = ntpath.split(grid_filename) # split into pathname and base filename
13198

13299
if head == '' or head == '.': # no path (or CWD) - add path as required
133100
logfile_definitions = tail or ntpath.basename(head)
@@ -161,6 +128,8 @@ class pythonProgramOptions:
161128

162129
chemically_homogeneous_evolution = 'PESSIMISTIC' # chemically homogeneous evolution. Options are 'NONE', 'OPTIMISTIC' and 'PESSIMISTIC'
163130

131+
store_input_files = True # store input files in output container?
132+
164133
switch_log = False
165134

166135
common_envelope_alpha = 1.0
@@ -172,24 +141,22 @@ class pythonProgramOptions:
172141
common_envelope_maximum_donor_mass_revised_energy_formalism = 2.0
173142
common_envelope_recombination_energy_density = 1.5E13
174143
common_envelope_alpha_thermal = 1.0 # lambda = alpha_th*lambda_b + (1-alpha_th)*lambda_g
175-
common_envelope_lambda_multiplier = 1.0 # Multiply common envelope lambda by some constant
176-
common_envelope_allow_main_sequence_survive = True # Allow main sequence stars to survive CE. Was previously False by default
144+
wolf_rayet_multiplier = 1.0
145+
cool_wind_mass_loss_multiplier = 1.0
177146
common_envelope_mass_accretion_prescription = 'ZERO'
178147
common_envelope_mass_accretion_min = 0.04 # For 'MACLEOD+2014' [Msol]
179148
common_envelope_mass_accretion_max = 0.10 # For 'MACLEOD+2014' [Msol]
180149
envelope_state_prescription = 'LEGACY'
181-
common_envelope_allow_radiative_envelope_survive = False
182-
common_envelope_allow_immediate_RLOF_post_CE_survive = False
183150

184151
mass_loss_prescription = 'VINK'
185-
luminous_blue_variable_prescription = 'HURLEY_ADD'
152+
luminous_blue_variable_prescription = 'BELCZYNSKI'#'HURLEY_ADD'
186153
luminous_blue_variable_multiplier = 1.5
187154
overall_wind_mass_loss_multiplier = 1.0
188155
wolf_rayet_multiplier = 1.0
189156
cool_wind_mass_loss_multiplier = 1.0
190157
check_photon_tiring_limit = False
191158

192-
circularise_binary_during_mass_transfer = False
159+
circularise_binary_during_mass_transfer = True
193160
angular_momentum_conservation_during_circularisation = False
194161
mass_transfer_angular_momentum_loss_prescription = 'ISOTROPIC'
195162
mass_transfer_accretion_efficiency_prescription = 'THERMAL'
@@ -209,7 +176,7 @@ class pythonProgramOptions:
209176
timestep_multiplier = 1.0 # Optional multiplier relative to default time step duration
210177

211178
initial_mass_function = 'KROUPA'
212-
initial_mass_min = 10.0 # Use 1.0 for LRNe, 5.0 for DCOs [Msol]
179+
initial_mass_min = 5.0 # Use 1.0 for LRNe, 5.0 for DCOs [Msol]
213180
initial_mass_max = 150.0 # Stellar tracks extrapolated above 50 Msol (Hurley+2000) [Msol]
214181

215182
initial_mass_power = 0.0
@@ -256,7 +223,7 @@ class pythonProgramOptions:
256223

257224
neutrino_mass_loss_BH_formation = "FIXED_MASS" # "FIXED_FRACTION"
258225
neutrino_mass_loss_BH_formation_value = 0.1 # Either fraction or mass (Msol) to lose
259-
226+
260227
remnant_mass_prescription = 'FRYER2012' #
261228
fryer_supernova_engine = 'DELAYED'
262229
black_hole_kicks = 'FALLBACK'
@@ -299,12 +266,10 @@ class pythonProgramOptions:
299266
PPI_lower_limit = 35.0 # Minimum core mass for PPI [Msol]
300267
PPI_upper_limit = 60.0 # Maximum core mass for PPI [Msol]
301268

302-
pulsational_pair_instability_prescription = 'FARMER'
269+
pulsational_pair_instability_prescription = 'MARCHANT'
303270

304271
maximum_neutron_star_mass = 2.5 # [Msol]
305272

306-
add_options_to_sysparms = 'GRID' # should all option values be added to system parameters files? options are 'ALWAYS', 'GRID', and 'NEVER'
307-
308273
log_level = 0
309274
log_classes = []
310275

@@ -347,7 +312,6 @@ class pythonProgramOptions:
347312
debug_to_file = False
348313
errors_to_file = False
349314

350-
351315
def booleanChoices(self):
352316
booleanChoices = [
353317
self.enable_warnings,
@@ -363,13 +327,12 @@ def booleanChoices(self):
363327
self.pulsation_pair_instability,
364328
self.quiet,
365329
self.common_envelope_allow_main_sequence_survive,
366-
self.common_envelope_allow_radiative_envelope_survive,
367-
self.common_envelope_allow_immediate_RLOF_post_CE_survive,
368330
self.evolvePulsars,
369331
self.debug_to_file,
370332
self.errors_to_file,
371333
self.allow_rlof_at_birth,
372334
self.allow_touching_at_birth,
335+
self.store_input_files,
373336
self.switch_log,
374337
self.check_photon_tiring_limit
375338
]
@@ -391,13 +354,12 @@ def booleanCommands(self):
391354
'--pulsational-pair-instability',
392355
'--quiet',
393356
'--common-envelope-allow-main-sequence-survive',
394-
'--common-envelope-allow-radiative-envelope-survive',
395-
'--common-envelope-allow-immediate-rlof-post-ce-survive',
396357
'--evolve-pulsars',
397358
'--debug-to-file',
398359
'--errors-to-file',
399360
'--allow-rlof-at-birth',
400361
'--allow-touching-at-birth',
362+
'--store-input-files',
401363
'--switch-log',
402364
'--check-photon-tiring-limit'
403365
]
@@ -588,8 +550,6 @@ def numericalCommands(self):
588550

589551
def stringChoices(self):
590552
stringChoices = [
591-
self.notes_hdrs,
592-
self.notes,
593553
self.mode,
594554
self.case_BB_stability_prescription,
595555
self.chemically_homogeneous_evolution,
@@ -633,16 +593,13 @@ def stringChoices(self):
633593
self.logfile_supernovae,
634594
self.logfile_switch_log,
635595
self.logfile_system_parameters,
636-
self.neutrino_mass_loss_BH_formation,
637-
self.add_options_to_sysparms
596+
self.neutrino_mass_loss_BH_formation
638597
]
639598

640599
return stringChoices
641600

642601
def stringCommands(self):
643602
stringCommands = [
644-
'--notes-hdrs',
645-
'--notes',
646603
'--mode',
647604
'--case-BB-stability-prescription',
648605
'--chemically-homogeneous-evolution',
@@ -686,8 +643,7 @@ def stringCommands(self):
686643
'--logfile-supernovae',
687644
'--logfile-switch-log',
688645
'--logfile-system-parameters',
689-
'--neutrino-mass-loss-BH-formation',
690-
'--add-options-to-sysparms'
646+
'--neutrino-mass-loss-BH-formation'
691647
]
692648

693649
return stringCommands
@@ -716,12 +672,12 @@ def generateCommandLineOptionsDict(self):
716672
and run directly as a terminal command, or passed to the stroopwafel interface
717673
where some of them may be overwritten. Options not to be included in the command
718674
line should be set to pythons None (except booleans, which should be set to False)
719-
675+
720676
Parameters
721677
-----------
722678
self : pythonProgramOptions
723679
Contains program options
724-
680+
725681
Returns
726682
--------
727683
commands : str or list of strs
@@ -730,17 +686,17 @@ def generateCommandLineOptionsDict(self):
730686
booleanCommands = self.booleanCommands()
731687
nBoolean = len(booleanChoices)
732688
assert len(booleanCommands) == nBoolean
733-
689+
734690
numericalChoices = self.numericalChoices()
735691
numericalCommands = self.numericalCommands()
736692
nNumerical = len(numericalChoices)
737693
assert len(numericalCommands) == nNumerical
738-
694+
739695
stringChoices = self.stringChoices()
740696
stringCommands = self.stringCommands()
741697
nString = len(stringChoices)
742698
assert len(stringCommands) == nString
743-
699+
744700
listChoices = self.listChoices()
745701
listCommands = self.listCommands()
746702
nList = len(listChoices)
@@ -750,25 +706,25 @@ def generateCommandLineOptionsDict(self):
750706
### Collect all options into a dictionary mapping option name to option value
751707

752708
command = {'compas_executable' : self.compas_executable}
753-
709+
754710
for i in range(nBoolean):
755711
if booleanChoices[i] == True:
756712
command.update({booleanCommands[i] : ''})
757713
elif booleanChoices[i] == False:
758714
command.update({booleanCommands[i] : 'False'})
759-
715+
760716
for i in range(nNumerical):
761717
if not numericalChoices[i] == None:
762718
command.update({numericalCommands[i] : str(numericalChoices[i])})
763-
719+
764720
for i in range(nString):
765721
if not stringChoices[i] == None:
766722
command.update({stringCommands[i] : cleanStringParameter(stringChoices[i])})
767-
723+
768724
for i in range(nList):
769725
if listChoices[i]:
770726
command.update({listCommands[i] : ' '.join(map(str,listChoices[i]))})
771-
727+
772728
return command
773729

774730

@@ -780,7 +736,7 @@ def combineCommandLineOptionsDictIntoShellCommand(commandOptions):
780736
"""
781737

782738
shellCommand = commandOptions['compas_executable']
783-
del commandOptions['compas_executable']
739+
del commandOptions['compas_executable']
784740
for key, val in commandOptions.items():
785741
shellCommand += ' ' + key + ' ' + val
786742

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# How to recreate/edit the BBH chirp mass distribution from the COMPAS methods paper
2+
3+
This folder contains everything you need to reproduce the BBH chirpmass distribution from the COMPAS methods paper (_arXiv_: https://arxiv.org/abs/2109.10352; Team COMPAS et al. 2021).
4+
5+
6+
The data used for this figure is publicly available at: https://zenodo.org/record/5655483
7+
8+
This data set contains the output of 10,000,000 binaries evolved using COMPAS 02.21.00, using adaptive importance sampling (STROOPWAFEL, Broekgaarden et al. 2019), sampling from a metallicity uniform in $\log(Z) \in [10^{-4},0.03]$. More details can be found in `Run_Details.txt`.
9+
10+
### Data reporduction
11+
The data can be reproduced by running version `02.21.00` of COMPAS,
12+
13+
1. Run `stroopwafel_interface.py`, that reads in the `Fig16_pythonSubmit.py.py` (both contained in this folder).
14+
2. Calculate the rates by running ```FastCosmicIntegration.py``` from COMPAS's post-processing tools, with the following flags altered from their default values:
15+
16+
17+
```:::bash
18+
python FastCosmicIntegration.py --mu0 0.035 --muz -0.23 --sigma0 0.39 --sigmaz 0.0 --alpha 0.0 --weight mixture_weight --zstep 0.01 --sens O3 --m1min 10. --aSF 0.01 --bSF 2.77 --cSF 2.9 --dSF 4.7
19+
```
20+

0 commit comments

Comments
 (0)