1"""
2Mock implementation of the PyNN API, for testing and documentation purposes.
3
4This simulator implements the PyNN API, but generates random data rather than
5really running simulations.
6
7:copyright: Copyright 2006-2021 by the PyNN team, see AUTHORS.
8:license: CeCILL, see LICENSE for details.
9"""
10
11import logging
12from pyNN import common
13from pyNN.common.control import DEFAULT_MAX_DELAY, DEFAULT_TIMESTEP, DEFAULT_MIN_DELAY
14from pyNN.connectors import *
15from pyNN.recording import *
16from . import simulator
17from .standardmodels import *
18from .populations import Population, PopulationView, Assembly
19from .projections import Projection
20from neo.io import get_io
21
22
23logger = logging.getLogger("PyNN")
24
25
26def list_standard_models():
27    """Return a list of all the StandardCellType classes available for this simulator."""
28    return [obj.__name__ for obj in globals().values() if isinstance(obj, type) and issubclass(obj, StandardCellType)]
29
30
31def setup(timestep=DEFAULT_TIMESTEP, min_delay=DEFAULT_MIN_DELAY,
32          **extra_params):
33
34    max_delay = extra_params.get('max_delay', DEFAULT_MAX_DELAY)
35    common.setup(timestep, min_delay, **extra_params)
36    simulator.state.clear()
37    simulator.state.dt = timestep  # move to common.setup?
38    simulator.state.min_delay = min_delay
39    simulator.state.max_delay = max_delay
40    simulator.state.mpi_rank = extra_params.get('rank', 0)
41    simulator.state.num_processes = extra_params.get('num_processes', 1)
42    return rank()
43
44
45def end(compatible_output=True):
46    """Do any necessary cleaning up before exiting."""
47    for (population, variables, filename) in simulator.state.write_on_end:
48        io = get_io(filename)
49        population.write_data(io, variables)
50    simulator.state.write_on_end = []
51    # should have common implementation of end()
52
53
54run, run_until = common.build_run(simulator)
55run_for = run
56
57reset = common.build_reset(simulator)
58
59initialize = common.initialize
60
61get_current_time, get_time_step, get_min_delay, get_max_delay, \
62    num_processes, rank = common.build_state_queries(simulator)
63
64create = common.build_create(Population)
65
66connect = common.build_connect(Projection, FixedProbabilityConnector, StaticSynapse)
67
68
69record = common.build_record(simulator)
70
71
72def record_v(source, filename): return record(['v'], source, filename)
73
74
75def record_gsyn(source, filename): return record(['gsyn_exc', 'gsyn_inh'], source, filename)
76