Example #1
0
    def test_pool(self):
        pool = InterruptiblePool(2)
        params = [1., 1.1]
        res = pool.map(runsim, params)

        self.assertAlmostEqual(res, [0.9950041652780258, 1.095870355119381],
                               delta=1e-15)
Example #2
0
 def test_nopool(self):
     pool = InterruptiblePool(2)
     params = [1., 1.1]
     res = [runsim(params[0]), runsim(params[1])]
     self.assertAlmostEqual(res[0], 0.9950041652780258, delta=1e-15)
     self.assertAlmostEqual(res[1], 1.095870355119381, delta=1e-15)
     pool.close()
Example #3
0
        return 10.  # At least one particle got ejected, returning large MEGNO.


import rebound
import numpy as np
print simulation((7, 0.1))

Ngrid = 500
par_a = np.linspace(7., 10., Ngrid)
par_e = np.linspace(0., 0.5, Ngrid)
parameters = []
for e in par_e:
    for a in par_a:
        parameters.append((a, e))
from rebound.interruptible_pool import InterruptiblePool
pool = InterruptiblePool()
results = pool.map(simulation, parameters)

results2d = np.array(results).reshape(Ngrid, Ngrid)
#%matplotlib inline
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(7, 5))
ax = plt.subplot(111)
extent = [min(par_a), max(par_a), min(par_e), max(par_e)]
ax.set_xlim(extent[0], extent[1])
ax.set_xlabel("semi-major axis $a$")
ax.set_ylim(extent[2], extent[3])
ax.set_ylabel("inclination $i$")
im = ax.imshow(results2d,
               interpolation="none",
               vmin=1.9,
Example #4
0
colors = {
    'whfast-nocor': "#00AA00",
    'whfast': "#FF0000",
    'mercury': "#6E6E6E",
    'swifter-whm': "#444444",
    'swifter-helio': "#AABBBB",
    'swifter-tu4': "#FFAAAA",
    'ias15': "g",
    'janus': "#0000FF",
}
trials = 4

parameters = [(inte, i * trials + j, j) for i, inte in enumerate(integrators)
              for j in xrange(trials)]
if len(sys.argv) != 2:
    pool = InterruptiblePool()
    print("Running %d simulations" % (len(parameters)))
    res = np.array(pool.map(simulation,
                            parameters)).reshape(len(integrators), trials, 4,
                                                 Ngrid)
    np.save("res.npy", res)
else:
    print("Loading %d simulations" % (len(parameters)))
    print(sys.argv[1])
    res = np.load(sys.argv[1])

f, axarr = plt.subplots(1, 1, figsize=(13, 4))
#extent=[res[:,:,0,:].min()/orbit, res[:,:,0,:].max()/orbit, 1e-16, 1e-9]
extent = [
    res[:, :, 0, :].min() / orbit, res[:, :, 0, :].max() / orbit, 1e-24, 1e-7
]
Example #5
0
    'whfast-nocor': "#FF0000",
    'whfast':       "#00AA00",
    'mercury':      "#6E6E6E",
    'wh':           "b",
    'swifter-whm':  "#444444",
    'swifter-helio':"#AABBBB",
    'swifter-tu4':  "#FFAAAA",
    'ias15':        "g",
}
trials = 4
    
parameters = [(inte,i*trials+j,j) for i,inte in enumerate(integrators) for j in xrange(trials)]


if len(sys.argv)!=2:
    pool = InterruptiblePool()
    print "Running %d simulations" % (len(parameters))
    res = np.array(pool.map(simulation,parameters)).reshape(len(integrators),trials,2,Ngrid)
    np.save("res.npy",res)
else:
    print "Loading %d simulations" % (len(parameters))
    print sys.argv[1]
    res = np.load(sys.argv[1])

import matplotlib; matplotlib.use("pdf")
import matplotlib.pyplot as plt
from matplotlib import ticker
from matplotlib.colors import LogNorm


f,axarr = plt.subplots(1,1,figsize=(13,4))
Example #6
0
tmax = orbit*1e3
integrators = ["wh","swifter-whm","swifter-tu4","swifter-helio","mercury","whfast-nocor","whfast"]
colors = {
    'whfast-nocor': "#FF0000",
    'whfast':       "#00AA00",
    'mercury':      "#6E6E6E",
    'wh':           "b",
    'swifter-whm':  "#444444",
    'swifter-helio':"#AABBBB",
    'swifter-tu4':  "#FFAAAA",
    'ias15':        "g",
    }
parameters = [(inte,dt,i*len(dts)+j) for i,inte in enumerate(integrators) for j, dt in enumerate(dts)]
   
if len(sys.argv)!=2:
    pool = InterruptiblePool(8)
    print "Running %d simulations" % (len(parameters))
    res = np.array(pool.map(simulation,parameters)).reshape(len(integrators),len(dts),2)
    np.save("res.npy",res)
else:
    print "Loading %d simulations" % (len(parameters))
    print sys.argv[1]
    res = np.load(sys.argv[1])

print res.shape

import matplotlib; matplotlib.use("pdf")
import matplotlib.pyplot as plt
from matplotlib import ticker
from matplotlib.colors import LogNorm
from matplotlib.font_manager import FontProperties
colors = {
    'whfast-nocor': "#FF0000",
    'whfast': "#00AA00",
    'mercury': "#6E6E6E",
    'wh': "b",
    'swifter-whm': "#444444",
    'swifter-helio': "#AABBBB",
    'swifter-tu4': "#FFAAAA",
    'ias15': "g",
}
parameters = [(inte, dt, i * len(dts) + j)
              for i, inte in enumerate(integrators)
              for j, dt in enumerate(dts)]

if len(sys.argv) != 2:
    pool = InterruptiblePool(8)
    print "Running %d simulations" % (len(parameters))
    res = np.array(pool.map(simulation,
                            parameters)).reshape(len(integrators), len(dts), 2)
    np.save("res.npy", res)
else:
    print "Loading %d simulations" % (len(parameters))
    print sys.argv[1]
    res = np.load(sys.argv[1])

print res.shape

import matplotlib
matplotlib.use("pdf")
import matplotlib.pyplot as plt
from matplotlib import ticker
Example #8
0
                          interpolation='nearest',
                          cmap="RdYlGn",
                          extent=extent)

    if first:
        cb1 = plt.colorbar(im1, ax=axarr[0])
        cb1.solids.set_rasterized(True)
        cb1.set_label("MEGNO $\\langle Y \\rangle$")

        cb2 = plt.colorbar(im2, ax=axarr[1])
        cb2.solids.set_rasterized(True)
        cb2.set_label("Lyapunov timescale [years]")
    plt.draw()


pool = InterruptiblePool(
)  # Number of threads default to the number of CPUs on the system


def runSim(p):
    print("Running %d simulations." % len(p))
    res = np.nan_to_num(np.array(pool.map(simulation, p)))
    for i, r in enumerate(res):
        resd[p[i]] = r


# Setup grid and run many simulations in parallel
a = np.array([7., 10.])  # range of saturn semi-major axis in AU
e = np.array([0., 0.5])  # range of saturn eccentricity

# Setup plots
f, axarr = plt.subplots(2, figsize=(10, 8))
Example #9
0
    except rebound.Escape:
        return 10. # At least one particle got ejected, returning large MEGNO.

import rebound
import numpy as np
print simulation((7,0.1))

Ngrid = 500
par_a = np.linspace(7.,10.,Ngrid)
par_e = np.linspace(0.,0.5,Ngrid)
parameters = []
for e in par_e:
    for a in par_a:
        parameters.append((a,e))
from rebound.interruptible_pool import InterruptiblePool
pool = InterruptiblePool()
results = pool.map(simulation,parameters)


results2d = np.array(results).reshape(Ngrid,Ngrid)
#%matplotlib inline
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(7,5))
ax = plt.subplot(111)
extent = [min(par_a),max(par_a),min(par_e),max(par_e)]
ax.set_xlim(extent[0],extent[1])
ax.set_xlabel("semi-major axis $a$")
ax.set_ylim(extent[2],extent[3])
ax.set_ylabel("inclination $i$")
im = ax.imshow(results2d, interpolation="none", vmin=1.9, vmax=4, cmap="jet", origin="lower", aspect='auto', extent=extent)
cb = plt.colorbar(im, ax=ax)
 def test_pool(self):
     pool = InterruptiblePool(2)
     params = [1.,1.1]
     res = pool.map(runsim,params)
     self.assertAlmostEqual(res,[0.9950041652780258,1.095870355119381],delta=1e-15)
Example #11
0
    return pgraph


def varpi_graph(vp1, vp2, times):
    plt.figure()
    plt.scatter(times, vp1, color='purple', s=10)
    plt.scatter(times, vp2, color='blue', s=10)
    plt.xlabel('Time (years)', fontsize=12)
    plt.ylabel('Pericentre Distance (m)', fontsize=12)
    scatter(times, vp1, color='purple', label='smaller planet varpi')
    scatter(times, vp2, color='blue', label='larger planet varpi')
    vpgraph = plt.savefig('sin,pericentre_distance_taupo=e={0}.pdf'.format(
        taues[1]))
    return vpgraph


args = np.logspace(4, 8, 20)
pool = InterruptiblePool(10)
pool.map(calc, args)

filenames = []
f = open('onlytaue,filenames.txt', 'w')
for count in range(len(args)):
    filenames.append('onlytaue={0}.txt'.format(args[count]))
    print(filenames[count])
    f.write(str(filenames[count]))
    f.write('\t')
    f.write(str(args[count]))
    f.write('\n')
f.close()
Example #12
0
    return [rebound.get_megno(),1./(rebound.get_lyapunov()*2.*np.pi)] # returns MEGNO and Lypunov timescale in years


### Setup grid and run many simulations in parallel
N = 100                      # Grid size, increase this number to see more detail
a = np.linspace(7.,10.,N)   # range of saturn semi-major axis in AU
e = np.linspace(0.,0.5,N)   # range of saturn eccentricity
parameters = []
for _e in e:
    for _a in a:
        parameters.append([_a,_e])


# Run simulations in parallel
pool = InterruptiblePool()    # Number of threads default to the number of CPUs on the system
print("Running %d simulations on %d threads..." % (len(parameters), pool._processes))
res = np.nan_to_num(np.array(pool.map(simulation,parameters))) 
megno = np.clip(res[:,0].reshape((N,N)),1.8,4.)             # clip arrays to plot saturated 
lyaptimescale = np.clip(np.absolute(res[:,1].reshape((N,N))),1e1,1e5)

### Create plot and save as pdf 
import matplotlib; matplotlib.use("pdf")
import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm

# Setup plots
f, axarr = plt.subplots(2,figsize=(10,10))
extent = [a.min(), a.max(), e.min(), e.max()]
for ax in axarr:
    ax.set_xlim(extent[0],extent[1])
    scatter(times[840:1000], phi6[840:1000], color = 'purple', label = '7:6')
    pgraph = plt.savefig('sin,resonance_angles_taupo=e={0}.pdf'.format(taues[1]))
    return pgraph

def varpi_graph(vp1, vp2, times):
    plt.figure()
    plt.scatter(times, vp1, color = 'purple', s=10)
    plt.scatter(times, vp2, color = 'blue', s=10)
    plt.xlabel('Time (years)', fontsize = 12)
    plt.ylabel('Pericentre Distance (m)', fontsize = 12)
    scatter(times,vp1, color = 'purple', label = 'smaller planet varpi')
    scatter(times, vp2, color = 'blue', label = 'larger planet varpi')
    vpgraph = plt.savefig('sin,pericentre_distance_taupo=e={0}.pdf'.format(taues[1]))
    return vpgraph

args = np.logspace(4,8,20)
pool = InterruptiblePool(10)
pool.map(calc,args)

filenames=[]
f=open('onlytaue,filenames.txt','w')
for count in range(len(args)):
   filenames.append('onlytaue={0}.txt'.format(args[count]))
   print(filenames[count])
   f.write(str(filenames[count]))
   f.write('\t')
   f.write(str(args[count]))
   f.write('\n')
f.close()