Draft: First try at improving beam pattern calculation
@colm.talbot @soichiro.morisaki
I took the @soichiro.morisaki 's script and implemented the LAL beam pattern functions in place for antenna_response
. I get about a 6-10x speedup right now, though the implementation is not ideal yet since I calculate the pattern twice every time, so we should get a 12-20x speedup. (Interestingly, the speedup becomes larger if I loop over more trials???)
There is still an issue with this, though. The beam patterns are not perfectly identical for some reason, the difference is on the order of 1e-4. I don't know if this is big enough to make an impact on PE. I'll put a testing script below that can be used with the MR.
import numpy as np
import time
import bilby
ifos = bilby.gw.detector.InterferometerList(["L1"])
ifo = ifos[0]
gpstime = 1305303144
trial = 1000
ts_bilby, ts_lal = [], []
for i in range(trial):
ra, dec, psi = 2. * np.pi * np.random.uniform(), np.pi * np.random.uniform() - np.pi / 2., np.pi * np.random.uniform()
# measure bilby's run time
s = time.time()
fplus_old, fcross_old = ifo.antenna_response_old(ra, dec, gpstime, psi, "plus"), ifo.antenna_response_old(ra, dec, gpstime, psi, "cross")
e = time.time()
ts_bilby.append(e - s)
# measure lal's run time
s = time.time()
fplus, fcross = ifo.antenna_response(ra, dec, gpstime, psi, "plus"), ifo.antenna_response(ra, dec, gpstime, psi, "cross")
e = time.time()
ts_lal.append(e - s)
print(fplus-fplus_old)
print(fcross-fcross_old)
print("Bilby's method takes {} seconds.".format(np.mean(ts_bilby)))
print("LAL's method takes {} seconds.".format(np.mean(ts_lal)))
print(np.mean(ts_bilby)/np.mean(ts_lal)) #
Edited by Moritz Huebner