Network
self, everything=False) core.Network.Network(
A network gathers already defined populations, projections and monitors in order to run them independently.
This is particularly useful when varying single parameters of a network and comparing the results (see the parallel_run()
method).
Only objects declared before the creation of the network can be used. Global methods such as simulate()
must be used on the network object. The objects must be accessed through the get()
method, as the original ones will not be part of the network (a copy is made).
Each network must be individually compiled, but it does not matter if the original objects were already compiled.
When passing everything=True
to the constructor, all populations/projections/monitors already defined at the global level will be added to the network.
If not, you can select which object will be added to network with the add()
method.
Example with everything=True
:
= ann.Population(100, Izhikevich)
pop = ann.Projection(pop, pop, 'exc')
proj 1.0)
proj.connect_all_to_all(= ann.Monitor(pop, 'spike')
m
compile() # Optional
ann.
= ann.Network(everything=True)
net = 0.02
net.get(pop).a compile()
net.1000.)
net.simulate(
= ann.Network(everything=True)
net2 = 0.05
net2.get(pop).a compile()
net2.1000.)
net2.simulate(
= net.get(m).raster_plot()
t, n = net2.get(m).raster_plot() t2, n2
Example with everything=False
(the default):
= ann.Population(100, Izhikevich)
pop = ann.Projection(pop, pop, 'exc')
proj1 1.0)
proj1.connect_all_to_all(= ann.Projection(pop, pop, 'exc')
proj2 2.0)
proj2.connect_all_to_all(= ann.Monitor(pop, 'spike')
m
= ann.Network()
net
net.add([pop, proj1, m])compile()
net.1000.)
net.simulate(
= ann.Network()
net2
net2.add([pop, proj2, m])compile()
net2.1000.)
net2.simulate(
= net.get(m).raster_plot()
t, n = net2.get(m).raster_plot() t2, n2
Parameters
Name | Type | Description | Default |
---|---|---|---|
everything | bool | defines if all existing populations and projections should be automatically added (default: False). | False |
Methods
Name | Description |
---|---|
add | Adds a Population, Projection or Monitor to the network. |
compile | Compiles the network. |
disable_learning | Disables learning for all projections. |
enable_learning | Enables learning for all projections. |
get | Returns the local Population, Projection or Monitor corresponding to the provided argument. |
get_current_step | Returns the current simulation step. |
get_monitors | Returns a list of declared monitors. By default, all monitors are returned. |
get_population | Returns the population with the given name. |
get_populations | Returns a list of all declared populations in this network. |
get_projection | Returns the projection with the given name. |
get_projections | Get a list of declared projections for the current network. By default, |
get_time | Returns the current time in ms. |
load | Loads a saved state of the current network by calling ANNarchy.core.IO.load(). |
reset | Reinitialises the network to its state before the call to compile. |
save | Saves the current network by calling ANNarchy.core.IO.save(). |
set_current_step | Sets the current simulation step. |
set_seed | Sets the seed of the random number generators for this network. |
set_time | Sets the current time in ms. |
simulate | Runs the network for the given duration in milliseconds. |
simulate_until | Runs the network for the maximal duration in milliseconds. If the stop_condition defined in the population becomes true during the simulation, it is stopped. |
step | Performs a single simulation step (duration = dt ). |
add
core.Network.Network.add(objects)
Adds a Population, Projection or Monitor to the network.
Parameters
Name | Type | Description | Default |
---|---|---|---|
objects | list | A single object or a list to add to the network. | required |
compile
compile(
core.Network.Network.='annarchy',
directory=False,
clean='default',
compiler='default',
compiler_flags='',
add_sources='',
extra_libs={'device': 0},
cuda_config='',
annarchy_json=False,
silent=False,
debug_build=False,
profile_enabled )
Compiles the network.
Parameters
Name | Type | Description | Default |
---|---|---|---|
directory | str | name of the subdirectory where the code will be generated and compiled. Must be a relative path. Default: “annarchy/”. | 'annarchy' |
clean | bool | boolean to specifying if the library should be recompiled entirely or only the changes since last compilation (default: False). | False |
compiler | str | C++ compiler to use. Default: g++ on GNU/Linux, clang++ on OS X. Valid compilers are [g++, clang++]. | 'default' |
compiler_flags | list[str] | platform-specific flags to pass to the compiler. Default: “-march=native -O2”. Warning: -O3 often generates slower code and can cause linking problems, so it is not recommended. | 'default' |
cuda_config | dict | dictionary defining the CUDA configuration for each population and projection. | {'device': 0} |
annarchy_json | str | compiler flags etc are stored in a .json file normally placed in the home directory. With this flag one can directly assign a file location. | '' |
silent | bool | defines if the “Compiling… OK” should be printed. | False |
disable_learning
=None) core.Network.Network.disable_learning(projections
Disables learning for all projections.
Parameters
Name | Type | Description | Default |
---|---|---|---|
projections | list | the projections whose learning should be disabled. By default, all the existing projections are disabled. | None |
enable_learning
=None, period=None, offset=None) core.Network.Network.enable_learning(projections
Enables learning for all projections.
Parameters
Name | Type | Description | Default |
---|---|---|---|
projections | list | the projections whose learning should be enabled. By default, all the existing projections are disabled. | None |
get
core.Network.Network.get(obj)
Returns the local Population, Projection or Monitor corresponding to the provided argument.
obj
is for example a top-level poopulation, while net.get(pop)
is the copy local to the network.
Example:
= ann.Population(100, Izhikevich)
pop = ann.Network()
net
net.add(pop)compile()
net.
print(net.get(pop).v)
Parameters
Name | Type | Description | Default |
---|---|---|---|
obj | A single object or a list of objects. | required |
Returns
Name | Type | Description |
---|---|---|
The corresponding object or list of objects. |
get_current_step
core.Network.Network.get_current_step()
Returns the current simulation step.
get_monitors
=None) core.Network.Network.get_monitors(obj
Returns a list of declared monitors. By default, all monitors are returned. By setting obj, only monitors recording from this object, either Population or Projection will be returned.
get_population
core.Network.Network.get_population(name)
Returns the population with the given name.
Parameters
Name | Type | Description | Default |
---|---|---|---|
name | str | name of the population | required |
Returns
Name | Type | Description |
---|---|---|
Population | The requested Population object if existing, None otherwise. |
get_populations
core.Network.Network.get_populations()
Returns a list of all declared populations in this network.
Returns
Name | Type | Description |
---|---|---|
list[Population] | the list of all populations in the network. |
get_projection
core.Network.Network.get_projection(name)
Returns the projection with the given name.
Parameters
Name | Type | Description | Default |
---|---|---|---|
name | str | name of the projection | required |
Returns
Name | Type | Description |
---|---|---|
Projection | The requested Projection object if existing, None otherwise. |
get_projections
core.Network.Network.get_projections(=None,
post=None,
pre=None,
target=False,
suppress_error )
Get a list of declared projections for the current network. By default, the method returns all connections within the network.
By setting the arguments, post, pre and target one can select a subset.
Parameters
Name | Type | Description | Default |
---|---|---|---|
post | all returned projections should have this population as post. | None |
|
pre | all returned projections should have this population as pre. | None |
|
target | all returned projections should have this target. | None |
|
suppress_error | by default, ANNarchy throws an error if the list of assigned projections is empty. If this flag is set to True, the error message is suppressed. | False |
Returns
Name | Type | Description |
---|---|---|
list[Projection] | the list of all assigned projections in this network or a subset according to the arguments. |
get_time
core.Network.Network.get_time()
Returns the current time in ms.
load
core.Network.Network.load(
filename,=True,
populations=True,
projections=None,
pickle_encoding )
Loads a saved state of the current network by calling ANNarchy.core.IO.load().
Parameters
Name | Type | Description | Default |
---|---|---|---|
filename | str | filename, may contain relative or absolute path. | required |
populations | bool | if True, population data will be saved (by default True) | True |
projections | bool | if True, projection data will be saved (by default True) | True |
pickle_encoding | str | optional parameter provided to the pickle.load() method. If set to None the default is used. | None |
reset
core.Network.Network.reset(=True,
populations=False,
projections=True,
monitors=False,
synapses )
Reinitialises the network to its state before the call to compile.
Parameters
Name | Type | Description | Default |
---|---|---|---|
populations | bool | if True (default), the neural parameters and variables will be reset to their initial value. | True |
projections | bool | if True, the synaptic parameters and variables (except the connections) will be reset (default=False). | False |
synapses | bool | if True, the synaptic weights will be erased and recreated (default=False). | False |
save
=True, projections=True) core.Network.Network.save(filename, populations
Saves the current network by calling ANNarchy.core.IO.save().
Parameters
Name | Type | Description | Default |
---|---|---|---|
filename | str | filename, may contain relative or absolute path. | required |
populations | bool | if True, population data will be saved (by default True) | True |
projections | bool | if True, projection data will be saved (by default True) | True |
set_current_step
core.Network.Network.set_current_step(t)
Sets the current simulation step.
Warning: can be dangerous for some spiking models.
set_seed
=True) core.Network.Network.set_seed(seed, use_seed_seq
Sets the seed of the random number generators for this network.
set_time
=0) core.Network.Network.set_time(t, net_id
Sets the current time in ms.
Warning: can be dangerous for some spiking models.
simulate
=False) core.Network.Network.simulate(duration, measure_time
Runs the network for the given duration in milliseconds.
The number of simulation steps is computed relative to the discretization step dt
declared in setup()
(default: 1ms):
1000.0) net.simulate(
Parameters
Name | Type | Description | Default |
---|---|---|---|
duration | float | the duration in milliseconds. | required |
measure_time | bool | defines whether the simulation time should be printed (default=False). | False |
simulate_until
core.Network.Network.simulate_until(
max_duration,
population,='and',
operator=False,
measure_time )
Runs the network for the maximal duration in milliseconds. If the stop_condition
defined in the population becomes true during the simulation, it is stopped.
One can specify several populations. If the stop condition is true for any of the populations, the simulation will stop (‘or’ function).
Example:
= ann.Population( ..., stop_condition = "r > 1.0 : any")
pop1
...compile()
net.=1000.0. population=pop1) net.simulate_until(max_duration
Parameters
Name | Type | Description | Default |
---|---|---|---|
max_duration | float | the maximum duration of the simulation in milliseconds. | required |
population | Population | the (list of) population whose stop_condition should be checked to stop the simulation. |
required |
operator | str | operator to be used (‘and’ or ‘or’) when multiple populations are provided (default: ‘and’). | 'and' |
measure_time | bool | defines whether the simulation time should be printed (default=False). | False |
Returns
Name | Type | Description |
---|---|---|
float | the actual duration of the simulation in milliseconds. |
step
core.Network.Network.step()
Performs a single simulation step (duration = dt
).