Auryn simulator

Simulator for spiking neural networks with synaptic plasticity

User Tools

Site Tools


examples:sim_poisson

This is an old revision of the document!


The important bits

Since Auryn simulations are executable c programs there is quite some overhead (see below). However since the header logic is usually the same let's focus first on the interesting bits, where the interesting stuff happens.

PoissonGroup * poisson = new PoissonGroup(size,kappa);
poisson->seed(seed);
 
sprintf(strbuf, "%s/%s.%d.ras", dir.c_str(), file_prefix.c_str(), world.rank() );
SpikeMonitor * smon_e = new SpikeMonitor( poisson, strbuf, size);
 
sprintf(strbuf, "%s/%s.%d.prate", dir.c_str(), file_prefix.c_str(), world.rank() );
PopulationRateMonitor * pmon_e = new PopulationRateMonitor( poisson, strbuf, 1.0 );
 
RateChecker * chk = new RateChecker( poisson , -1 , 20.*kappa , 10);
if (!sys->run(simtime,false)) 
	errcode = 1;

Running this script should usually in a very brief output like this one

bash-4.1$ ./sim_poisson --seed 1231231
seed set to 1231231.
[=========================] 100%      t=10.0 s  f=21.3 Hz  
( 0) Freeing ...

In addition to this the script will create a ras and a prate output file (poisson.0.ras, poisson.0.prate) as well as a log file poisson.0.log.

The full script

#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <string>
 
#include <boost/program_options.hpp>
#include <boost/mpi/environment.hpp>
#include <boost/mpi/communicator.hpp>
#include <boost/mpi.hpp>
 
#include "auryn_global.h"
#include "auryn_definitions.h"
#include "System.h"
#include "Logger.h"
#include "PoissonGroup.h"
#include "SpikeMonitor.h"
#include "PopulationRateMonitor.h"
#include "RateChecker.h"
 
using namespace std;
 
namespace po = boost::program_options;
namespace mpi = boost::mpi;
 
int main(int ac, char* av[]) 
{
 
	string dir = "./";
	string file_prefix = "poisson";
 
	char strbuf [255];
	string msg;
 
	NeuronID size = 1000;
	NeuronID seed = 1;
	double kappa = 5.;
	double simtime = 10.;
 
	int errcode = 0;
 
    try {
 
        po::options_description desc("Allowed options");
        desc.add_options()
            ("help", "produce help message")
            ("simtime", po::value<double>(), "simulation time")
            ("kappa", po::value<double>(), "poisson group rate")
            ("size", po::value<int>(), "poisson group size")
            ("seed", po::value<int>(), "random seed")
        ;
 
        po::variables_map vm;        
        po::store(po::parse_command_line(ac, av, desc), vm);
        po::notify(vm);    
 
        if (vm.count("help")) {
            cout << desc << "\n";
            return 1;
        }
 
 
        if (vm.count("kappa")) {
            cout << "kappa set to " 
                 << vm["kappa"].as<double>() << ".\n";
			kappa = vm["kappa"].as<double>();
        } 
 
        if (vm.count("simtime")) {
            cout << "simtime set to " 
                 << vm["simtime"].as<double>() << ".\n";
			simtime = vm["simtime"].as<double>();
        } 
 
        if (vm.count("size")) {
            cout << "size set to " 
                 << vm["size"].as<int>() << ".\n";
			size = vm["size"].as<int>();
        } 
 
        if (vm.count("seed")) {
            cout << "seed set to " 
                 << vm["seed"].as<int>() << ".\n";
			seed = vm["seed"].as<int>();
        } 
    }
    catch(exception& e) {
        cerr << "error: " << e.what() << "\n";
        return 1;
    }
    catch(...) {
        cerr << "Exception of unknown type!\n";
    }
 
	// BEGIN Global stuff
	mpi::environment env(ac, av);
	mpi::communicator world;
	communicator = &world;
 
	sprintf(strbuf, "%s/%s.%d.log", dir.c_str(), file_prefix.c_str(), world.rank());
	string logfile = strbuf;
	logger = new Logger(logfile,world.rank(),PROGRESS,EVERYTHING);
 
	sys = new System(&world);
	// END Global stuff
 
	PoissonGroup * poisson = new PoissonGroup(size,kappa);
	poisson->seed(seed);
 
	sprintf(strbuf, "%s/%s.%d.ras", dir.c_str(), file_prefix.c_str(), world.rank() );
	SpikeMonitor * smon_e = new SpikeMonitor( poisson, strbuf, size);
 
	sprintf(strbuf, "%s/%s.%d.prate", dir.c_str(), file_prefix.c_str(), world.rank() );
	PopulationRateMonitor * pmon_e = new PopulationRateMonitor( poisson, strbuf, 1.0 );
 
	RateChecker * chk = new RateChecker( poisson , -1 , 20.*kappa , 10);
	if (!sys->run(simtime,false)) 
			errcode = 1;
 
	logger->msg("Freeing ...",PROGRESS,true);
	delete sys;
 
	if (errcode)
		env.abort(errcode);
	return errcode;
}
examples/sim_poisson.1386600634.txt.gz · Last modified: 2013/12/09 14:50 by zenke