Previous Next Table of Contents

15. Simulations

Broadly speaking, a GENESIS ``simulation'' consists of the following components:

Sometimes, GENESIS users refer to a ``simulation'' as a specific step-through of a given simulation setup (i.e., stepping through a simulation, as defined above, over time) -- a ``run'' of a simulation.

15.1 Running a Simulation

Many GENESIS routines help you construct simulations (see, for example, Elements , Messages , Clocks , and so forth). The table below lists routines that specifically deal with preparing the simulation for time-oriented runs:

Routine Description
disable Disables an element and its children from participating in a
simulation.
enable Enables previously disabled elements to participate in a
simulation.
reset Resets simulation to initial conditions, including calling
RESET actions for individual elements in the simulation.
check Checks various aspects of simulation for specification errors.
step Advances the simulation by one or more steps.
stop Completes current simulation step, stopping simulation.
abort Cleanly interrupts simulation in progress.
showstat Reports statistics about current simulation (time, step,
stepsize, or memory use; or element resource use).
getstat Returns time, step, or memory use as a function value.
setmethod Sets integration method for elements to use in simulation.

The step routine might be considered the central GENESIS routine -- it runs the simulation, which is in a large part the whole point of GENESIS. In relation to the step routine, everything else you do in a GENESIS simulation script is a preparation for running the simulation.

A typical sequence of events in running a simulation is as follows:

  1. Set up the simulation environment (elements, messages, clocks, etc.) Often, you will use the readcell to construct one or more cells from specifications contained in cell parameter files.
  2. Run the reset routine to establish the initial state for the run:
             genesis > reset
        
    
  3. Run the check routine to check for obvious specification errors:
             genesis > check
        
    
    If there are any errors, return to step 1 to revise the environment as appropriate based on the check output.
  4. Run the step routine with a small step number (e.g., step 10) to test whether the simulation will run reasonably:
             genesis > step 10
    
    If the simulation fails or shows odd results, figure out where the problem is and return to step 1. Often, this will involve some experimentation with the step size used for the global simulation clock, as described in Simulation Clocks.
  5. Run the reset routine to prepare for the full run:
             genesis > reset
    
  6. Having determined that your simulation clocks are using an appropriate step size, run the step routine for a longer period of time. If you are not using graphics or interactive input, you may wish to place your simulation job in the background. For example:
             genesis > step -time 10.0 -background
        
    
    (The GENESIS prompt returns immediately but the simulation will have started in the background, as you can confirm using the showjobs routine.)

When performing long simulation runs in the background, you can use a disk_out element to save simulation results to disk at regular intervals, and the save command to save the state of the model at the end of the run.

You may wish to practice these steps using the simple GENESIS programming example scripts in the Scripts/tutorials directory before you try to build and run your own model.

15.2 Simulation Clocks

Each element in a simulation is associated with an interval timer or ``clock''. This clock is used to determine how frequently the action associated with the element (i.e., the INIT or PROCESS listed in the simulation schedule) will be executed during the simulation process. This is particularly useful when you want components of a simulation to run at significantly different time scales.

By convention, clock number 0 is the global simulation clock or the basic simulation time step. All elements start out using clock 0 by default.

The simulator also contains an array of 100 independent clocks (this is the number of available clocks; a typical simulation only uses a few of these clocks). Each clock is identified by a number from 1 to 100 corresponding to its position in the clock array. Clocks other than clock 0 must have settings larger than that of clock 0; these settings should be integer multiples of the clock 0 setting for maximal timing precision.

The setting of a specific clock is not some ``current time'', but is the time increment used for stepping its associated elements through the simulation. The units used for time must be consistent with those used for other related variables and parameters of the simulation. For example, if membrane resistances and capacitances are expressed in kilohms and microfarads, then times should be expressed in milliseconds. To make it easier to keep track of units, many (but not all) GENESIS simulations use SI (MKS) units, and express time in seconds.

For example, suppose clock 0 has the setting 1.0 (its default setting), and you assign clock 1 the value 5. If you then have a graphical element use clock 1 for its simulation time, the graph element would perform its simulation action (e.g., receiving a message and plotting a value) only once every 5 steps taken by the other elements. This can greatly speed up a simulation, as the time increment used for the display of information can usually be much larger than that which is small enough for an accurate stepwise numerical solution of the equations governing the model.

The following GENESIS routines are used for working with simulation clocks:

Routine Description
showclocks Displays currently defined clocks and their assigned values.
useclock Specifies which clock an element should use during simulation.
setclock Sets time interval (step size) associated with specified clock.
getclock Returns value of specified simulation clock.

Choosing a Simulation Time Step

At each step of a simulation, each participating element typically performs one or more computations. Some elements perform a stepwise numerical integration in order to solve the state equations of the element they represent. When setting up a simulation, you will need to choose a global simulation clock step size which is small enough to give accurate results, yet is large enough to give a reasonable simulation speed.

You can empirically determine the time step used with an integration method by decreasing the time step until the differences in simulation results are within some criterion. As a starting point, you should pick a step which would yield a smooth curve if you were to make a ``connect-the-dots'' type of plot of the most rapidly varying variable. The size of the time step needed also depends on the integration method which is used. The documentation for setmethod describes the several different ways these integrals can be calculated.

Typically, you need around 10 microseconds for a neural simulation with explicit methods (like the default Exponential Euler method) and 50 to 100 microseconds with the implicit methods (Backward Euler and Crank-Nicholson). (For the implicit methods the limiting factor is often the speed of the channel kinetics.) Implicit methods are recommended when there are many small compartments in a cell model, as these result in numerically ``stiff'' equations.

There is a complication when using the implicit methods. These are inherently not object oriented, and involve the construction of an ``hsolve'' element which takes over the computations for a specified cell. (See the documentation for hsolve.)

15.3 GENESIS Jobs

Certain compiled C functions available in GENESIS are designed to be run as background jobs (e.g., the function XEventLoop, which oversees XODUS screen events). You can execute and monitor these background functions using the following job routines:

Routine Description
showjobs Lists all of the active GENESIS jobs and their priorities.
addjob Adds a job to the GENESIS background job table.
deletejob Removes a job from the GENESIS job table.
setpriority Changes priority of a GENESIS background simulation job.


Previous Next Table of Contents