Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backwards integration #104

Open
wants to merge 51 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
3cc4b08
integrating backwards - crude
May 31, 2023
aecc74d
integrating backwards - crude
May 31, 2023
aaaa966
integrating backwards, needs tidying
May 31, 2023
01fcbb1
frequencies need modified
Jun 2, 2023
df48a55
now generating backwards waveform
Jun 4, 2023
714f004
integrate backwards with kwarg
Jun 4, 2023
8b52b33
tidied up
Jun 4, 2023
3ffe962
backwards integration - schwarzschild
Jun 4, 2023
6a087a9
modified ODEs for Schwarzschild - backwards
Jun 4, 2023
cb7453f
test scripts for backwards int
Jun 4, 2023
bbdf0da
tidied up
Jun 4, 2023
7eb304f
input as kwarg
Jun 5, 2023
27d2c17
decreased ODE error, better
Jun 5, 2023
c0c977b
AAK working
Jun 5, 2023
a9c3f41
tidied up example script
Jun 6, 2023
c5598e0
minor changes
Jun 6, 2023
484a0ee
commented code
Jun 6, 2023
8384b3c
working on kwargs
Jun 6, 2023
18857e8
low error works
Jun 6, 2023
a133791
changed max_init_len
Jun 6, 2023
c8551b3
tidied up
Jun 6, 2023
5f69c52
kwargs fine
Jun 6, 2023
bdc31d0
fixed time step
Jun 7, 2023
d8f0a0b
backwards int + fixed time step
Jun 7, 2023
560d6e8
example file - fixed time step
Jun 7, 2023
15c9451
example file - backwards int
Jun 7, 2023
d3ad72c
fixed kwargs for AAK
Jun 7, 2023
b276e0b
removed warning, max_init_len
Jun 7, 2023
93cec4d
more error catching
Jun 7, 2023
4c51fe3
error catching
Jun 7, 2023
567da52
ready for use
Jun 7, 2023
093642b
modified unittests
Jun 9, 2023
4b97336
extra error handling
Jun 9, 2023
0708dbe
tidied and commented
Jun 9, 2023
454cf75
fixed small #define bug
Jun 10, 2023
e8feb00
tidied up unittest
Jun 10, 2023
876d576
added details to README
Jun 10, 2023
6f105bf
added examples
Jun 10, 2023
078c9d6
added more tutorial examples
Jun 10, 2023
9603863
added more unittests
Jun 10, 2023
7d02287
fixed irritating bug
Jun 10, 2023
9acf671
fixed small bug
Jun 10, 2023
f8e1ab1
tidied up and commented
Jun 10, 2023
53734bc
max_init_len warning + tinkering
Jun 10, 2023
0c1b8c5
tidied up warning message
Jun 10, 2023
5cb9b4f
Removed spline interpolation
Jun 11, 2023
f9e7cd7
further experiments
Jun 11, 2023
6028c04
finished tutorial notebook
Jun 12, 2023
e72f06f
Finished up example notebook
Jun 12, 2023
cfa6d95
change unittests -- fixed bug
Jun 12, 2023
b0e44f6
no spline anymore
Jun 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"files.associations": {
"*.tex": "latex",
"iomanip": "cpp",
"iostream": "cpp"
}
}
Binary file added __pycache__/test_traj.cpython-39.pyc
Binary file not shown.
166 changes: 166 additions & 0 deletions backwards_integration_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
import sys
import os

import matplotlib.pyplot as plt
import numpy as np

from few.trajectory.inspiral import EMRIInspiral
from few.amplitude.romannet import RomanAmplitude
from few.amplitude.interp2dcubicspline import Interp2DAmplitude
from few.waveform import GenerateEMRIWaveform
from few.utils.utility import (get_overlap,
get_mismatch,
get_fundamental_frequencies,
get_separatrix,
get_mu_at_t,
get_p_at_t,
get_kerr_geo_constants_of_motion,
xI_to_Y,
Y_to_xI,
interpolate_trajectories_backwards_integration)

from few.utils.ylm import GetYlms
from few.utils.modeselector import ModeSelector
from few.summation.interpolatedmodesum import CubicSplineInterpolant
from few.waveform import SchwarzschildEccentricWaveformBase
from few.summation.interpolatedmodesum import InterpolatedModeSum
from few.summation.directmodesum import DirectModeSum
from few.utils.constants import *
from few.summation.aakwave import AAKSummation
from few.waveform import Pn5AAKWaveform, AAKWaveformBase

from scipy.interpolate import interp1d



use_gpu = False

# keyword arguments for inspiral
inspiral_kwargs = {
"DENSE_STEPPING": 0, # Set to 1 if we want a sparsely sampled trajectory
"max_init_len": int(1e7), # all of the trajectories will be well under len = 1000
"err" : 1e-10,
}


# initial parameters
M = 1e6
mu = 1e1
a = 0.85
p_f = 8.50 # Final semi-latus rectum
e_f = 0.15 # Final eccentricity
iota0_f = 1.0 # Final inclination
Y_f = np.cos(iota0_f)
T = 1
Phi_phi0 = 1.0
Phi_theta0 = 2.0
Phi_r0 = 3.0

dt = 10.0
waveform_choice = input("Do you want Kerr inspirals? [y/n]")
if waveform_choice == "y":
waveform_class = 'Pn5AAKWaveform'
trajectory_class = 'pn5'
print("5PN AAK trajectory and waveform")
else:
waveform_class = 'FastSchwarzschildEccentricFlux'
trajectory_class = "SchwarzEccFlux"
print("Eccentric Schwarzschild trajectory and waveform")

# Set up trajectory module for backwards integration
traj_backwards = EMRIInspiral(func = trajectory_class, integrate_backwards = True)

# Generate backwards integration
t_back, p_back, e_back, Y_back, Phi_phi_back, Phi_r_back, Phi_theta_back = traj_backwards(M, mu, a, p_f, e_f, Y_f,
Phi_phi0=Phi_phi0, Phi_theta0=Phi_theta0, Phi_r0=Phi_r0, dt = dt, T=T, **inspiral_kwargs)
# Set up trajectory module for forwards integration
traj_forwards = EMRIInspiral(func = trajectory_class, integrate_backwards = False)

# Start trajectory at final point of backwards integration
initial_p = p_back[-1]
initial_e = e_back[-1]
initial_Y = Y_back[-1]


# breakpoint()
# Generate forwards integration
t_forward, p_forward, e_forward, Y_forward, Phi_phi_forward, Phi_r_forward, Phi_theta_forward = traj_forwards(M, mu, a, initial_p, initial_e, initial_Y,
Phi_phi0=Phi_phi0, Phi_theta0=Phi_theta0, Phi_r0=Phi_r0, T=T, **inspiral_kwargs)

print("Finished trajectories")
p_back_interp = interp1d(max(t_back) - t_back,p_back, kind = 'cubic')
p_check_forward = p_back_interp(t_forward)

# ======================== WAVEFORM GENERATION =============================

# Set extrinsic parameters for waveform generation
qS = 0.2
phiS = 0.2
qK = 0.8
phiK = 0.8
dist = 1.0
mich = False

# Set up inspiral_kwargs - note use of "integrate_backwards"
inspiral_kwargs = {
"max_init_len": int(1e8),
"DENSE_STEPPING": 0,
"err": 1e-10,
"integrate_backwards": True
}

# keyword arguments for inspiral generator (RomanAmplitude)
amplitude_kwargs = {
"max_init_len": int(1e5), # all of the trajectories will be well under len = 1000
"use_gpu": use_gpu # GPU is available in this class
}

# keyword arguments for Ylm generator (GetYlms)
Ylm_kwargs = {
"assume_positive_m": False # if we assume positive m, it will generate negative m for all m>0
}

# keyword arguments for summation generator (InterpolatedModeSum)
sum_kwargs = {
"use_gpu": use_gpu, # GPU is availabel for this type of summation
"pad_output": False
}
# Generate waveform using backwards integration
wave_generator_backwards = GenerateEMRIWaveform(waveform_class, inspiral_kwargs = inspiral_kwargs, use_gpu=False)
waveform_back = wave_generator_backwards(M, mu, a, p_f, e_f, Y_f, dist, qS, phiS, qK, phiK,
Phi_phi0=Phi_phi0, Phi_theta0=Phi_theta0, Phi_r0=Phi_r0, dt=dt, T=T)
print("Finished backwards integration")

breakpoint()
# Extract plus polarised waveform
h_p_back_int = waveform_back.real

# Now change inspiral_kwargs so we integrate forwards
inspiral_kwargs['integrate_backwards'] = False

# Generate waveform using forwards integration
wave_generator_forwards = GenerateEMRIWaveform(waveform_class,inspiral_kwargs=inspiral_kwargs, sum_kwargs=sum_kwargs, use_gpu=False)
waveform_forward = wave_generator_forwards(M, mu, a, initial_p, initial_e, initial_Y, dist, qS, phiS, qK, phiK,
Phi_phi0=Phi_phi0, Phi_theta0=Phi_theta0, Phi_r0=Phi_r0, dt=dt, T=T)

print("Finished forwards integration")
# Extract plus polarised waveform
h_p_forward_int = waveform_forward.real

# Output non-noise_weighted mismatch
print("Mismatch between two waveforms is", get_mismatch(waveform_forward,waveform_back[::-1]))

# Extract relevant times [seconds]
n_t = len(h_p_forward_int)
t = np.arange(0,n_t*dt,dt)

# Plot the two waveforms against eachother
plt.plot(t/24/60/60,h_p_back_int[::-1], c = 'blue', alpha = 1, linestyle = 'dashed', label = 'integrated backwards')
plt.plot(t/24/60/60,h_p_forward_int, c = 'red', alpha = 0.5, label = 'integrated forwards')
plt.xlabel(r'Time $t$ [days]')
plt.ylabel(r'$h_{p}$')
plt.title(r'Comparison')
plt.legend()
plt.show()
plt.clf()

93 changes: 93 additions & 0 deletions check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import sys
import os

import matplotlib.pyplot as plt
import numpy as np

from few.trajectory.inspiral import EMRIInspiral
from few.amplitude.romannet import RomanAmplitude
from few.amplitude.interp2dcubicspline import Interp2DAmplitude
from few.waveform import FastSchwarzschildEccentricFlux, SlowSchwarzschildEccentricFlux, GenerateEMRIWaveform
from few.utils.utility import (get_overlap,
get_mismatch,
get_fundamental_frequencies,
get_separatrix,
get_mu_at_t,
get_p_at_t,
get_kerr_geo_constants_of_motion,
xI_to_Y,
Y_to_xI)

from few.utils.ylm import GetYlms
from few.utils.modeselector import ModeSelector
from few.summation.interpolatedmodesum import CubicSplineInterpolant
from few.waveform import SchwarzschildEccentricWaveformBase
from few.summation.interpolatedmodesum import InterpolatedModeSum
from few.summation.directmodesum import DirectModeSum
from few.utils.constants import *
from few.summation.aakwave import AAKSummation
from few.waveform import Pn5AAKWaveform, AAKWaveformBase

use_gpu = False

# keyword arguments for inspiral generator (RunSchwarzEccFluxInspiral)
inspiral_kwargs={
"DENSE_STEPPING": 0, # we want a sparsely sampled trajectory
"max_init_len": int(1e4), # all of the trajectories will be well under len = 1000
}

# keyword arguments for inspiral generator (RomanAmplitude)
amplitude_kwargs = {
"max_init_len": int(1e3), # all of the trajectories will be well under len = 1000
"use_gpu": use_gpu # GPU is available in this class
}

# keyword arguments for Ylm generator (GetYlms)
Ylm_kwargs = {
"assume_positive_m": False # if we assume positive m, it will generate negative m for all m>0
}

# keyword arguments for summation generator (InterpolatedModeSum)
sum_kwargs = {
"use_gpu": use_gpu, # GPU is availabel for this type of summation
"pad_output": False,
}

# THE FOLLOWING THREAD COMMANDS DO NOT WORK ON THE M1 CHIP, BUT CAN BE USED WITH OLDER MODELS
# EVENTUALLY WE WILL PROBABLY REMOVE OMP WHICH NOW PARALLELIZES WITHIN ONE WAVEFORM AND LEAVE IT TO
# THE USER TO PARALLELIZE FOR MANY WAVEFORMS ON THEIR OWN.

# set omp threads one of two ways
# num_threads = 4

# this is the general way to set it for all computations
# from few.utils.utility import omp_set_num_threads
# omp_set_num_threads(num_threads)

few = FastSchwarzschildEccentricFlux(
inspiral_kwargs=inspiral_kwargs,
amplitude_kwargs=amplitude_kwargs,
Ylm_kwargs=Ylm_kwargs,
sum_kwargs=sum_kwargs,
use_gpu=use_gpu,
# num_threads=num_threads, # 2nd way for specific classes
)

# parameters
M = 1e5
mu = 1e1
p0 = 20.24
e0 = 0.3
theta = np.pi/3 # polar viewing angle
phi = np.pi/4 # azimuthal viewing angle
dt = 10.0
T = 6.5

traj = EMRIInspiral(func="SchwarzEccFlux")
t, p, e, x, Phi_phi, Phi_theta, Phi_r = traj(M, mu, 0.0, p0, e0, 1.0, dt = dt, T=T, max_init_len = int(1e7))
# breakpoint()
traj_back = EMRIInspiral(func="SchwarzEccFlux", integrate_backwards = True)
p_f = p[-1]; e_f = e[-1]
print("backwards")
t,p_back,e_back,x, Phi_phi_back, Phi_theta, Phi_r_back = traj_back(M, mu, 0.0, p_f, e_f, 1.0, dt = dt, T = T, max_init_len = int(1e7))
breakpoint()
2 changes: 1 addition & 1 deletion docs/html/docs_main.html
Original file line number Diff line number Diff line change
Expand Up @@ -307,4 +307,4 @@ <h1>Package TODOs<a class="headerlink" href="#package-todos" title="Permalink to


</body>
</html>
</html>
2 changes: 1 addition & 1 deletion docs/source/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ In the main directory of the package run in the terminal:

::

python -m unittest discover
python -m unittest discover -v

Contributing
------------
Expand Down
Loading