Cypress  1.0
C++ Spiking Neural Network Simulation Framework
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
cypress::PyNN Class Reference

#include <pynn.hpp>

Inheritance diagram for cypress::PyNN:
Inheritance graph
[legend]
Collaboration diagram for cypress::PyNN:
Collaboration graph
[legend]

Classes

class  PyNNSimulatorNotFound
 

Public Member Functions

 PyNN (const std::string &simulator, const Json &setup=Json())
 
 ~PyNN () override
 
Real timestep ()
 
std::unordered_set< const NeuronType * > supported_neuron_types () const override
 
std::string name () const override
 
const std::string & simulator () const
 
const std::string & normalised_simulator () const
 
const std::vector< std::string > & imports () const
 
std::string nmpi_platform () const
 
Json setup () const
 
void run (NetworkBase &network, Real duration=0.0) const
 

Static Public Member Functions

static std::vector< std::string > simulators ()
 
static std::string get_import (const std::vector< std::string > &imports, const std::string &simulator)
 
static int get_pynn_version ()
 
static int get_neo_version ()
 
static py::dict json_to_dict (Json json)
 
static std::string get_neuron_class (const NeuronType &neuron_type)
 
static void init_logger ()
 
static py::object create_source_population (const PopulationBase &pop, py::module &pynn)
 
static py::object create_homogeneous_pop (const PopulationBase &pop, py::module &pynn, bool &init_available)
 
static void set_inhomogeneous_parameters (const PopulationBase &pop, py::object &pypop, bool init_available=false)
 
static void set_homogeneous_rec (const PopulationBase &pop, py::object &pypop)
 
static void set_inhomogenous_rec (const PopulationBase &pop, py::object &pypop, py::module &pynn)
 
static py::object get_pop_view (const py::module &pynn, const py::object &py_pop, const PopulationBase &c_pop, const size_t &start, const size_t &end)
 
static py::object get_connector7 (const ConnectionDescriptor &conn, const py::module &pynn)
 
static py::object get_connector (const std::string &connector_name, const py::module &pynn, const Real &additional_parameter, const bool allow_self_connections)
 
static py::object group_connect (const std::vector< PopulationBase > &populations, const std::vector< py::object > &pypopulations, const ConnectionDescriptor &conn, const py::module &pynn, const bool nest_flag, const Real timestep=0.0)
 
static py::object group_connect (const std::vector< PopulationBase > &populations, const std::vector< py::object > &pypopulations, const ConnectionDescriptor &conn, const py::module &pynn, const Real nest_flag)=delete
 
static py::object group_connect7 (const std::vector< PopulationBase > &populations, const std::vector< py::object > &pypopulations, const ConnectionDescriptor &conn, const py::module &pynn)
 
static std::tuple< py::object, py::object > list_connect (const std::vector< py::object > &pypopulations, const ConnectionDescriptor conn, const py::module &pynn, const bool current_based, const Real timestep=0.0)
 
static std::tuple< py::object, py::object > list_connect (const std::vector< py::object > &pypopulations, const ConnectionDescriptor conn, const py::module &pynn, const Real current_based)=delete
 
static std::tuple< py::object, py::object > list_connect7 (const std::vector< py::object > &pypopulations, const ConnectionDescriptor conn, const py::module &pynn)
 
template<typename T >
static Matrix< T > matrix_from_numpy (const py::object &object, bool transposed=false)
 
static void fetch_data_nest (const std::vector< PopulationBase > &populations, const std::vector< py::object > &pypopulations)
 
static void fetch_data_spinnaker (const std::vector< PopulationBase > &populations, const std::vector< py::object > &pypopulations)
 
static void fetch_data_neo (const std::vector< PopulationBase > &populations, const std::vector< py::object > &pypopulations)
 
static void spikey_run (NetworkBase &source, Real duration, py::module &pynn, py::dict dict)
 
static py::object spikey_create_source_population (const PopulationBase &pop, py::module &pynn)
 
static py::object spikey_create_homogeneous_pop (const PopulationBase &pop, py::module &pynn)
 
static void spikey_set_homogeneous_rec (const PopulationBase &pop, py::object &pypop, py::module &pynn)
 
static void spikey_set_inhomogeneous_rec (const PopulationBase &pop, py::object &pypop, py::module pynn)
 
static void spikey_set_inhomogeneous_parameters (const PopulationBase &pop, py::object &pypop)
 
static void spikey_get_spikes (PopulationBase pop, py::object &pypop)
 
static void spikey_get_voltage (NeuronBase neuron, py::module &pynn)
 

Protected Member Functions

void do_run (NetworkBase &network, Real duration) const override
 

Protected Attributes

std::string m_simulator
 
std::string m_normalised_simulator
 
std::vector< std::string > m_imports
 
bool m_keep_log
 
Json m_setup
 

Detailed Description

The Backend class is an abstract base class which provides the facilities for network execution.

Constructor & Destructor Documentation

cypress::PyNN::PyNN ( const std::string &  simulator,
const Json setup = Json() 
)

Constructor of the PyNN backend. Throws an exception if the given PyNN backend does not exist.

Parameters
simulatoris the name of the simulator backend to be used by PyNN. Use the static backends method to list available backends.
setupcontains additional setup information that should be passed to the backend.
cypress::PyNN::~PyNN ( )
override

Destructor of the PyNN class.

Member Function Documentation

static py::object cypress::PyNN::create_homogeneous_pop ( const PopulationBase pop,
py::module &  pynn,
bool &  init_available 
)
static

Creates a PyNN population with homogeneous parameters, inhomogeneous parameters can be set with set_inhomogeneous_parameters afterwards.

Parameters
popThe cypress population
pynnthe PyNN instance
Returns
handler for the PyNN population
static py::object cypress::PyNN::create_source_population ( const PopulationBase pop,
py::module &  pynn 
)
static

Creates a PyNN source population

Parameters
popThe cypress population
pynnthe PyNN instance
Returns
handler for the PyNN population
void cypress::PyNN::do_run ( NetworkBase network,
Real  duration 
) const
overrideprotectedvirtual

Abstract method which has to be implemented by the backend.

Implements cypress::Backend.

static void cypress::PyNN::fetch_data_neo ( const std::vector< PopulationBase > &  populations,
const std::vector< py::object > &  pypopulations 
)
static

Fetch all data (spikes, traces) from NEO. This is a general method

Parameters
populationsCypress populations
pypopulationsPyNN populations
static void cypress::PyNN::fetch_data_nest ( const std::vector< PopulationBase > &  populations,
const std::vector< py::object > &  pypopulations 
)
static

Fetch all data (spikes, traces) from nest. This is faster than using NEO.

Parameters
populationsCypress populations
pypopulationsPyNN populations
static void cypress::PyNN::fetch_data_spinnaker ( const std::vector< PopulationBase > &  populations,
const std::vector< py::object > &  pypopulations 
)
static

Fetch all data (spikes, traces) from spiNNaker. This is faster than using NEO.

Parameters
populationsCypress populations
pypopulationsPyNN populations
static py::object cypress::PyNN::get_connector ( const std::string &  connector_name,
const py::module &  pynn,
const Real additional_parameter,
const bool  allow_self_connections 
)
static

Creates a PyNN 0.9 Connector

Parameters
connector_namename of the pyNN connector
pynnReference to the pynn module
additional_parameterAdditional parameter needed by the connector
allow_self_connectionsflag to allow self connections if source and target populations are the same
Returns
py::object reference to the connector
static py::object cypress::PyNN::get_connector7 ( const ConnectionDescriptor conn,
const py::module &  pynn 
)
static

Creates a PyNN 0.7 Connector

Parameters
connector_namename of the pyNN connector
group_connGroup connection description
pynnReference to the pynn module
Returns
py::object reference to the connector
static std::string cypress::PyNN::get_import ( const std::vector< std::string > &  imports,
const std::string &  simulator 
)
static

Returns a string containing the import for given simulator. Throws an error is simualator could not be found

Parameters
importslist of possible/supported imports
simulatorsimulator string
static int cypress::PyNN::get_neo_version ( )
static

Returns the neo version, 5 represents version 0.5.x

Returns
integer representing the neo version
static std::string cypress::PyNN::get_neuron_class ( const NeuronType neuron_type)
static

Given a NeuronType, this function returns the name of the PyNN neuron_type

Parameters
neuron_typeReference to the NeuronType of the population
Returns
PyNN class name of the neuron type
static py::object cypress::PyNN::get_pop_view ( const py::module &  pynn,
const py::object &  py_pop,
const PopulationBase c_pop,
const size_t &  start,
const size_t &  end 
)
static

Get a handler for a part of a population

Parameters
pynnhandler for the PyNN instance
py_popPyNN population
c_popCypress population
startid of the first neuron
endid of the last neuron
Returns
handler for PopulationView object
static int cypress::PyNN::get_pynn_version ( )
static

Returns the PyNN version, 8 represents version 0.8.x

Returns
integer representing the pyNN version
static py::object cypress::PyNN::group_connect ( const std::vector< PopulationBase > &  populations,
const std::vector< py::object > &  pypopulations,
const ConnectionDescriptor conn,
const py::module &  pynn,
const bool  nest_flag,
const Real  timestep = 0.0 
)
static

Connect based on an existing PyNN connector

Parameters
populationsvector of cypress populations
pypopulationsvector of PyNN populations
connCypress connection descriptor
pynnHandler for PyNN module
nest_flaguse sign of weight and ignore receptor_type for nest and current based neurons
timesteptimestep of the simulator
Returns
Handler for the connector
static py::object cypress::PyNN::group_connect ( const std::vector< PopulationBase > &  populations,
const std::vector< py::object > &  pypopulations,
const ConnectionDescriptor conn,
const py::module &  pynn,
const Real  nest_flag 
)
staticdelete
static py::object cypress::PyNN::group_connect7 ( const std::vector< PopulationBase > &  populations,
const std::vector< py::object > &  pypopulations,
const ConnectionDescriptor conn,
const py::module &  pynn 
)
static

Connect based on an existing PyNN connector

Parameters
populationsvector of cypress populations
pypopulationsvector of PyNN populations
connCypress connection descriptor
pynnHandler for PyNN module
Returns
Handler for the connector
const std::vector<std::string>& cypress::PyNN::imports ( ) const
inline

Returns the Python imports that tried to be used when starting the platform.

static void cypress::PyNN::init_logger ( )
static

Intitialize the logger, still TODO

static py::dict cypress::PyNN::json_to_dict ( Json  json)
static

Converting a Json object to a py::dict. Make sure that the python interpreter is already started before calling this function

Parameters
jsonThe json object which will be converted
Returns
python dictionary
static std::tuple<py::object, py::object> cypress::PyNN::list_connect ( const std::vector< py::object > &  pypopulations,
const ConnectionDescriptor  conn,
const py::module &  pynn,
const bool  current_based,
const Real  timestep = 0.0 
)
static

Creates a PyNN FromList Connection

Parameters
pypopulationslist of python populations
connConnectionDescriptor of the List connection
pynnHandler for PyNN python module
current_basedtrue if target population is current_based
timestepTimestep of the simulator, default 0
Returns
tuple of the excitatory,inhibitory connection. List is separated for compatibility reasons
static std::tuple<py::object, py::object> cypress::PyNN::list_connect ( const std::vector< py::object > &  pypopulations,
const ConnectionDescriptor  conn,
const py::module &  pynn,
const Real  current_based 
)
staticdelete
static std::tuple<py::object, py::object> cypress::PyNN::list_connect7 ( const std::vector< py::object > &  pypopulations,
const ConnectionDescriptor  conn,
const py::module &  pynn 
)
static

Creates a PyNN6/7 FromList Connection

Parameters
pypopulationslist of python populations
connConnectionDescriptor of the List connection
pynnHandler for PyNN python module
Returns
tuple of the excitatory,inhibitory connection. List is separated for compatibility reasons
template<typename T >
static Matrix<T> cypress::PyNN::matrix_from_numpy ( const py::object &  object,
bool  transposed = false 
)
static

Given a numpy object, this method creates the (transposed) C++ matrix without creating a copy. The python dtype is checked and compared to

Parameters
T.Matrix sizes are caught in Python, because the py::buffer_info seems to be misleading in some cases.
TType of the matrix
objecthandler for numpy array
transposedmatrix dimensions are swapped (hack for NEO)
Returns
C++ matrix of the numpy array
std::string cypress::PyNN::name ( ) const
inlineoverridevirtual

Returns the canonical name of the backend.

Implements cypress::Backend.

std::string cypress::PyNN::nmpi_platform ( ) const

Returns the NMPI platform name corresponding to the currently chosen PyNN backend.

const std::string& cypress::PyNN::normalised_simulator ( ) const
inline

Returns the canonical simulator name.

void cypress::Backend::run ( NetworkBase network,
Real  duration = 0.0 
) const
inherited

Simulates the given spiking neural network for the given duration.

Parameters
networkis the network that should be simulated. The simulation result will be written to the network instance.
durationis the duration for which the network should be simulated.
static void cypress::PyNN::set_homogeneous_rec ( const PopulationBase pop,
py::object &  pypop 
)
static

Set recording for a full population

Parameters
popSource cypress population
pypopTarget PyNN population
static void cypress::PyNN::set_inhomogeneous_parameters ( const PopulationBase pop,
py::object &  pypop,
bool  init_available = false 
)
static

Sets parameters of an existing population

Parameters
popSource cypress population
pypopTarget PyNN population
init_availableflag for initializing the population
static void cypress::PyNN::set_inhomogenous_rec ( const PopulationBase pop,
py::object &  pypop,
py::module &  pynn 
)
static

Set mixed recordings for a population

Parameters
popSource cypress population
pypopTarget PyNN population
Json cypress::PyNN::setup ( ) const
inline

Return the system config

const std::string& cypress::PyNN::simulator ( ) const
inline

Returns the simulator name as provided by the user.

static std::vector<std::string> cypress::PyNN::simulators ( )
static

Lists available PyNN simulators.

static py::object cypress::PyNN::spikey_create_homogeneous_pop ( const PopulationBase pop,
py::module &  pynn 
)
static

Creates a PyNN population with homogeneous parameters for Spikey, inhomogeneous parameters can be set with set_inhomogeneous_parameters afterwards.

Parameters
popThe cypress population
pynnthe PyNN instance
Returns
handler for the PyNN population
static py::object cypress::PyNN::spikey_create_source_population ( const PopulationBase pop,
py::module &  pynn 
)
static

Creates a PyNN source population for Spikey

Parameters
popThe cypress population
pynnthe PyNN instance
Returns
handler for the PyNN population
static void cypress::PyNN::spikey_get_spikes ( PopulationBase  pop,
py::object &  pypop 
)
static

Fetches spikes and saves them to pop

Parameters
popcypress population
pypopPyNN population
static void cypress::PyNN::spikey_get_voltage ( NeuronBase  neuron,
py::module &  pynn 
)
static

Fetch membrane voltage for a neuron in Spikey

Parameters
neuronThe cypress neuron recording the membrane
pynnpointer to PyNN module
static void cypress::PyNN::spikey_run ( NetworkBase source,
Real  duration,
py::module &  pynn,
py::dict  dict 
)
static

Special run function for the Spikey system

Parameters
sourceThe Network description
durationSimulation duration
pynnModule pointer to PyNN.hardware.spikey
static void cypress::PyNN::spikey_set_homogeneous_rec ( const PopulationBase pop,
py::object &  pypop,
py::module &  pynn 
)
static

Sets parameters of an existing population for spikey

Parameters
popSource cypress population
pypopTarget PyNN population
init_availableflag for initializing the population
static void cypress::PyNN::spikey_set_inhomogeneous_parameters ( const PopulationBase pop,
py::object &  pypop 
)
static

Set mixed recordings for a population for the Spikey system

Parameters
popSource cypress population
pypopTarget PyNN population
static void cypress::PyNN::spikey_set_inhomogeneous_rec ( const PopulationBase pop,
py::object &  pypop,
py::module  pynn 
)
static

Set recording for a full population for spikey

Parameters
popSource cypress population
pypopTarget PyNN population
std::unordered_set<const NeuronType *> cypress::PyNN::supported_neuron_types ( ) const
overridevirtual

Returns a set of neuron types which are supported by this backend. Trying to execute a network with other neurons than the ones specified in the result of this function will result in an exception.

Returns
a set of neuron types supported by this particular backend instance.

Implements cypress::Backend.

Real cypress::PyNN::timestep ( )

Calculates the timestep the simulation will be running with. This does not make any sense for analogue hardware, why zero is returned in this case.

Returns
the simulation timestep in milliseconds.

Member Data Documentation

std::vector<std::string> cypress::PyNN::m_imports
protected
bool cypress::PyNN::m_keep_log
protected
std::string cypress::PyNN::m_normalised_simulator
protected
Json cypress::PyNN::m_setup
protected
std::string cypress::PyNN::m_simulator
protected

The documentation for this class was generated from the following file: