In [1]:
%reset
%load_ext autoreload
import numpy as np
from subprocess import Popen
from os import makedirs,getcwd
from os.path import exists
import datetime
from shutil import copy
from glob import glob
import pyximport
pyximport.install()
import simulation as sm


Once deleted, variables cannot be recovered. Proceed (y/[n])? y

Check Parameter


In [9]:
%memit sm.runsimulation(N = 10000, dim = 700, p = 1., mu = 1./1000000.)


peak memory: 88.36 MiB, increment: 14.77 MiB

In [10]:
%timeit sm.runsimulation(N = 10000, dim = 700, p = 1., mu = 1./1000000.)


1 loops, best of 3: 7.9 s per loop

In [6]:
N = 10000
dist     = np.zeros((N,),dtype=float)
maxdist  = 0.
ensemble = 100

for ii in range(ensemble):
    sim    = sm.runsimulation(N = 10000, dim = 700, p = 1., mu = 1./1000000.)
    simmax = np.sqrt(sim.max())
    dist = dist + sim
    if simmax > maxdist:
        maxdist = simmax

dist *= 1./ensemble
D = np.polyfit(range(N-1000,N), dist[-1000::], 1)

In [16]:
from matplotlib import pyplot as plt
%matplotlib inline

print "Maximum Distance"
print maxdist

fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_ylabel(r'$E(x^2)$')
ax.set_xlabel('time step')
ax.plot(range(N),dist)
x = np.arange(N-1000,N,1)
y = D[0]*x + D[1]
ax.plot(x,y,'r-')


Maximum Distance
294.416371827

Submit Job


In [18]:
%autoreload 2

now = datetime.datetime.now()

N_ensembles    = 1000
N_runs         = 10000
dim            = 500
probs          = np.arange(0.05,1.05,0.05)
mus            = [1./100000., 1./10.]
path           = "/users/stud/koher/arbeit/" + now.strftime("%Y_%m_%d") + "/"

if not exists(path):
    makedirs(path)
files = [getcwd()+"/simulation.pyx",
         getcwd()+"/job",
         getcwd()+"/Simulation.ipynb"]

for afile in files:
    copy(afile, path)

for mu in mus:
    for prob in  probs:
        name = "prob="+str(prob) + "_mu=" + str(mu)
        Popen('qsub -o %s -v ENSEMBLES="%5i",RUNS="%5i",PROB="%1.2e",MU="%1.2e",SIZE="%5i",DIR="%s" -N %s job' %(path, N_ensembles, N_runs, prob, mu, dim, path, name), shell=True)

Auswertung


In [7]:
%matplotlib inline
N_ensembles    = 1000
N_runs         = 10000
dim            = 500
probs          = np.arange(0.05,1.05,0.05)
mus            = [1./100000., 1./10.]
path           = "/users/stud/koher/arbeit/" + now.strftime("%Y_%m_%d") + "/"

fig = plt.figure(figsize=(12,7))
ax = fig.add_subplot(121)
ax.set_ylabel(r'$E(x^2)$')
ax.set_xlabel(r'$t$')
ax.set_title('Mean squared displacement')
mu = mus[0]
for prob in probs:
    fname = path + "p"+str(prob) + "_mu" + str(mu) + '.npz'
    results = np.load(fname)
    dist = np.square(results['dist'])
    ax.plot(range(N_runs),dist)
    D = np.polyfit(range(N_runs-1000,N_runs), dist[-1000::], 1)
    x = np.arange(N_runs-1000,N_runs,1)
    y = D[0]*x + D[1]
    ax.plot(x,y,'r-')

D_all = np.zeros((5,20))
ax = fig.add_subplot(122)
ax.set_ylabel(r'Diffusivity D')
ax.set_xlabel(r'Link probability p')
ax.set_title('Diffusivity as a function of the link probability')
for ii in range(len(mus)):
    for jj in range(len(probs)):
        fname = path + "p"+str(probs[jj]) + "_mu" + str(mus[ii]) + '.npz'
        results = np.load(fname)
        dist = np.square(results['dist'])
        D_all[ii,jj] = np.polyfit(range(N_runs-1000,N_runs), dist[-1000::], 1)[0]
    ax.plot(range(len(probs)),D_all[ii,:])


Out[7]:
u'/users/stud/koher/arbeit/simulation'