|
1 | 1 | """ |
2 | 2 | Brian2 implementation of the PyNN API. |
3 | 3 |
|
4 | | -:copyright: Copyright 2006-2016 by the PyNN team, see AUTHORS. |
| 4 | +:copyright: Copyright 2006-2023 by the PyNN team, see AUTHORS. |
5 | 5 | :license: CeCILL, see LICENSE for details. |
6 | 6 | """ |
7 | 7 |
|
8 | | -import logging |
9 | | -import brian2 # noqa: F401 |
10 | | -from pyNN import common, space # noqa: F401 |
11 | | -from pyNN.common.control import DEFAULT_MAX_DELAY, DEFAULT_TIMESTEP, DEFAULT_MIN_DELAY |
12 | | -from pyNN.standardmodels import StandardCellType |
13 | | -from pyNN.connectors import * # noqa: F401, F403 |
14 | | -from pyNN.connectors import FixedProbabilityConnector |
15 | | -from pyNN.brian2 import simulator |
16 | | -from pyNN.brian2.standardmodels.cells import * # noqa: F401, F403 |
17 | | -from pyNN.brian2.standardmodels.synapses import * # noqa: F401, F403 |
18 | | -from pyNN.brian2.standardmodels.synapses import StaticSynapse |
19 | | -from pyNN.brian2.standardmodels.electrodes import * # noqa: F401, F403 |
20 | | -from pyNN.brian2.standardmodels.electrodes import update_currents |
21 | | -from pyNN.brian2.standardmodels.receptors import ( # noqa: F401 |
22 | | - CondAlphaPostSynapticResponse, AlphaPSR, |
23 | | - CondExpPostSynapticResponse, ExpPSR, |
24 | | - CurrExpPostSynapticResponse) |
25 | | -from pyNN.brian2.populations import Population, PopulationView, Assembly # noqa: F401 |
26 | | -from pyNN.brian2.projections import Projection |
27 | | -from pyNN.recording import get_io |
28 | | - |
29 | | -logger = logging.getLogger("PyNN") |
| 8 | +from .. import errors, random, space # noqa: F401 |
| 9 | +from ..network import Network # noqa: F401 |
| 10 | +from ..standardmodels import StandardCellType |
| 11 | +from ..random import NumpyRNG, GSLRNG, RandomDistribution # noqa: F401 |
| 12 | +from ..connectors import * # noqa: F401, F403 |
| 13 | +from .standardmodels.cells import * # noqa: F401, F403 |
| 14 | +from .standardmodels.synapses import * # noqa: F401, F403 |
| 15 | +from .standardmodels.electrodes import * # noqa: F401, F403 |
| 16 | +from .standardmodels.receptors import ( # noqa: F401 |
| 17 | + CondAlphaPostSynapticResponse, |
| 18 | + AlphaPSR, |
| 19 | + CondExpPostSynapticResponse, |
| 20 | + ExpPSR, |
| 21 | + CurrExpPostSynapticResponse, |
| 22 | +) |
| 23 | +from .populations import Population, PopulationView, Assembly # noqa: F401 |
| 24 | +from .projections import Projection # noqa: F401 |
| 25 | +from .control import ( # noqa: F401 |
| 26 | + setup, |
| 27 | + end, |
| 28 | + run, |
| 29 | + run_until, |
| 30 | + run_for, |
| 31 | + reset, |
| 32 | + initialize, |
| 33 | + get_current_time, |
| 34 | + get_time_step, |
| 35 | + get_min_delay, |
| 36 | + get_max_delay, |
| 37 | + num_processes, |
| 38 | + rank, |
| 39 | +) |
| 40 | +from .procedural_api import create, connect, record, record_v, record_gsyn # noqa: F401 |
30 | 41 |
|
31 | 42 |
|
32 | 43 | def list_standard_models(): |
33 | 44 | """Return a list of all the StandardCellType classes available for this simulator.""" |
34 | | - return [obj.__name__ for obj in globals().values() |
35 | | - if isinstance(obj, type) and issubclass(obj, StandardCellType)] |
36 | | - |
37 | | - |
38 | | -def setup(timestep=DEFAULT_TIMESTEP, min_delay=DEFAULT_MIN_DELAY, |
39 | | - **extra_params): |
40 | | - """ |
41 | | - Should be called at the very beginning of a script. |
42 | | - extra_params contains any keyword arguments that are required by a given |
43 | | - simulator but not by others. |
44 | | - """ |
45 | | - |
46 | | - max_delay = extra_params.get('max_delay', DEFAULT_MAX_DELAY) |
47 | | - common.setup(timestep, min_delay, **extra_params) |
48 | | - simulator.state.clear() |
49 | | - simulator.state.dt = timestep # move to common.setup? |
50 | | - simulator.state.min_delay = min_delay |
51 | | - simulator.state.max_delay = max_delay |
52 | | - simulator.state.mpi_rank = 0 |
53 | | - simulator.state.num_processes = 1 |
54 | | - |
55 | | - simulator.state.network.add( |
56 | | - brian2.NetworkOperation(update_currents, when="start", clock=simulator.state.network.clock) |
57 | | - ) |
58 | | - return rank() |
59 | | - |
60 | | - |
61 | | -def end(compatible_output=True): |
62 | | - """Do any necessary cleaning up before exiting.""" |
63 | | - for (population, variables, filename) in simulator.state.write_on_end: |
64 | | - io = get_io(filename) |
65 | | - population.write_data(io, variables) |
66 | | - simulator.state.write_on_end = [] |
67 | | - # should have common implementation of end() |
68 | | - |
69 | | - |
70 | | -run, run_until = common.build_run(simulator) |
71 | | -run_for = run |
72 | | - |
73 | | -reset = common.build_reset(simulator) |
74 | | - |
75 | | -initialize = common.initialize |
76 | | - |
77 | | -get_current_time, get_time_step, get_min_delay, get_max_delay, \ |
78 | | - num_processes, rank = common.build_state_queries(simulator) |
79 | | - |
80 | | -create = common.build_create(Population) |
81 | | - |
82 | | -connect = common.build_connect(Projection, FixedProbabilityConnector, StaticSynapse) |
83 | | - |
84 | | - |
85 | | -record = common.build_record(simulator) |
86 | | - |
87 | | - |
88 | | -def record_v(source, filename): return record(['v'], source, filename) |
89 | | - |
90 | | - |
91 | | -def record_gsyn(source, filename): return record(['gsyn_exc', 'gsyn_inh'], source, filename) |
| 45 | + return [ |
| 46 | + obj.__name__ |
| 47 | + for obj in globals().values() |
| 48 | + if isinstance(obj, type) and issubclass(obj, StandardCellType) |
| 49 | + ] |
0 commit comments