예제 #1
0
    def __new__(cls, name, bases, dct):

        import nineml.abstraction_layer as al
        from nineml.abstraction_layer import flattening, writers, component_modifiers
        import nest

        # Extract Parameters Back out from Dict:
        nineml_model = dct["nineml_model"]
        synapse_components = dct["synapse_components"]

        # Flatten the model:
        assert isinstance(nineml_model, al.ComponentClass)
        if nineml_model.is_flat():
            flat_component = nineml_model
        else:
            flat_component = flattening.flatten(nineml_model, name)

        # Make the substitutions:
        flat_component.backsub_all()
        # flat_component.backsub_aliases()
        # flat_component.backsub_equations()

        # Close any open reduce ports:
        component_modifiers.ComponentModifier.close_all_reduce_ports(component=flat_component)

        flat_component.short_description = "Auto-generated 9ML neuron model for PyNN.nest"
        flat_component.long_description = "Auto-generated 9ML neuron model for PyNN.nest"

        # Close any open reduce ports:
        component_modifiers.ComponentModifier.close_all_reduce_ports(component=flat_component)

        # synapse ports:
        synapse_ports = []
        for syn in synapse_components:
            # get recv event ports
            # TODO: model namespace look
            # syn_component = nineml_model[syn.namespace]
            syn_component = nineml_model.subnodes[syn.namespace]
            recv_event_ports = list(syn_component.query.event_recv_ports)
            # check there's only one
            if len(recv_event_ports) != 1:
                raise ValueError, "A synapse component has multiple recv ports.  Cannot dis-ambiguate"
            synapse_ports.append(syn.namespace + "_" + recv_event_ports[0].name)

        # New:
        dct["combined_model"] = flat_component
        # TODO: Override this with user layer
        # default_values = ModelToSingleComponentReducer.flatten_namespace_dict( parameters )
        dct["default_parameters"] = dict((p.name, 1.0) for p in flat_component.parameters)
        dct["default_initial_values"] = dict((s.name, 0.0) for s in flat_component.state_variables)
        dct["synapse_types"] = [syn.namespace for syn in synapse_components]
        dct["standard_receptor_type"] = dct["synapse_types"] == ("excitatory", "inhibitory")
        dct["injectable"] = True  # need to determine this. How??
        dct["conductance_based"] = True  # how to determine this??
        dct["model_name"] = name
        dct["nest_model"] = name

        # Recording from bindings:
        dct["recordable"] = [port.name for port in flat_component.analog_ports] + ["spikes", "regime"]
        # TODO bindings -> alias and support recording of them in nest template
        # + [binding.name for binding in flat_component.bindings]

        dct["weight_variables"] = dict(
            [(syn.namespace, syn.namespace + "_" + syn.weight_connector) for syn in synapse_components]
        )

        logger.debug("Creating class '%s' with bases %s and dictionary %s" % (name, bases, dct))

        # TODO: UL configuration of initial regime.
        initial_regime = flat_component.regimes_map.keys()[0]

        from nestbuilder import NestFileBuilder

        nfb = NestFileBuilder(
            nest_classname=name,
            component=flat_component,
            synapse_ports=synapse_ports,
            initial_regime=initial_regime,
            initial_values=dct["default_initial_values"],
            default_values=dct["default_parameters"],
        )
        nfb.compile_files()
        nest.Install("mymodule")

        return type.__new__(cls, name, bases, dct)
예제 #2
0
comp_data = TestableComponent('nestequivalent_iaf_cond_exp')

# Build the component:
component = comp_data()
component = flatten(component)
component.backsub_all()
ComponentModifier.close_all_reduce_ports(component=component)

# Copy the descriptive strings:
component.short_description = comp_data.metadata.short_description
component.long_description = comp_data.metadata.long_description

# Get the initial regime. If this component comes from an flattened component,
# then we should look up the new regime from the locations in the old
# components, hence the nedd for this code:
initial_regime = comp_data.metadata.initial_regime
if component.was_flattened():
    new_regime = component.flattener.get_new_regime(initial_regime)
    initial_regime = new_regime.name

from nestbuilder import NestFileBuilder
nfb = NestFileBuilder(
    nest_classname=comp_data.metadata.nest_classname,
    component=component,
    synapse_ports=comp_data.metadata.synapse_ports,
    initial_regime=initial_regime,  # new_regime.name,
    initial_values=comp_data.metadata.initial_values,
    default_values=comp_data.metadata.parameters,
)
nfb.compile_files()
예제 #3
0
    def __new__(cls, name, bases, dct):

        import nineml.abstraction_layer as al
        from nineml.abstraction_layer import flattening, writers, component_modifiers
        import nest

        #Extract Parameters Back out from Dict:
        nineml_model = dct['nineml_model']
        synapse_components = dct['synapse_components']

        # Flatten the model:
        assert isinstance(nineml_model, al.ComponentClass)
        if nineml_model.is_flat():
            flat_component = nineml_model
        else:
            flat_component = flattening.flatten(nineml_model, name)

        # Make the substitutions:
        flat_component.backsub_all()
        #flat_component.backsub_aliases()
        #flat_component.backsub_equations()

        # Close any open reduce ports:
        component_modifiers.ComponentModifier.close_all_reduce_ports(
            component=flat_component)

        flat_component.short_description = "Auto-generated 9ML neuron model for PyNN.nest"
        flat_component.long_description = "Auto-generated 9ML neuron model for PyNN.nest"

        # Close any open reduce ports:
        component_modifiers.ComponentModifier.close_all_reduce_ports(
            component=flat_component)

        # synapse ports:
        synapse_ports = []
        for syn in synapse_components:
            # get recv event ports
            # TODO: model namespace look
            #syn_component = nineml_model[syn.namespace]
            syn_component = nineml_model.subnodes[syn.namespace]
            recv_event_ports = list(syn_component.query.event_recv_ports)
            # check there's only one
            if len(recv_event_ports) != 1:
                raise ValueError(
                    "A synapse component has multiple recv ports.  Cannot dis-ambiguate"
                )
            synapse_ports.append(syn.namespace + '_' +
                                 recv_event_ports[0].name)

        # New:
        dct["combined_model"] = flat_component
        # TODO: Override this with user layer
        #default_values = ModelToSingleComponentReducer.flatten_namespace_dict( parameters )
        dct["default_parameters"] = dict(
            (p.name, 1.0) for p in flat_component.parameters)
        dct["default_initial_values"] = dict(
            (s.name, 0.0) for s in flat_component.state_variables)
        dct["synapse_types"] = [syn.namespace for syn in synapse_components]
        dct["standard_receptor_type"] = (dct["synapse_types"] == (
            'excitatory', 'inhibitory'))
        dct["injectable"] = True  # need to determine this. How??
        dct["conductance_based"] = True  # how to determine this??
        dct["model_name"] = name
        dct["nest_model"] = name

        # Recording from bindings:
        dct["recordable"] = [
            port.name for port in flat_component.analog_ports
        ] + ['spikes', 'regime']
        # TODO bindings -> alias and support recording of them in nest template
        #+ [binding.name for binding in flat_component.bindings]

        dct["weight_variables"] = dict([
            (syn.namespace, syn.namespace + '_' + syn.weight_connector)
            for syn in synapse_components
        ])

        logger.debug("Creating class '%s' with bases %s and dictionary %s" %
                     (name, bases, dct))

        # TODO: UL configuration of initial regime.
        initial_regime = flat_component.regimes_map.keys()[0]

        from nestbuilder import NestFileBuilder
        nfb = NestFileBuilder(
            nest_classname=name,
            component=flat_component,
            synapse_ports=synapse_ports,
            initial_regime=initial_regime,
            initial_values=dct["default_initial_values"],
            default_values=dct["default_parameters"],
        )
        nfb.compile_files()
        nest.Install('mymodule')

        return type.__new__(cls, name, bases, dct)
예제 #4
0
    'iaf.vrest': -65.0,
    'iaf.vreset': -65.0,
    'iaf.vthresh': -50.0,
    'cobaExcit.tau': 2.0,
    'cobaInhib.tau': 5.0,
    'cobaExcit.vrev': 0.0,
    'cobaInhib.vrev': -70.0,
    'cobaExcit.q': 2.0,
    'cobaInhib.q': 2.0,
    'iaf.ISyn':0.0,

    'cobaExcit.gl': 0.0,
}


default_values = ComponentFlattener.flatten_namespace_dict( parameters )



from nestbuilder import NestFileBuilder
nfb = NestFileBuilder(  nest_classname = nest_classname, 
                        component = iaf_cond_exp_9ML_reduced, 
                        synapse_ports = synapse_ports,
                        initial_regime =  initial_regime,
                        initial_values = initial_values,
                        default_values = default_values,
                        )
nfb.compile_files()


예제 #5
0
initial_values = {'V_m': -70.0, 'g_ex': 0.0, 'g_in': 0.0, 't_spike': 0.0}

default_values = {
    'tau_syn_ex': 1.5,
    'tau_syn_in': 10.0,
    'E_ex': 0.0,
    'E_in': -80.0,
    'Isyn': 0.0,
    'C_m': 1.0,
    'g_L': 10.0,
    'q_ex': 2.0,
    'q_in': 2.0,
    't_ref': 5.0,
    'V_th': -55.0,
    'E_L': -70.0,
    'V_reset': -70.0
}

# CG specific stuff which needs to be determined somehow
nest_classname = "iaf_cond_exp_9ml"

from nestbuilder import NestFileBuilder
nfb = NestFileBuilder(nest_classname=nest_classname,
                      component=iaf_cond_exp_9ML,
                      synapse_ports=synapse_ports,
                      initial_regime=initial_regime,
                      initial_values=initial_values,
                      default_values=default_values)
nfb.compile_files()