From 053bf2d0eefd42fe1247189fb8470f08b27885f8 Mon Sep 17 00:00:00 2001 From: Rayne Liu <rl746@cornell.edu> Date: Thu, 13 Aug 2020 17:39:20 -0400 Subject: [PATCH] Finally found the bug with the pool but did not understand it - but PyCBC pool also worked with ptemcee --- code/RDGW150914_ptemcee.py | 27 ++++++++++++--------------- code/RDGW150914_ptemcee1.py | 7 +++++-- code/RDGW150914_ptemcee2.py | 6 +++++- code/RDGW150914_ptemcee3.py | 6 +++++- code/RDGW150914_ptemcee4.py | 6 +++++- code/condor_submit_RdownPtemcee.sub | 4 ++-- code/condor_submit_RdownPtemcee1.sub | 4 ++-- code/condor_submit_RdownPtemcee2.sub | 4 ++-- code/condor_submit_RdownPtemcee3.sub | 4 ++-- code/condor_submit_RdownPtemcee4.sub | 4 ++-- 10 files changed, 42 insertions(+), 30 deletions(-) diff --git a/code/RDGW150914_ptemcee.py b/code/RDGW150914_ptemcee.py index e27eae7..58cb04a 100755 --- a/code/RDGW150914_ptemcee.py +++ b/code/RDGW150914_ptemcee.py @@ -16,6 +16,8 @@ from matplotlib import rc plt.rcParams.update({'font.size': 16.5}) import ptemcee +from pycbc.pool import choose_pool +#from multiprocessing import Pool import math import h5py import inspect @@ -32,18 +34,19 @@ from scipy.optimize import minimize #tshift: time shift after the strain peak #vary_fund: whether you vary the fundamental frequency. Works in the model_dv function. -rootpath="/work/rayne.liu" #"/Users/RayneLiu" +rootpath="/Users/RayneLiu"# "/work/rayne.liu" nmax=1 tshift=19 vary_fund = True #sampler parameters npoints=101 -nwalkers = 32 +nwalkers = 42 ntemps=12 ndim = int(4*(nmax+1)) burnin = 10 #How many points do you burn before doing the corner plot. You need to watch the convergence of the chain plot a bit. #This is trivial but often forgotten: this cannot be more than npoints! Usually 1/5~1/4 npoints is what I observe. + numbins = 21 #corner plot parameter - how many bins you want datacolor = '#105670' #'#4fa3a7' pkcolor = '#f2c977' #'#ffb45f' @@ -160,8 +163,8 @@ def log_likelihood(theta): # The evidence is just a normalization factor def log_probability(theta): lp = log_prior(theta) - print('lp:') - print(lp) + #print('lp:') + #print(lp) if not np.isfinite(lp): return -np.inf return lp + log_likelihood(theta) @@ -170,6 +173,9 @@ def log_probability(theta): #Fit with ptemcee +#Set the number of cores of your processors +pool = choose_pool(4) +pool.size = 4 vary_param = float(vary_fund) pos = np.array([[random.uniform(-0.1,0.1), random.uniform(-0.1,0.1), 4.28313743e-01, random.uniform(2.5, 2.6) + (1-vary_param) * np.pi]]) for i in range (1,nmax+1): @@ -180,7 +186,8 @@ pos = pos.T.flatten() pos = list(pos) pos += 1e-5 * np.random.randn(ntemps, nwalkers, ndim) #print(pos) -sampler = ptemcee.Sampler(nwalkers, ndim, log_likelihood, log_prior, ntemps=ntemps) + +sampler = ptemcee.Sampler(nwalkers, ndim, log_likelihood, log_prior, ntemps=ntemps, pool=pool) sampler.run_mcmc(pos,npoints) @@ -291,13 +298,3 @@ plt.xlabel("t") plt.ylabel("h") figband.savefig(rootpath+'/git/rdstackingproject/plotsmc/vary'+str(vary_fund)+'nmax='+str(nmax)+'_tshift='+str(tshift)+'_'+str(npoints)+'pt_band.pdf', format = 'pdf') -""" - - - - - - - - -""" diff --git a/code/RDGW150914_ptemcee1.py b/code/RDGW150914_ptemcee1.py index bde6934..e491c3d 100755 --- a/code/RDGW150914_ptemcee1.py +++ b/code/RDGW150914_ptemcee1.py @@ -16,6 +16,7 @@ from matplotlib import rc plt.rcParams.update({'font.size': 16.5}) import ptemcee +from pycbc.pool import choose_pool import math import h5py import inspect @@ -170,6 +171,9 @@ def log_probability(theta): #Fit with ptemcee +#Set the number of cores of your processors +pool = choose_pool(4) +pool.size = 4 vary_param = float(vary_fund) pos = np.array([[random.uniform(-0.1,0.1), random.uniform(-0.1,0.1), 4.28313743e-01, random.uniform(2.5, 2.6) + (1-vary_param) * np.pi]]) for i in range (1,nmax+1): @@ -180,12 +184,11 @@ pos = pos.T.flatten() pos = list(pos) pos += 1e-5 * np.random.randn(ntemps, nwalkers, ndim) #print(pos) -sampler = ptemcee.Sampler(nwalkers, ndim, log_likelihood, log_prior, ntemps=ntemps) +sampler = ptemcee.Sampler(nwalkers, ndim, log_likelihood, log_prior, ntemps=ntemps, pool=pool) sampler.run_mcmc(pos,npoints) - #Define labels and start plotting paramlabels_a = [r'$\alpha_'+str(i)+'$' for i in range (nmax+1)] paramlabels_b = [r'$\beta_'+str(i)+'$' for i in range (nmax+1)] diff --git a/code/RDGW150914_ptemcee2.py b/code/RDGW150914_ptemcee2.py index 3d29a78..19f8eea 100755 --- a/code/RDGW150914_ptemcee2.py +++ b/code/RDGW150914_ptemcee2.py @@ -16,6 +16,7 @@ from matplotlib import rc plt.rcParams.update({'font.size': 16.5}) import ptemcee +from pycbc.pool import choose_pool import math import h5py import inspect @@ -170,6 +171,9 @@ def log_probability(theta): #Fit with ptemcee +#Set the number of cores of your processors +pool = choose_pool(4) +pool.size = 4 vary_param = float(vary_fund) pos = np.array([[random.uniform(-0.1,0.1), random.uniform(-0.1,0.1), 4.28313743e-01, random.uniform(2.5, 2.6) + (1-vary_param) * np.pi]]) for i in range (1,nmax+1): @@ -180,7 +184,7 @@ pos = pos.T.flatten() pos = list(pos) pos += 1e-5 * np.random.randn(ntemps, nwalkers, ndim) #print(pos) -sampler = ptemcee.Sampler(nwalkers, ndim, log_likelihood, log_prior, ntemps=ntemps) +sampler = ptemcee.Sampler(nwalkers, ndim, log_likelihood, log_prior, ntemps=ntemps, pool=pool) sampler.run_mcmc(pos,npoints) diff --git a/code/RDGW150914_ptemcee3.py b/code/RDGW150914_ptemcee3.py index 6e2f096..c49e4c2 100755 --- a/code/RDGW150914_ptemcee3.py +++ b/code/RDGW150914_ptemcee3.py @@ -16,6 +16,7 @@ from matplotlib import rc plt.rcParams.update({'font.size': 16.5}) import ptemcee +from pycbc.pool import choose_pool import math import h5py import inspect @@ -170,6 +171,9 @@ def log_probability(theta): #Fit with ptemcee +#Set the number of cores of your processors +pool = choose_pool(4) +pool.size = 4 vary_param = float(vary_fund) pos = np.array([[random.uniform(-0.1,0.1), random.uniform(-0.1,0.1), 4.28313743e-01, random.uniform(2.5, 2.6) + (1-vary_param) * np.pi]]) for i in range (1,nmax+1): @@ -180,7 +184,7 @@ pos = pos.T.flatten() pos = list(pos) pos += 1e-5 * np.random.randn(ntemps, nwalkers, ndim) #print(pos) -sampler = ptemcee.Sampler(nwalkers, ndim, log_likelihood, log_prior, ntemps=ntemps) +sampler = ptemcee.Sampler(nwalkers, ndim, log_likelihood, log_prior, ntemps=ntemps, pool=pool) sampler.run_mcmc(pos,npoints) diff --git a/code/RDGW150914_ptemcee4.py b/code/RDGW150914_ptemcee4.py index 759575a..af162ee 100755 --- a/code/RDGW150914_ptemcee4.py +++ b/code/RDGW150914_ptemcee4.py @@ -16,6 +16,7 @@ from matplotlib import rc plt.rcParams.update({'font.size': 16.5}) import ptemcee +from pycbc.pool import choose_pool import math import h5py import inspect @@ -170,6 +171,9 @@ def log_probability(theta): #Fit with ptemcee +#Set the number of cores of your processors +pool = choose_pool(4) +pool.size = 4 vary_param = float(vary_fund) pos = np.array([[random.uniform(-0.1,0.1), random.uniform(-0.1,0.1), 4.28313743e-01, random.uniform(2.5, 2.6) + (1-vary_param) * np.pi]]) for i in range (1,nmax+1): @@ -180,7 +184,7 @@ pos = pos.T.flatten() pos = list(pos) pos += 1e-5 * np.random.randn(ntemps, nwalkers, ndim) #print(pos) -sampler = ptemcee.Sampler(nwalkers, ndim, log_likelihood, log_prior, ntemps=ntemps) +sampler = ptemcee.Sampler(nwalkers, ndim, log_likelihood, log_prior, ntemps=ntemps, pool=pool) sampler.run_mcmc(pos,npoints) diff --git a/code/condor_submit_RdownPtemcee.sub b/code/condor_submit_RdownPtemcee.sub index ced2df3..478b6f8 100755 --- a/code/condor_submit_RdownPtemcee.sub +++ b/code/condor_submit_RdownPtemcee.sub @@ -12,8 +12,8 @@ initialdir = . notify_user = rl746@cornell.edu notification = Complete arguments = "-processid $(Process)" -request_memory = 16GB -request_cpus = 1 +request_memory = 8GB +request_cpus = 4 on_exit_remove = (ExitBySignal == False) || ((ExitBySignal == True) && (ExitSignal != 11)) accounting_group = aei.dev.test_dynesty queue 1 diff --git a/code/condor_submit_RdownPtemcee1.sub b/code/condor_submit_RdownPtemcee1.sub index 34bcd92..0358c84 100755 --- a/code/condor_submit_RdownPtemcee1.sub +++ b/code/condor_submit_RdownPtemcee1.sub @@ -12,8 +12,8 @@ initialdir = . notify_user = rl746@cornell.edu notification = Complete arguments = "-processid $(Process)" -request_memory = 16GB -request_cpus = 1 +request_memory = 8GB +request_cpus = 4 on_exit_remove = (ExitBySignal == False) || ((ExitBySignal == True) && (ExitSignal != 11)) accounting_group = aei.dev.test_dynesty queue 1 diff --git a/code/condor_submit_RdownPtemcee2.sub b/code/condor_submit_RdownPtemcee2.sub index 218ef23..f780e1f 100755 --- a/code/condor_submit_RdownPtemcee2.sub +++ b/code/condor_submit_RdownPtemcee2.sub @@ -12,8 +12,8 @@ initialdir = . notify_user = rl746@cornell.edu notification = Complete arguments = "-processid $(Process)" -request_memory = 16GB -request_cpus = 1 +request_memory = 8GB +request_cpus = 4 on_exit_remove = (ExitBySignal == False) || ((ExitBySignal == True) && (ExitSignal != 11)) accounting_group = aei.dev.test_dynesty queue 1 diff --git a/code/condor_submit_RdownPtemcee3.sub b/code/condor_submit_RdownPtemcee3.sub index de8eda0..f9e3d38 100755 --- a/code/condor_submit_RdownPtemcee3.sub +++ b/code/condor_submit_RdownPtemcee3.sub @@ -12,8 +12,8 @@ initialdir = . notify_user = rl746@cornell.edu notification = Complete arguments = "-processid $(Process)" -request_memory = 16GB -request_cpus = 1 +request_memory = 8GB +request_cpus = 4 on_exit_remove = (ExitBySignal == False) || ((ExitBySignal == True) && (ExitSignal != 11)) accounting_group = aei.dev.test_dynesty queue 1 diff --git a/code/condor_submit_RdownPtemcee4.sub b/code/condor_submit_RdownPtemcee4.sub index b337b63..2780f90 100755 --- a/code/condor_submit_RdownPtemcee4.sub +++ b/code/condor_submit_RdownPtemcee4.sub @@ -12,8 +12,8 @@ initialdir = . notify_user = rl746@cornell.edu notification = Complete arguments = "-processid $(Process)" -request_memory = 16GB -request_cpus = 1 +request_memory = 8GB +request_cpus = 4 on_exit_remove = (ExitBySignal == False) || ((ExitBySignal == True) && (ExitSignal != 11)) accounting_group = aei.dev.test_dynesty queue 1 -- GitLab