| 7 | | def setup(timestep=0.1, min_delay=0.1, max_delay=10.0, debug=False, **extra_params): |
| | 16 | from pyNN.moose.cells import * |
| | 17 | from pyNN.moose.recording import * |
| | 18 | |
| | 19 | import logging |
| | 20 | logger = logging.getLogger("PyNN") |
| | 21 | |
| | 22 | # ============================================================================== |
| | 23 | # Functions for simulation set-up and control |
| | 24 | # ============================================================================== |
| | 25 | |
| | 26 | def setup(timestep=0.1, min_delay=0.1, max_delay=10.0, **extra_params): |
| 13 | | common.setup(timestep, min_delay, max_delay, debug, **extra_params) |
| 14 | | ctx = moose.PyMooseBase.getContext() |
| 15 | | ctx.setClock(0, timestep, 0) |
| | 32 | common.setup(timestep, min_delay, max_delay, **extra_params) |
| | 33 | simulator.state.dt = timestep |
| 21 | | |
| 22 | | def create(cellclass, cellparams=None, n=1): |
| 23 | | """ |
| 24 | | Create n cells all of the same type. |
| 25 | | If n > 1, return a list of cell ids/references. |
| 26 | | If n==1, return just the single id. |
| 27 | | """ |
| 28 | | assert n > 0, 'n must be a positive integer' |
| 29 | | cell_gids = [] |
| 30 | | if isinstance(cellclass, type): |
| 31 | | for i in range(n): |
| 32 | | print cellclass, cellparams |
| 33 | | cell_type = cellclass(cellparams) |
| 34 | | cell = eval("Neuron."+cell_type.moose_name)(**cell_type.parameters) |
| 35 | | cell_gids.append(cell.id) |
| 36 | | cell_gids = [ID(gid) for gid in cell_gids] |
| 37 | | elif isinstance(cellclass, str): # celltype is not a standard cell |
| 38 | | cellclass = eval(cellclass) |
| 39 | | for i in range(n): |
| 40 | | cell = cellclass(**cellparams) |
| 41 | | cell_gids.append(cell.id) |
| 42 | | cell_gids = [ID(gid) for gid in cell_gids] |
| 43 | | else: |
| 44 | | raise Exception("Invalid cell type") |
| 45 | | for id in cell_gids: |
| 46 | | id.cellclass = cellclass |
| 47 | | if n == 1: |
| 48 | | return cell_gids[0] |
| 49 | | else: |
| 50 | | return cell_gids |
| 60 | | moose.step(simtime) |
| | 44 | simulator.run(simtime) |
| | 45 | |
| | 46 | |
| | 47 | # ============================================================================== |
| | 48 | # Functions returning information about the simulation state |
| | 49 | # ============================================================================== |
| | 50 | |
| | 51 | get_current_time = common.get_current_time |
| | 52 | get_time_step = common.get_time_step |
| | 53 | get_min_delay = common.get_min_delay |
| | 54 | get_max_delay = common.get_max_delay |
| | 55 | num_processes = common.num_processes |
| | 56 | rank = common.rank |
| | 57 | |
| | 58 | # ============================================================================== |
| | 59 | # Low-level API for creating, connecting and recording from individual neurons |
| | 60 | # ============================================================================== |
| | 61 | |
| | 62 | create = common.create |
| | 63 | |
| | 64 | #connect = common.connect |
| | 65 | |
| | 66 | #set = common.set |
| | 67 | |
| | 68 | record = common.build_record('spikes', simulator) |
| | 69 | |
| | 70 | record_v = common.build_record('v', simulator) |
| | 71 | |
| | 72 | record_gsyn = common.build_record('gsyn', simulator) |
| | 73 | |
| | 74 | |