Test usage of the experimental ADFSP solver

PyURDME includes the ADFSP (Adaptive Diffusive Finite State Projection) solver. This solver integrates the Reaction-Diffusion Master Equations using the DFSP algorithm found in [Drawert et al., J.Chem.Phys, 2010] using an adaptive timesteping schemed based on the estimating the operator splitting error using the method from [Hellander et al., J.Comp.Phys, 2013].


In [1]:
%pylab inline
from pyurdme.adfsp_solver import ADFSPSolver
from examples.cylinder_demo.cylinder_demo3D import cylinderDemo3D
import pyurdme
import time
import scipy.fftpack
import numpy


Populating the interactive namespace from numpy and matplotlib

In [3]:
model = cylinderDemo3D()
sol = ADFSPSolver(model)
print "Attempting to compile"
sol.compile()
print "Beginning simulation"
t1 = time.time()
result = sol.run()
print "Simulation complete in {0}s".format(time.time()-t1)


Attempting to compile
Beginning simulation
Simulation complete in 4.20588898659s

In [4]:
print "Plotting solution"
# Plot of the time-average spatial concentration.
x_vals = model.mesh.coordinates()[:, 0]
A_vals = numpy.mean(result.get_species("A", concentration=True), axis=0)
B_vals = numpy.mean(result.get_species("B", concentration=True), axis=0)
plt.plot(x_vals,A_vals,'.r',x_vals,B_vals,'.b')
plt.legend(['A', 'B'])


Plotting solution
Out[4]:
<matplotlib.legend.Legend at 0x110936650>

In [5]:
sol = ADFSPSolver(model, report_level=0)
print "Attempting to compile"
sol.compile()
N = 10
run_times = []
print "Beginning simulation:"
for n in range(N):
    sys.stdout.write(str(n))
    sys.stdout.flush()
    t1 = time.time()
    result = sol.run()
    elapsed_time = time.time()-t1
    run_times.append(elapsed_time)
print "Simulation of {0} trajectories: avg={1} std={2}".format(N, numpy.mean(run_times), numpy.std(run_times))


Attempting to compile
Beginning simulation:
0123456789Simulation of 10 trajectories: avg=3.17652721405 std=0.457474561977

In [6]:
from pyurdme.nsmsolver import NSMSolver
nsm = NSMSolver(model, report_level=0)
print "NSM: Attempting to compile"
nsm.compile()
N = 10
nsm_times = []
print "NSM: Beginning simulation:",
for n in range(N):
    sys.stdout.write(str(n))
    sys.stdout.flush()
    t1 = time.time()
    result = nsm.run()
    elapsed_time = time.time()-t1
    nsm_times.append(elapsed_time)
print ""
print "NSM: Simulation of {0} trajectories: avg={1} std={2}".format(N, numpy.mean(nsm_times), numpy.std(nsm_times))


NSM: Attempting to compile
NSM: Beginning simulation:0123456789 
NSM: Simulation of 10 trajectories: avg=3.61504948139 std=0.214400820178

In [ ]:


In [ ]: