Network#
A Network
object holds copies of previously defined populations,
projections or monitors in order to simulate them independently.
The parallel_run()
method can be used to simulate different networks
in parallel.
ANNarchy.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
:
pop = Population(100, Izhikevich)
proj = Projection(pop, pop, 'exc')
proj.connect_all_to_all(1.0)
m = Monitor(pop, 'spike')
compile() # Optional
net = Network(everything=True)
net.get(pop).a = 0.02
net.compile()
net.simulate(1000.)
net2 = 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 = Population(100, Izhikevich)
proj1 = Projection(pop, pop, 'exc')
proj1.connect_all_to_all(1.0)
proj2 = Projection(pop, pop, 'exc')
proj2.connect_all_to_all(2.0)
m = Monitor(pop, 'spike')
net = Network()
net.add([pop, proj1, m])
net.compile()
net.simulate(1000.)
net2 = 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()
Source code in ANNarchy/core/Network.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 |
|
__init__(everything=False)
#
Parameters:
-
everything
–defines if all existing populations and projections should be automatically added (default: False).
Source code in ANNarchy/core/Network.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
|
add(objects)
#
Adds a Population, Projection or Monitor to the network.
Parameters:
-
objects
–A single object or a list to add to the network.
Source code in ANNarchy/core/Network.py
147 148 149 150 151 152 153 154 155 156 157 |
|
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:
-
directory
–name of the subdirectory where the code will be generated and compiled. Must be a relative path. Default: "annarchy/".
-
clean
–boolean to specifying if the library should be recompiled entirely or only the changes since last compilation (default: False).
-
compiler
–C++ compiler to use. Default: g++ on GNU/Linux, clang++ on OS X. Valid compilers are [g++, clang++].
-
compiler_flags
–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.
-
cuda_config
–dictionary defining the CUDA configuration for each population and projection.
-
annarchy_json
–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
–defines if the "Compiling... OK" should be printed.
Source code in ANNarchy/core/Network.py
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
|
disable_learning(projections=None)
#
Disables learning for all projections.
Parameters:
-
projections
–the projections whose learning should be disabled. By default, all the existing projections are disabled.
Source code in ANNarchy/core/Network.py
457 458 459 460 461 462 463 464 465 466 |
|
enable_learning(projections=None, period=None, offset=None)
#
Enables learning for all projections.
Parameters:
-
projections
–the projections whose learning should be enabled. By default, all the existing projections are disabled.
Source code in ANNarchy/core/Network.py
446 447 448 449 450 451 452 453 454 455 |
|
get(obj)
#
Returns the local Population, Projection or Monitor identical to the provided argument.
Example:
pop = Population(100, Izhikevich)
net = Network()
net.add(pop)
net.compile()
net.simulate(100.)
print net.get(pop).v
Parameters:
-
obj
–A single object or a list of objects.
Returns:
-
–
The corresponding object or list of objects.
Source code in ANNarchy/core/Network.py
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
|
get_current_step()
#
Returns the current simulation step.
Source code in ANNarchy/core/Network.py
428 429 430 |
|
get_population(name)
#
Returns the population with the given name.
Parameters:
-
name
–name of the population
Returns:
-
–
The requested
Population
object if existing,None
otherwise.
Source code in ANNarchy/core/Network.py
468 469 470 471 472 473 474 475 476 477 478 479 |
|
get_populations()
#
Returns a list of all declared populations in this network.
Source code in ANNarchy/core/Network.py
494 495 496 497 498 499 500 |
|
get_projection(name)
#
Returns the projection with the given name.
Parameters:
-
name
–name of the projection
Returns:
-
–
The requested
Projection
object if existing,None
otherwise.
Source code in ANNarchy/core/Network.py
481 482 483 484 485 486 487 488 489 490 491 492 |
|
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:
-
post
–all returned projections should have this population as post.
-
pre
–all returned projections should have this population as pre.
-
target
–all returned projections should have this target.
-
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.
Returns:
-
–
A list of all assigned projections in this network or a subset according to the arguments.
Source code in ANNarchy/core/Network.py
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 |
|
get_time()
#
Returns the current time in ms.
Source code in ANNarchy/core/Network.py
416 417 418 |
|
load(filename, populations=True, projections=True, pickle_encoding=None)
#
Loads a saved state of the current network by calling ANNarchy.core.IO.load().
Parameters:
-
filename
–filename, may contain relative or absolute path.
-
populations
–if True, population data will be saved (by default True)
-
projections
–if True, projection data will be saved (by default True)
-
pickle_encoding
–optional parameter provided to the pickle.load() method. If set to None the default is used.
Source code in ANNarchy/core/Network.py
543 544 545 546 547 548 549 550 551 552 |
|
reset(populations=True, projections=False, monitors=True, synapses=False)
#
Reinitialises the network to its state before the call to compile.
Parameters:
-
populations
–if True (default), the neural parameters and variables will be reset to their initial value.
-
projections
–if True, the synaptic parameters and variables (except the connections) will be reset (default=False).
-
synapses
–if True, the synaptic weights will be erased and recreated (default=False).
Source code in ANNarchy/core/Network.py
406 407 408 409 410 411 412 413 414 |
|
save(filename, populations=True, projections=True)
#
Saves the current network by calling ANNarchy.core.IO.save().
Parameters:
-
filename
–filename, may contain relative or absolute path.
-
populations
–if True, population data will be saved (by default True)
-
projections
–if True, projection data will be saved (by default True)
Source code in ANNarchy/core/Network.py
554 555 556 557 558 559 560 561 562 |
|
set_current_step(t)
#
Sets the current simulation step.
Warning: can be dangerous for some spiking models.
Source code in ANNarchy/core/Network.py
432 433 434 435 436 437 438 |
|
set_seed(seed, use_seed_seq=True)
#
Sets the seed of the random number generators for this network.
Source code in ANNarchy/core/Network.py
440 441 442 443 444 |
|
set_time(t, net_id=0)
#
Sets the current time in ms.
Warning: can be dangerous for some spiking models.
Source code in ANNarchy/core/Network.py
420 421 422 423 424 425 426 |
|
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):
simulate(1000.0)
Parameters:
-
duration
–the duration in milliseconds.
-
measure_time
–defines whether the simulation time should be printed (default=False).
Source code in ANNarchy/core/Network.py
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 |
|
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 = Population( ..., stop_condition = "r > 1.0 : any")
compile()
simulate_until(max_duration=1000.0. population=pop1)
Parameters:
-
max_duration
–the maximum duration of the simulation in milliseconds.
-
population
–the (list of) population whose
stop_condition
should be checked to stop the simulation. -
operator
–operator to be used ('and' or 'or') when multiple populations are provided (default: 'and').
-
measure_time
–defines whether the simulation time should be printed (default=False).
Returns:
-
–
the actual duration of the simulation in milliseconds.
Source code in ANNarchy/core/Network.py
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 |
|
step()
#
Performs a single simulation step (duration = dt
).
Source code in ANNarchy/core/Network.py
400 401 402 403 404 |
|
ANNarchy.core.Network.parallel_run(method, networks=None, number=0, max_processes=-1, measure_time=False, sequential=False, same_seed=False, annarchy_json='', visible_cores=[], **args)
#
Allows to run multiple networks in parallel using multiprocessing.
If the networks
argument is provided as a list of Network objects, the given method will be executed for each of these networks.
If number
is given instead, the same number of networks will be created and the method is applied.
If number
is used, the created networks are not returned, you should return what you need to analyse.
Example:
pop1 = PoissonPopulation(100, rates=10.0)
pop2 = Population(100, Izhikevich)
proj = Projection(pop1, pop2, 'exc')
proj.connect_fixed_probability(weights=5.0, probability=0.2)
m = Monitor(pop2, 'spike')
compile()
def simulation(idx, net):
net.get(pop1).rates = 10. * idx
net.simulate(1000.)
return net.get(m).raster_plot()
results = parallel_run(method=simulation, number = 3)
t1, n1 = results[0]
t2, n2 = results[1]
t3, n3 = results[2]
Parameters:
-
method
–a Python method which will be executed for each network. This function must accept an integer as first argument (id of the simulation) and a Network object as second argument.
-
networks
–a list of networks to simulate in parallel.
-
number
–the number of identical networks to run in parallel.
-
max_processes
–maximal number of processes to start concurrently (default: the available number of cores on the machine).
-
measure_time
–if the total simulation time should be printed out.
-
sequential
–if True, runs the simulations sequentially instead of in parallel (default: False).
-
same_seed
–if True, all networks will use the same seed. If not, the seed will be randomly initialized with time(0) for each network (default). It has no influence when the
networks
argument is set (the seed has to be set individually for each network usingnet.set_seed()
), only whennumber
is used. -
annarchy_json
–path to a different configuration file if needed (default "").
-
visible_cores
–a list of CPU core ids to simulate on (must have max_processes entries and max_processes must be != -1)
-
args
–other named arguments you want to pass to the simulation method.
Returns:
-
–
a list of the values returned by
method
.
Source code in ANNarchy/core/Network.py
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 |
|