-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathglobal_parameters.py
123 lines (101 loc) · 5.38 KB
/
global_parameters.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env python
# -*- coding: utf-8 -*-
####################################################################################
# This module defines neccesary definitions of global parameters and initial conditions.
# The quantities in this module are kept fixed throughout the computation and are not varied in the MCMC run.
# Contents:
# 1. Libraries
# 2. Physical constants in cgs units
# 3. Parameter values for fiducial model
# 4. Geometrical parameters and initial conditions of the system.
# 5. Parameters needed for ODE solver
# 6. Parameters for the MCMC run !!! SET THE MCMC FILE PATH TO SAVE THE CHAIN
####################################################################################
###### Libraries
import numpy as np
import math
import subprocess
class color: # useful for printing out text in colour.
PURPLE = '\033[1;35;48m'
CYAN = '\033[1;36;48m'
BOLD = '\033[1;37;48m'
BLUE = '\033[1;34;48m'
GREEN = '\033[1;32;48m'
YELLOW = '\033[1;33;48m'
RED = '\033[1;31;48m'
BLACK = '\033[1;30;48m'
UNDERLINE = '\033[4;37;48m'
END = '\033[1;37;0m'
def check_GPU():
"""
Checks GPU functionality.
"""
try:
subprocess.check_output('nvidia-smi')
print(color.GREEN + 'All is good, GPU detected.' + color.END)
except Exception:
print(color.RED + 'No GPU detected. The code cannot run at full functionality.' + color.END)
######
###### Physical constants in cgs units.
Ms = 1.9892*10**(33) # Solar mass, cgs
G = 6.67428*10**(-8) # Newton's G, cgs
c = 29979245800 # Speed of light, cgs
Pi = np.pi # Constant π
H0 = 72/(3*10**19) # Hubble parameters in sec
######
###### Parameter values for fiducial model.
# Add/remove parameters as needed, but ensure all other relevant parts of the code are adjusted.
μ0 = 10 # orbiting mass in units of solar mass [M_sun]
M0 = (10**6) # central BH mass in units of solar mass [M_sun]
spin0 = 0.1 # central BH spin [S/M^2]
Xi0 = 0.8 # modified gravity parameter modifying the GW lum. distance.
#Xi = Xi0 # comment this out in case the modified gravity parameter Xi is not fixed in the MCMC and use Xi0 above as the respective fiducial value.
z = 0.01 # redshift of the source. Affects the luminosity distances.
# p0: Vector with fiducial model parameters. The same set of parameters which will be varied under the MCMC.
p0 = [M0, μ0, spin0, Xi0]
###### Geometrical parameters and initial conditions of the system.
λ = Pi/6 # This is an angle which we fix throughout (fiducial and MCMC).
# Initial values for phase Φ, angles γ and α, eccentricity e at the LSO.
# Here they are set to be the same when solving the ODEs for both fiducial model and MCMC run.
# If any of these parameters below are chosen to be varied under the MCMC, this line below
# and other parts of the code need to be modified.
Phi_LSO, gamma_LSO, alpha_LSO, e_LSO = 0, 0, 0, 0.3
# For more, see Barack&Cutler2004.
#######
###### Parameters needed for ODE solver
# nu_LSO: The initial condition of the orbital frequency (ν) at the LSO. It depends on the central mass and eccentricity.
nu_LSO = (c**3/(2*Pi*G*M0*Ms))*((1 - e_LSO**2)/(6 + 2*e_LSO))**(3/2)
# x0: Vector with initial conditions for the ODE system. Here is defined to be equal to the LSO.
x0 = [Phi_LSO, nu_LSO, e_LSO, gamma_LSO, alpha_LSO ]
# For more, see: Barack&Cutler2004.
t_max = 3.127*10**7 # initial integration time in seconds (3.127*10**7 sec = 1 year).
t_min = 0 # final integration time.
points = int(np.floor(0.1*np.abs(t_max-t_min))) # Grid points for integration. Defines resolution of waveform
t_span = np.linspace(t_max, t_min, points) # time limits for integration
solver0 = 'RK23'
# Choose between:
#'BDF'(backward differentiation formula),
#'LSODA' (ODEPACK), DOP853(Runge-Kutta 7th order),
#'RK23'(Runge-Kutta 3rd order),
#'RK45' (Runge-Kutta 5th order)
rtol = 10**-10 # relative tolerance for ODE solver
atol = 10**-10 # absolute tolerance for ODE solver
n_max = 20 # maximum number of overtones to include in the waveform.
######
###### Parameters for the MCMC run
filepath = '.../MCMC.txt' # THIS IS THE PATH TO THE TEXT FILE WHERE TO SAVE THE MCMC RESULTS.
parameter_names = ['Mass M', 'Mass μ', 'spin', 'Ξ'] # Parameters varied under MCMC
Ndim = 4 # Number of parameters to fit. Change this accordingly.
Nwalker = 2*Ndim # Number of walkers for the MCMC run. By default, twice the Ndim.
Nsteps = 2000 # Number of MCMC steps. Change this accordingly.
vectorize = False
#
# Set up the backend's filename to save the result of the MCMC in a txt file.
filename = "MCMC.txt"
#
# This is the vector defining the initial parameters for the walkers of the MCMC run.
# The value of each parameter is its fiducial value plus some small Gaussian noise.
# The dimension of p_init_MC must be equal to the number of walkers Nwalker.
# p_init_MC needs be modified for different set of parameters.
p_init_MC = np.random.randn(Nwalker, Ndim)*[1, 1*(10**-5), 2*(10**-6),1*(10**-5)] + [M0, μ0, spin0,Xi0]
######