Beispiel #1
0
def assignTicks(tickTargetMap):
    """
    Assign ticks to target elements.

    Parameters
    ----------
    tickTargetMap:
    Map from tick no. to target path and method. The path can be wildcard expression also.
    """
    if len(tickTargetMap) == 0:
        assignDefaultTicks()
    for tickNo, target in tickTargetMap.items():
        if not isinstance(target, basestring):
            if len(target) == 1:
                _moose.useClock(tickNo, target[0], 'process')
            elif len(target) == 2:
                _moose.useClock(tickNo, target[0], target[1])
        else:
            _moose.useClock(tickNo, target, 'process')
Beispiel #2
0
def assignTicks(tickTargetMap):
    """
    Assign ticks to target elements.

    Parameters
    ----------
    tickTargetMap:
    Map from tick no. to target path and method. The path can be wildcard expression also.
    """
    if len(tickTargetMap) == 0:
        assignDefaultTicks()
    for tickNo, target in tickTargetMap.items():
        if not isinstance(target, basestring):
            if len(target) == 1:
                _moose.useClock(tickNo, target[0], 'process')
            elif len(target) == 2:
                _moose.useClock(tickNo, target[0], target[1])
        else:
            _moose.useClock(tickNo, target, 'process')
Beispiel #3
0
def resetSim(simpaths, simdt, plotdt, simmethod='hsolve'):
    """ For each of the MOOSE paths in simpaths, this sets the clocks and finally resets MOOSE.
    If simmethod=='hsolve', it sets up hsolve-s for each Neuron under simpaths, and clocks for hsolve-s too. """
    print 'Solver:', simmethod
    _moose.setClock(INITCLOCK, simdt)
    _moose.setClock(ELECCLOCK, simdt) # The hsolve and ee methods use clock 1
    _moose.setClock(CHANCLOCK, simdt) # hsolve uses clock 2 for mg_block, nmdachan and others.
    _moose.setClock(POOLCLOCK, simdt) # Ca/ion pools & funcs use clock 3
    _moose.setClock(STIMCLOCK, simdt) # Ca/ion pools & funcs use clock 3
    _moose.setClock(PLOTCLOCK, plotdt) # for tables
    for simpath in simpaths:
        ## User can connect [qty]Out of an element to input of Table or
        ## requestOut of Table to get[qty] of the element.
        ## Scheduling the Table to a clock tick, will call process() of the Table
        ## which will send a requestOut and overwrite any value set by input(),
        ## thus adding garbage value to the vector. Hence schedule only if
        ## input message is not connected to the Table.
        for table in _moose.wildcardFind(simpath+'/##[TYPE=Table]'):
            if len(table.neighbors['input']) == 0:
                _moose.useClock(PLOTCLOCK, table.path, 'process')
        _moose.useClock(ELECCLOCK, simpath+'/##[TYPE=PulseGen]', 'process')
        _moose.useClock(STIMCLOCK, simpath+'/##[TYPE=DiffAmp]', 'process')
        _moose.useClock(STIMCLOCK, simpath+'/##[TYPE=VClamp]', 'process')
        _moose.useClock(STIMCLOCK, simpath+'/##[TYPE=PIDController]', 'process')
        _moose.useClock(STIMCLOCK, simpath+'/##[TYPE=RC]', 'process')
        _moose.useClock(STIMCLOCK, simpath+'/##[TYPE=TimeTable]', 'process')
        _moose.useClock(ELECCLOCK, simpath+'/##[TYPE=LeakyIaF]', 'process')
        _moose.useClock(ELECCLOCK, simpath+'/##[TYPE=IntFire]', 'process')
        _moose.useClock(ELECCLOCK, simpath+'/##[TYPE=IzhikevichNrn]', 'process')
        _moose.useClock(ELECCLOCK, simpath+'/##[TYPE=SpikeGen]', 'process')
        _moose.useClock(ELECCLOCK, simpath+'/##[TYPE=Interpol]', 'process')
        _moose.useClock(ELECCLOCK, simpath+'/##[TYPE=Interpol2D]', 'process')
        _moose.useClock(CHANCLOCK, simpath+'/##[TYPE=HHChannel2D]', 'process')
        _moose.useClock(CHANCLOCK, simpath+'/##[TYPE=SynChan]', 'process')
        ## If simmethod is not hsolve, set clocks for the biophysics,
        ## else just put a clock on the hsolve:
        ## hsolve takes care of the clocks for the biophysics
        if 'hsolve' not in simmethod.lower():
            print 'Using exp euler'
            _moose.useClock(INITCLOCK, simpath+'/##[TYPE=Compartment]', 'init')
            _moose.useClock(ELECCLOCK, simpath+'/##[TYPE=Compartment]', 'process')
            _moose.useClock(CHANCLOCK, simpath+'/##[TYPE=HHChannel]', 'process')
            _moose.useClock(POOLCLOCK, simpath+'/##[TYPE=CaConc]', 'process')
            _moose.useClock(POOLCLOCK, simpath+'/##[TYPE=Func]', 'process')
        else: # use hsolve, one hsolve for each Neuron
            print 'Using hsolve'
            element = _moose.Neutral(simpath)
            for childid in element.children: 
                childobj = _moose.Neutral(childid)
                classname = childobj.className
                if classname in ['Neuron']:
                    neuronpath = childobj.path
                    h = _moose.HSolve( neuronpath+'/solve' )
                    h.dt = simdt
                    h.target = neuronpath
                    _moose.useClock(INITCLOCK, h.path, 'process')
    _moose.reinit()
Beispiel #4
0
def assignDefaultTicks(modelRoot='/model', dataRoot='/data', solver='hsolve'):
    print 'assignDefaultTicks'
    if isinstance(modelRoot, _moose.melement) or isinstance(modelRoot, _moose.vec):
        modelRoot = modelRoot.path
    if isinstance(dataRoot, _moose.melement) or isinstance(dataRoot, _moose.vec):
        dataRoot = dataRoot.path
    if solver != 'hsolve' or len(_moose.wildcardFind('%s/##[ISA=HSolve]' % (modelRoot))) == 0:
        _moose.useClock(0, '%s/##[ISA=Compartment]' % (modelRoot), 'init')
        _moose.useClock(1, '%s/##[ISA=Compartment]'  % (modelRoot), 'process')
        _moose.useClock(2, '%s/##[ISA=HHChannel]'  % (modelRoot), 'process')
        # _moose.useClock(2, '%s/##[ISA=ChanBase]'  % (modelRoot), 'process')
    _moose.useClock(0, '%s/##[ISA=IzhikevichNrn]' % (modelRoot), 'process')
    _moose.useClock(0, '%s/##[ISA=GapJunction]' % (modelRoot), 'process')
    _moose.useClock(0, '%s/##[ISA=HSolve]'  % (modelRoot), 'process')
    _moose.useClock(1, '%s/##[ISA=LeakyIaF]'  % (modelRoot), 'process')
    _moose.useClock(1, '%s/##[ISA=IntFire]'  % (modelRoot), 'process')
    _moose.useClock(1, '%s/##[ISA=SpikeGen]'  % (modelRoot), 'process')
    _moose.useClock(1, '%s/##[ISA=PulseGen]'  % (modelRoot), 'process')
    _moose.useClock(1, '%s/##[ISA=StimulusTable]'  % (modelRoot), 'process')
    _moose.useClock(1, '%s/##[ISA=TimeTable]'  % (modelRoot), 'process')
    _moose.useClock(2, '%s/##[ISA=HHChannel2D]'  % (modelRoot), 'process')
    _moose.useClock(2, '%s/##[ISA=SynChan]'  % (modelRoot), 'process')
    _moose.useClock(2, '%s/##[ISA=MgBlock]'  % (modelRoot), 'process')
    _moose.useClock(3, '%s/##[ISA=CaConc]'  % (modelRoot), 'process')
    _moose.useClock(3, '%s/##[ISA=Func]' % (modelRoot), 'process')
    # The voltage clamp circuit depends critically on the dt used for
    # computing soma Vm and need to be on a clock with dt=elecdt.
    _moose.useClock(0, '%s/##[ISA=DiffAmp]'  % (modelRoot), 'process') 
    _moose.useClock(0, '%s/##[ISA=VClamp]' % (modelRoot), 'process')
    _moose.useClock(0, '%s/##[ISA=PIDController]' % (modelRoot), 'process')
    _moose.useClock(0, '%s/##[ISA=RC]' % (modelRoot), 'process')
    # Special case for kinetics models
    kinetics = _moose.wildcardFind('%s/##[FIELD(name)=kinetics]' % modelRoot)
    if len(kinetics) > 0:
        # Do nothing for kinetics models - until multiple scheduling issue is fixed.
        pass
        # _moose.useClock(4, '%s/##[ISA!=PoolBase]' % (kinetics[0].path), 'process')
        # _moose.useClock(5, '%s/##[ISA==PoolBase]' % (kinetics[0].path), 'process')
        # _moose.useClock(8, '%s/##[ISA=Table]' % (dataRoot), 'process')
    else:
        # input() function is called in Table. process() which gets
        # called at each timestep. When a message is connected
        # explicitly to input() dest field, it is driven by the sender
        # and process() adds garbage value to the vector. Hence not to
        # be scheduled.
        for tab in _moose.wildcardFind('%s/##[ISA=Table]' % (dataRoot)):
            if len(tab.neighbors['input']) == 0:
                _moose.useClock(9, tab.path, 'process')
Beispiel #5
0
def resetSim(simpaths, simdt, plotdt, simmethod='hsolve'):
    """ For each of the MOOSE paths in simpaths, this sets the clocks and finally resets MOOSE.
    If simmethod=='hsolve', it sets up hsolve-s for each Neuron under simpaths, and clocks for hsolve-s too. """
    print 'Solver:', simmethod
    _moose.setClock(INITCLOCK, simdt)
    _moose.setClock(ELECCLOCK, simdt)  # The hsolve and ee methods use clock 1
    _moose.setClock(
        CHANCLOCK,
        simdt)  # hsolve uses clock 2 for mg_block, nmdachan and others.
    _moose.setClock(POOLCLOCK, simdt)  # Ca/ion pools & funcs use clock 3
    _moose.setClock(STIMCLOCK, simdt)  # Ca/ion pools & funcs use clock 3
    _moose.setClock(PLOTCLOCK, plotdt)  # for tables
    for simpath in simpaths:
        ## User can connect [qty]Out of an element to input of Table or
        ## requestOut of Table to get[qty] of the element.
        ## Scheduling the Table to a clock tick, will call process() of the Table
        ## which will send a requestOut and overwrite any value set by input(),
        ## thus adding garbage value to the vector. Hence schedule only if
        ## input message is not connected to the Table.
        for table in _moose.wildcardFind(simpath + '/##[TYPE=Table]'):
            if len(table.neighbors['input']) == 0:
                _moose.useClock(PLOTCLOCK, table.path, 'process')
        _moose.useClock(ELECCLOCK, simpath + '/##[TYPE=PulseGen]', 'process')
        _moose.useClock(STIMCLOCK, simpath + '/##[TYPE=DiffAmp]', 'process')
        _moose.useClock(STIMCLOCK, simpath + '/##[TYPE=VClamp]', 'process')
        _moose.useClock(STIMCLOCK, simpath + '/##[TYPE=PIDController]',
                        'process')
        _moose.useClock(STIMCLOCK, simpath + '/##[TYPE=RC]', 'process')
        _moose.useClock(STIMCLOCK, simpath + '/##[TYPE=TimeTable]', 'process')
        _moose.useClock(ELECCLOCK, simpath + '/##[TYPE=LeakyIaF]', 'process')
        _moose.useClock(ELECCLOCK, simpath + '/##[TYPE=IntFire]', 'process')
        _moose.useClock(ELECCLOCK, simpath + '/##[TYPE=IzhikevichNrn]',
                        'process')
        _moose.useClock(ELECCLOCK, simpath + '/##[TYPE=SpikeGen]', 'process')
        _moose.useClock(ELECCLOCK, simpath + '/##[TYPE=Interpol]', 'process')
        _moose.useClock(ELECCLOCK, simpath + '/##[TYPE=Interpol2D]', 'process')
        _moose.useClock(CHANCLOCK, simpath + '/##[TYPE=HHChannel2D]',
                        'process')
        _moose.useClock(CHANCLOCK, simpath + '/##[TYPE=SynChan]', 'process')
        ## If simmethod is not hsolve, set clocks for the biophysics,
        ## else just put a clock on the hsolve:
        ## hsolve takes care of the clocks for the biophysics
        if 'hsolve' not in simmethod.lower():
            print 'Using exp euler'
            _moose.useClock(INITCLOCK, simpath + '/##[TYPE=Compartment]',
                            'init')
            _moose.useClock(ELECCLOCK, simpath + '/##[TYPE=Compartment]',
                            'process')
            _moose.useClock(CHANCLOCK, simpath + '/##[TYPE=HHChannel]',
                            'process')
            _moose.useClock(POOLCLOCK, simpath + '/##[TYPE=CaConc]', 'process')
            _moose.useClock(POOLCLOCK, simpath + '/##[TYPE=Func]', 'process')
        else:  # use hsolve, one hsolve for each Neuron
            print 'Using hsolve'
            element = _moose.Neutral(simpath)
            for childid in element.children:
                childobj = _moose.Neutral(childid)
                classname = childobj.className
                if classname in ['Neuron']:
                    neuronpath = childobj.path
                    h = _moose.HSolve(neuronpath + '/solve')
                    h.dt = simdt
                    h.target = neuronpath
                    _moose.useClock(INITCLOCK, h.path, 'process')
    _moose.reinit()
Beispiel #6
0
def assignDefaultTicks(modelRoot='/model', dataRoot='/data', solver='hsolve'):
    if isinstance(modelRoot, _moose.melement) or isinstance(
            modelRoot, _moose.vec):
        modelRoot = modelRoot.path
    if isinstance(dataRoot, _moose.melement) or isinstance(
            dataRoot, _moose.vec):
        dataRoot = dataRoot.path
    if solver != 'hsolve' or len(
            _moose.wildcardFind('%s/##[ISA=HSolve]' % (modelRoot))) == 0:
        _moose.useClock(0, '%s/##[ISA=Compartment]' % (modelRoot), 'init')
        _moose.useClock(1, '%s/##[ISA=Compartment]' % (modelRoot), 'process')
        _moose.useClock(2, '%s/##[ISA=HHChannel]' % (modelRoot), 'process')
        # _moose.useClock(2, '%s/##[ISA=ChanBase]'  % (modelRoot), 'process')
    _moose.useClock(0, '%s/##[ISA=IzhikevichNrn]' % (modelRoot), 'process')
    _moose.useClock(0, '%s/##[ISA=GapJunction]' % (modelRoot), 'process')
    _moose.useClock(0, '%s/##[ISA=HSolve]' % (modelRoot), 'process')
    _moose.useClock(1, '%s/##[ISA=LeakyIaF]' % (modelRoot), 'process')
    _moose.useClock(1, '%s/##[ISA=IntFire]' % (modelRoot), 'process')
    _moose.useClock(1, '%s/##[ISA=SpikeGen]' % (modelRoot), 'process')
    _moose.useClock(1, '%s/##[ISA=PulseGen]' % (modelRoot), 'process')
    _moose.useClock(1, '%s/##[ISA=StimulusTable]' % (modelRoot), 'process')
    _moose.useClock(1, '%s/##[ISA=TimeTable]' % (modelRoot), 'process')
    _moose.useClock(2, '%s/##[ISA=HHChannel2D]' % (modelRoot), 'process')
    _moose.useClock(2, '%s/##[ISA=SynChan]' % (modelRoot), 'process')
    _moose.useClock(2, '%s/##[ISA=MgBlock]' % (modelRoot), 'process')
    _moose.useClock(3, '%s/##[ISA=CaConc]' % (modelRoot), 'process')
    _moose.useClock(3, '%s/##[ISA=Func]' % (modelRoot), 'process')
    # The voltage clamp circuit depends critically on the dt used for
    # computing soma Vm and need to be on a clock with dt=elecdt.
    _moose.useClock(0, '%s/##[ISA=DiffAmp]' % (modelRoot), 'process')
    _moose.useClock(0, '%s/##[ISA=VClamp]' % (modelRoot), 'process')
    _moose.useClock(0, '%s/##[ISA=PIDController]' % (modelRoot), 'process')
    _moose.useClock(0, '%s/##[ISA=RC]' % (modelRoot), 'process')
    # Special case for kinetics models
    kinetics = _moose.wildcardFind('%s/##[FIELD(name)=kinetics]' % modelRoot)
    if len(kinetics) > 0:
        # Do nothing for kinetics models - until multiple scheduling issue is fixed.
        _moose.useClock(4, '%s/##[ISA!=PoolBase]' % (kinetics[0].path),
                        'process')
        _moose.useClock(5, '%s/##[ISA==PoolBase]' % (kinetics[0].path),
                        'process')
        _moose.useClock(18, '%s/##[ISA=Table2]' % (dataRoot), 'process')
    else:
        # input() function is called in Table. process() which gets
        # called at each timestep. When a message is connected
        # explicitly to input() dest field, it is driven by the sender
        # and process() adds garbage value to the vector. Hence not to
        # be scheduled.
        for tab in _moose.wildcardFind('%s/##[ISA=Table]' % (dataRoot)):
            if len(tab.neighbors['input']) == 0:
                _moose.useClock(9, tab.path, 'process')
Beispiel #7
0
def resetSim(simpaths, simdt, plotdt, simmethod="hsolve"):
    """ For each of the MOOSE paths in simpaths, this sets the clocks and finally resets MOOSE.
    If simmethod=='hsolve', it sets up hsolve-s for each Neuron under simpaths, and clocks for hsolve-s too. """
    print "Solver:", simmethod
    _moose.setClock(INITCLOCK, simdt)
    _moose.setClock(ELECCLOCK, simdt)  # The hsolve and ee methods use clock 1
    _moose.setClock(CHANCLOCK, simdt)  # hsolve uses clock 2 for mg_block, nmdachan and others.
    _moose.setClock(POOLCLOCK, simdt)  # Ca/ion pools use clock 3
    _moose.setClock(STIMCLOCK, simdt)  # Ca/ion pools use clock 3
    _moose.setClock(PLOTCLOCK, plotdt)  # for tables
    for simpath in simpaths:
        _moose.useClock(PLOTCLOCK, simpath + "/##[TYPE=Table]", "process")
        _moose.useClock(ELECCLOCK, simpath + "/##[TYPE=PulseGen]", "process")
        _moose.useClock(STIMCLOCK, simpath + "/##[TYPE=DiffAmp]", "process")
        _moose.useClock(STIMCLOCK, simpath + "/##[TYPE=VClamp]", "process")
        _moose.useClock(STIMCLOCK, simpath + "/##[TYPE=PIDController]", "process")
        _moose.useClock(STIMCLOCK, simpath + "/##[TYPE=RC]", "process")
        _moose.useClock(ELECCLOCK, simpath + "/##[TYPE=LeakyIaF]", "process")
        _moose.useClock(ELECCLOCK, simpath + "/##[TYPE=IntFire]", "process")
        _moose.useClock(CHANCLOCK, simpath + "/##[TYPE=HHChannel2D]", "process")
        _moose.useClock(CHANCLOCK, simpath + "/##[TYPE=SynChan]", "process")
        ## If simmethod is not hsolve, set clocks for the biophysics,
        ## else just put a clock on the hsolve:
        ## hsolve takes care of the clocks for the biophysics
        if "hsolve" not in simmethod.lower():
            print "Using exp euler"
            _moose.useClock(INITCLOCK, simpath + "/##[TYPE=Compartment]", "init")
            _moose.useClock(ELECCLOCK, simpath + "/##[TYPE=Compartment]", "process")
            _moose.useClock(CHANCLOCK, simpath + "/##[TYPE=HHChannel]", "process")
            _moose.useClock(POOLCLOCK, simpath + "/##[TYPE=CaConc]", "process")
        else:  # use hsolve, one hsolve for each Neuron
            print "Using hsolve"
            element = _moose.Neutral(simpath)
            for childid in element.children:
                childobj = _moose.Neutral(childid)
                classname = childobj.class_
                if classname in ["Neuron"]:
                    neuronpath = childobj.path
                    h = _moose.HSolve(neuronpath + "/solve")
                    h.dt = simdt
                    h.target = neuronpath
                    _moose.useClock(INITCLOCK, h.path, "process")
    _moose.reinit()
Beispiel #8
0
def assignDefaultTicks(modelRoot="/model", dataRoot="/data"):
    _moose.useClock(0, "%s/##[ISA=Compartment]" % (modelRoot), "init")
    _moose.useClock(1, "%s/##[ISA=LeakyIaF]" % (modelRoot), "process")
    _moose.useClock(1, "%s/##[ISA=IntFire]" % (modelRoot), "process")
    _moose.useClock(1, "%s/##[ISA=Compartment]" % (modelRoot), "process")
    _moose.useClock(1, "%s/##[ISA=PulseGen]" % (modelRoot), "process")
    _moose.useClock(2, "%s/##[ISA=ChanBase]" % (modelRoot), "process")
    _moose.useClock(2, "%s/##[ISA=MgBlock]" % (modelRoot), "process")
    _moose.useClock(3, "%s/##[ISA=CaConc]" % (modelRoot), "process")
    _moose.useClock(7, "%s/##[ISA=DiffAmp]" % (modelRoot), "process")
    _moose.useClock(7, "%s/##[ISA=VClamp]" % (modelRoot), "process")
    _moose.useClock(7, "%s/##[ISA=PIDController]" % (modelRoot), "process")
    _moose.useClock(7, "%s/##[ISA=RC]" % (modelRoot), "process")
    # Special case for kinetics models
    kinetics = _moose.wildcardFind("%s/##[FIELD(name)=kinetics]" % modelRoot)
    if len(kinetics) > 0:
        _moose.useClock(4, "%s/##[ISA!=PoolBase]" % (kinetics[0].path), "process")
        _moose.useClock(5, "%s/##[ISA==PoolBase]" % (kinetics[0].path), "process")
        _moose.useClock(8, "%s/##[ISA=Table]" % (dataRoot), "process")
    else:
        _moose.useClock(9, "%s/##[ISA=Table]" % (dataRoot), "process")