ANNarchy 4.8.2
  • ANNarchy
  • Installation
  • Tutorial
  • Manual
  • Notebooks
  • Reference

  • Reference
  • Core components
    • Population
    • Projection
    • Neuron
    • Synapse
    • Monitor
    • PopulationView
    • Dendrite
    • Network
  • Configuration
    • setup
    • compile
    • clear
    • reset
    • set_seed
    • get_population
    • get_projection
    • populations
    • projections
    • monitors
  • Simulation
    • simulate
    • simulate_until
    • step
    • parallel_run
    • enable_learning
    • disable_learning
    • get_time
    • set_time
    • get_current_step
    • set_current_step
    • dt
  • Neuron models
    • LeakyIntegrator
    • Izhikevich
    • IF_curr_exp
    • IF_cond_exp
    • IF_curr_alpha
    • IF_cond_alpha
    • HH_cond_exp
    • EIF_cond_alpha_isfa_ista
    • EIF_cond_exp_isfa_ista
  • Synapse models
    • STP
    • STDP
    • Hebb
    • Oja
    • IBCM
  • Inputs
    • InputArray
    • TimedArray
    • PoissonPopulation
    • TimedPoissonPopulation
    • SpikeSourceArray
    • HomogeneousCorrelatedSpikeTrains
    • CurrentInjection
    • DecodingProjection
    • ImagePopulation
    • VideoPopulation
  • IO
    • save
    • load
    • save_parameters
    • load_parameters
  • Utilities
    • report
  • Random Distributions
    • Uniform
    • DiscreteUniform
    • Normal
    • LogNormal
    • Exponential
    • Gamma
    • Binomial
  • Functions and Constants
    • add_function
    • functions
    • Constant
    • get_constant
  • Plotting
    • raster_plot
    • histogram
    • inter_spike_interval
    • coefficient_of_variation
    • population_rate
    • smoothed_rate
  • Callbacks
    • every
    • callbacks_enabled
    • disable_callbacks
    • enable_callbacks
    • clear_all_callbacks
  • Convolution
    • Convolution
    • Pooling
    • Transpose
    • Copy
  • BOLD monitoring
    • BoldMonitor
    • BoldModel
    • balloon_RN
    • balloon_RL
    • balloon_CN
    • balloon_CL
    • balloon_maith2021
    • balloon_two_inputs
  • Tensorboard logging
    • Logger
  • ANN-to-SNN conversion
    • ANNtoSNNConverter

On this page

  • Network
    • Parameters
    • Methods
      • add
      • compile
      • disable_learning
      • enable_learning
      • get
      • get_current_step
      • get_monitors
      • get_population
      • get_populations
      • get_projection
      • get_projections
      • get_time
      • load
      • reset
      • save
      • set_current_step
      • set_seed
      • set_time
      • simulate
      • simulate_until
      • step

Network

core.Network.Network(self, everything=False)

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:

pop = ann.Population(100, Izhikevich)
proj = ann.Projection(pop, pop, 'exc')
proj.connect_all_to_all(1.0)
m = ann.Monitor(pop, 'spike')

ann.compile() # Optional

net = ann.Network(everything=True)
net.get(pop).a = 0.02
net.compile()
net.simulate(1000.)

net2 = ann.Network(everything=True)
net2.get(pop).a = 0.05
net2.compile()
net2.simulate(1000.)

t, n = net.get(m).raster_plot()
t2, n2 = net2.get(m).raster_plot()

Example with everything=False (the default):

pop = ann.Population(100, Izhikevich)
proj1 = ann.Projection(pop, pop, 'exc')
proj1.connect_all_to_all(1.0)
proj2 = ann.Projection(pop, pop, 'exc')
proj2.connect_all_to_all(2.0)
m = ann.Monitor(pop, 'spike')

net = ann.Network()
net.add([pop, proj1, m])
net.compile()
net.simulate(1000.)

net2 = ann.Network()
net2.add([pop, proj2, m])
net2.compile()
net2.simulate(1000.)

t, n = net.get(m).raster_plot()
t2, n2 = net2.get(m).raster_plot()

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

core.Network.Network.compile(
    directory='annarchy',
    clean=False,
    compiler='default',
    compiler_flags='default',
    add_sources='',
    extra_libs='',
    cuda_config={'device': 0},
    annarchy_json='',
    silent=False,
    debug_build=False,
    profile_enabled=False,
)

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

core.Network.Network.disable_learning(projections=None)

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

core.Network.Network.enable_learning(projections=None, period=None, offset=None)

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:

pop = ann.Population(100, Izhikevich)
net = ann.Network()
net.add(pop)
net.compile()

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

core.Network.Network.get_monitors(obj=None)

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(
    post=None,
    pre=None,
    target=None,
    suppress_error=False,
)

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,
    populations=True,
    projections=True,
    pickle_encoding=None,
)

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(
    populations=True,
    projections=False,
    monitors=True,
    synapses=False,
)

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

core.Network.Network.save(filename, populations=True, projections=True)

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

core.Network.Network.set_seed(seed, use_seed_seq=True)

Sets the seed of the random number generators for this network.

set_time

core.Network.Network.set_time(t, net_id=0)

Sets the current time in ms.

Warning: can be dangerous for some spiking models.

simulate

core.Network.Network.simulate(duration, measure_time=False)

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):

net.simulate(1000.0)

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,
    operator='and',
    measure_time=False,
)

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:

pop1 = ann.Population( ..., stop_condition = "r > 1.0 : any")
...
net.compile()
net.simulate_until(max_duration=1000.0. population=pop1)

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).

Dendrite
setup
 

Copyright Julien Vitay, Helge Ülo Dinkelbach, Fred Hamker