Skip to content

Commit 1ff3a2a

Browse files
Missing #include<atomic>
Added python part of SAR experiment.
1 parent 88c189e commit 1ff3a2a

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

models/SAR.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# run a single instance of a SAR ensemble run
2+
from ecolab_model import spatial_ecolab as ecolab
3+
4+
from random import random, seed as randomSeed
5+
6+
from ecolab import array_urand, myid, device
7+
8+
import os
9+
import sys
10+
from math import sqrt
11+
12+
# we want initialisation to be identical across all processes
13+
randomSeed(1)
14+
15+
# we want the array operations to have a different seed across processes
16+
array_urand.seed(10+myid())
17+
18+
19+
nsp=int(sys.argv[1]) # initial number of species
20+
A=int(sys.argv[2]) # area
21+
mut_max=float(sys.argv[3]) # mutation rate
22+
migration=float(sys.argv[4]) # initial migration rate
23+
24+
25+
ecolab.repro_min(-0.1)
26+
ecolab.repro_max(0.1)
27+
ecolab.odiag_min(-1e-5)
28+
ecolab.odiag_max(1e-5)
29+
ecolab.mut_max(mut_max)
30+
ecolab.sp_sep(0.1)
31+
32+
def randomList(num, min, max):
33+
return [random()*(max-min)+min for i in range(num)]
34+
35+
ecolab.species(range(nsp))
36+
37+
numX=int(sqrt(A))
38+
numY=A//numX
39+
ecolab.setGrid(numX,numY)
40+
ecolab.partitionObjects()
41+
42+
# initialises allocators and space on GPU, so that density arrays can be set
43+
#ecolab.makeConsistent()
44+
45+
for i in range(numX):
46+
for j in range(numY):
47+
ecolab.cell(i,j).density(nsp*[100])
48+
49+
ecolab.repro_rate(randomList(nsp, ecolab.repro_min(), ecolab.repro_max()))
50+
ecolab.interaction.diag(randomList(nsp, -1e-3, -1e-3))
51+
ecolab.random_interaction(3,0)
52+
53+
ecolab.interaction.val(randomList(len(ecolab.interaction.val), ecolab.odiag_min(), ecolab.odiag_max()))
54+
55+
ecolab.mutation(nsp*[mut_max])
56+
ecolab.migration(nsp*[migration])
57+
58+
from plot import plot
59+
from GUI import gui, statusBar, windows
60+
61+
def stepImpl():
62+
ecolab.generate(100)
63+
ecolab.mutate()
64+
ecolab.migrate()
65+
ecolab.condense()
66+
ecolab.gather()
67+
68+
def av(x):
69+
return sum(x)/len(x) if len(x)>0 else 0
70+
71+
def step():
72+
stepImpl()
73+
# area, mutation, migration, no. species, connectivity
74+
75+
for i in range(100):
76+
step()
77+
78+
print(numX*numY, av(ecolab.mutation()), av(ecolab.migration()), len(ecolab.species), sum([x*x for x in ecolab.interaction.val()])/len(ecolab.species)**2)
79+
80+
81+

models/starComplexity.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "ecolab_epilogue.h"
99

1010
#include <algorithm>
11+
#include <atomic>
1112
#include <assert.h>
1213
#include <time.h>
1314

0 commit comments

Comments
 (0)