Show
Ignore:
Timestamp:
03/11/10 15:24:33 (2 years ago)
Author:
apdavison
Message:

Resumed implementation of the moose module. HH_cond_exp2.py example runs and gives the same results with moose as with neuron (nest is different - need to figure out why).

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/moose/__init__.py

    r601 r726  
    1 """Interfacing MOOSE to PyNN""" 
     1# encoding: utf-8 
     2""" 
     3MOOSE implementation of the PyNN API 
     4 
     5Authors: Subhasis Ray and Andrew Davison 
     6 
     7$Id:$ 
     8""" 
     9 
    210import moose 
    3 import Neuron 
    4 from cells import * 
    5 from pyNN import common 
     11from pyNN.moose import simulator 
     12from pyNN import common, recording 
     13common.simulator = simulator 
     14recording.simulator = simulator 
    615 
    7 def setup(timestep=0.1, min_delay=0.1, max_delay=10.0, debug=False, **extra_params): 
     16from pyNN.moose.cells import * 
     17from pyNN.moose.recording import * 
     18 
     19import logging 
     20logger = logging.getLogger("PyNN") 
     21 
     22# ============================================================================== 
     23#   Functions for simulation set-up and control 
     24# ============================================================================== 
     25 
     26def setup(timestep=0.1, min_delay=0.1, max_delay=10.0, **extra_params): 
    827    """ 
    928    Should be called at the very beginning of a script. 
     
    1130    simulator but not by others. 
    1231    """ 
    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 
    1634    return 0 
    1735 
    1836def end(compatible_output=True): 
    1937    """Do any necessary cleaning up before exiting.""" 
     38    for recorder in simulator.recorder_list: 
     39        recorder.write(gather=True, compatible_output=compatible_output) 
    2040    moose.PyMooseBase.endSimulation() 
    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 
    5141 
    52 def record(source, filename): 
    53         dataDir = Neutral("/data") 
    54         probe = Table(source.name, dataDir) 
    55         probe.step_mode = 3 
    56         probe.connect("inputRequest", source, "Vm") 
    57          
    5842def run(simtime): 
    5943        """Run the simulation for simtime""" 
    60         moose.step(simtime) 
     44        simulator.run(simtime) 
     45 
     46 
     47# ============================================================================== 
     48#   Functions returning information about the simulation state 
     49# ============================================================================== 
     50 
     51get_current_time = common.get_current_time 
     52get_time_step = common.get_time_step 
     53get_min_delay = common.get_min_delay 
     54get_max_delay = common.get_max_delay 
     55num_processes = common.num_processes 
     56rank = common.rank    
     57 
     58# ============================================================================== 
     59#   Low-level API for creating, connecting and recording from individual neurons 
     60# ============================================================================== 
     61 
     62create = common.create 
     63 
     64#connect = common.connect 
     65 
     66#set = common.set 
     67 
     68record = common.build_record('spikes', simulator) 
     69 
     70record_v = common.build_record('v', simulator) 
     71 
     72record_gsyn = common.build_record('gsyn', simulator) 
     73         
     74