Through several years of experience in complex systems education, we have come to realize that using a simple general-purpose computer programming language itself as a complex systems modeling platform is our current best solution to address most, if not all, of the educational challenges discussed above. By definition, general-purpose computer programming languages are universal and can offer unlimited opportunity of modeling with all the details clearly spelled out in front of the user’s eyes.
Identifying a programming language that would be easily accessible and useful in a wide variety of disciplines had been difficult even a decade ago.a Fortunately, several easy-to-use programming languages have recently emerged and become very popular in various scientific and industrial communities, including Python and R. For our educational needs, we chose Python, a programming language now widely used in industries as well as in academia, so that students can gain practical skills for both complex systems simulation and computer programming simultaneously.
Using the Python language itself as a modeling and simulation platform, we have developed “PyCX”, an online repository of simple, crude, easy-to-understand sample codes for various complex systems simulation.b The target audiences of PyCX are researchers and students who are interested in developing their own complex systems simulation software using a general-purpose programming language but do not have much experience in computer programming. We carefully designed the sample codes so that our audience can understand, modify, create and visualize dynamic complex systems simulations relatively easily.
The core philosophy of PyCX is therefore placed on the simplicity, readability, generalizability and pedagogical values of simulation codes. This is often achieved even at the cost of computational speed, efficiency or maintainability. For example: (1) every PyCX sample code is written as a single.py file, which is a plain text file, without being split into multiple separate files; (2) all the dynamic simulations follow the same scheme consisting of three parts (initialization, visualization and updating); (3) we do not use the object-oriented programming paradigm because it is sometimes difficult for non-computer scientists to grasp; and (4) we do use global variables frequently to make the code more intuitive and readable. These choices were intentionally made based on our experience in teaching complex systems modeling and simulation to non-computer scientists and their feedback.
A simple example of PyCX sample codes (“abm-randomwalk.py”, an agent-based simulation of particles moving in independent random walk in a two-dimensional open space) is shown below. For a dynamic simulation like this one, the user needs to define three functions (init for initialization, draw for visualization, and step for updating) and then call pycxsimulator.GUI().start() to run the simulation.
import matplotlib
matplotlib.use(’TkAgg’)
import pylab as PL
import random as RD
import scipy as SP
RD.seed()
populationSize = 100
noiseLevel = 1
def init():
global time, agents
time = 0
agents = []
for i in xrange(populationSize):
newAgent = [RD.gauss(0, 1), RD.gauss(0, 1)]
agents.append(newAgent)
def draw():
PL.cla()
x = [ag[0] for ag in agents]
y = [ag[1] for ag in agents]
PL.plot(x, y, ’bo’)
PL.axis(’scaled’)
PL.axis([-100, 100, -100, 100])
PL.title(’t = ’ + str(time))
def step():
global time, agents
time += 1
for ag in agents:
ag[0] += RD.gauss(0, noiseLevel)
ag[1] += RD.gauss(0, noiseLevel)
import pycxsimulator
pycxsimulator.GUI().start(func=[init,draw,step])
There are a few limitations in using Python for complex systems education. The first limitation is that the software installation and maintenance is a little more difficult than other more sophisticated software environment.c We believe, though, that the long-term educational benefit from learning a general-purpose programming language will outweigh the short-term learning difficulty for the majority of students.
The second limitation is that it is relatively difficult to build an interactive GUI (Graphical User Interface) in Python. To alleviate this problem, we provide a simple universal GUI and a coding template for dynamic simulations. The user can define just three functions (for initialization, visualization and updating) in the “realtime-simulation-template.py” file to implement a dynamic simulation, and then the “pycxsimulator.py” module will automatically generate a minimalistic GUI with three buttons (“Run/Pause”, “Step Once” and “Reset”; Figure 1). These two files must be placed within the same folder.