Exemple #1
0
    def __init__(self, name, parameters=(), aliases=(), constants=()):
        self._name = validate_identifier(name)
        BaseALObject.__init__(self)
        DocumentLevelObject.__init__(self)
        ContainerObject.__init__(self)

        # Caches the dimension resolver so that it can be reused in subsequent
        # calls
        self._dimension_resolver = None

        # Turn any strings in the parameter list into Parameters:
        param_types = (basestring, Parameter)
        param_td = filter_discrete_types(parameters, param_types)
        params_from_strings = [Parameter(s) for s in param_td[basestring]]
        parameters = param_td[Parameter] + params_from_strings

        # Load the aliases as objects or strings:
        aliases = normalise_parameter_as_list(aliases)
        alias_td = filter_discrete_types(aliases, (basestring, Alias))
        aliases_from_strs = [Alias.from_str(o) for o in alias_td[basestring]]
        aliases = alias_td[Alias] + aliases_from_strs

        constants = normalise_parameter_as_list(constants)

        self.add(*parameters)
        self.add(*aliases)
        self.add(*constants)
Exemple #2
0
 def __init__(self, name, w, r):
     AnnotatedNineMLObject.__init__(self)
     self.name = name
     DocumentLevelObject.__init__(self)
     self.name = name
     self.w = w
     self.r = r
Exemple #3
0
 def __init__(self, name, source, destination, source_port,
              destination_port, delay, connectivity=None,
              connection_rule_properties=None,
              connectivity_class=Connectivity):
     self._name = validate_identifier(name)
     BaseULObject.__init__(self)
     DocumentLevelObject.__init__(self)
     self._source = source
     self._destination = destination
     self._source_port = source_port
     self._destination_port = destination_port
     if connectivity is not None:
         assert isinstance(connectivity, BaseConnectivity)
         if connection_rule_properties is not None:
             raise NineMLUsageError(
                 "Cannot provide both connectivty and "
                 "connection_rule_properties as kwargs to projection class")
         self._connectivity = connectivity
     else:
         connectivity = connectivity_class(
             connection_rule_properties, source.size, destination.size)
     self._connectivity = connectivity
     self._delay = delay
     if isinstance(source_port, Port):
         self._check_ports(source_port, destination_port)
Exemple #4
0
 def __init__(self, name, dimension, power, offset=0.0):
     self._name = validate_identifier(name)
     AnnotatedNineMLObject.__init__(self)
     DocumentLevelObject.__init__(self)
     assert isinstance(dimension, Dimension)
     self._dimension = dimension
     self._power = power
     self._offset = offset
Exemple #5
0
 def __init__(self, name, a, bs, c, d, g):
     ContainerObject.__init__(self)
     self.name = name
     DocumentLevelObject.__init__(self)
     self.a = a
     self.add(*bs)
     self.c = c
     self.d = d
     self.g = g
Exemple #6
0
 def __init__(self, name, size, dynamics_properties):
     self._name = validate_identifier(name)
     BaseULObject.__init__(self)
     DocumentLevelObject.__init__(self)
     self.size = size
     if not dynamics_properties.component_class.is_flat:
         dynamics_properties = dynamics_properties.flatten(
             name + '_flat_dyn')
     self._dynamics_properties = dynamics_properties
Exemple #7
0
 def __init__(self, name, dimensions=None, **kwargs):
     self._name = validate_identifier(name)
     AnnotatedNineMLObject.__init__(self)
     DocumentLevelObject.__init__(self)
     if dimensions is not None:
         assert len(dimensions) == 7, "Incorrect dimension length"
         self._dims = tuple(dimensions)
     else:
         self._dims = tuple(kwargs.pop(d, 0)
                            for d in self.dimension_symbols)
     assert not len(kwargs), "Unrecognised kwargs ({})".format(kwargs)
Exemple #8
0
 def __init__(self, name, dynamics_properties, synapse_propertiess=[],
              connection_property_sets=[]):
     # Initiate inherited base classes
     BaseULObject.__init__(self)
     DocumentLevelObject.__init__(self)
     ContainerObject.__init__(self)
     WithSynapsesProperties.__init__(self, name, dynamics_properties,
                                     synapse_propertiess,
                                     connection_property_sets)
     # Create references to all dynamics member variables so that inherited
     # MultiDynamicsProperties properties and methods can find them.
     self._annotations = dynamics_properties._annotations
     self._sub_components = dynamics_properties._sub_components
Exemple #9
0
 def __init__(self, name, dynamics_properties, synapses_properties=[],
              connection_property_sets=[]):
     WithSynapsesProperties.__init__(self, name, dynamics_properties,
                                     synapses_properties,
                                     connection_property_sets)
     # Initiate inherited base classes
     BaseULObject.__init__(self)
     DocumentLevelObject.__init__(self, dynamics_properties.document)
     ContainerObject.__init__(self)
     # Create references to all dynamics member variables so that inherited
     # DynamicsProperties properties and methods can find them.
     self._annotations = dynamics_properties._annotations
     self._properties = dynamics_properties._properties
     self._initial_values = dynamics_properties._initial_values
     self._initial_regime = dynamics_properties._initial_regime
Exemple #10
0
 def __init__(self, name, pre, post, response, delay, connectivity=None,
              connection_rule_properties=None,
              plasticity=None, port_connections=None,
              analog_port_connections=None, event_port_connections=None,
              connectivity_class=Connectivity, **kwargs):
     """
     Create a new projection.
     """
     self._name = validate_identifier(name)
     BaseULObject.__init__(self)
     ContainerObject.__init__(self)
     DocumentLevelObject.__init__(self)
     assert isinstance(name, basestring)
     assert isinstance(delay, Quantity)
     assert isinstance(pre, (Population, Selection))
     assert isinstance(post, (Population, Selection))
     assert isinstance(response, DynamicsProperties)
     assert isinstance(plasticity, (DynamicsProperties, type(None)))
     self._pre = pre
     self._post = post
     self._response = response
     self._plasticity = plasticity
     if connectivity is not None:
         assert isinstance(connectivity, Connectivity)
         if connection_rule_properties is not None:
             raise NineMLUsageError(
                 "Cannot provide both connectivty and "
                 "connection_rule_properties as kwargs to projection class")
         self._connectivity = connectivity
     else:
         self._connectivity = connectivity_class(
             connection_rule_properties, pre.size, post.size, **kwargs)
     self._delay = delay
     if port_connections is None:
         port_connections = []
     if analog_port_connections is None:
         analog_port_connections = []
     if event_port_connections is None:
         event_port_connections = []
     for port_connection in chain(port_connections,
                                  event_port_connections,
                                  analog_port_connections):
         if isinstance(port_connection, tuple):
             port_connection = BasePortConnection.from_tuple(
                 port_connection, self)
         port_connection.bind(self, to_roles=True)
         self.add(port_connection)
Exemple #11
0
 def __init__(self, name, dynamics, synapses=[],
              connection_parameter_sets=[]):
     WithSynapses.__init__(self, name, dynamics, synapses,
                           connection_parameter_sets)
     BaseALObject.__init__(self)
     DocumentLevelObject.__init__(self, dynamics.document)
     ContainerObject.__init__(self)
     # Create references to all dynamics member variables so that inherited
     # Dynamics properties and methods can find them.
     self._annotations = dynamics._annotations
     self._sub_components = dynamics._sub_components
     self._analog_send_ports = dynamics._analog_send_ports
     self._analog_receive_ports = dynamics._analog_receive_ports
     self._analog_reduce_ports = dynamics._analog_reduce_ports
     self._event_send_ports = dynamics._event_send_ports
     self._event_receive_ports = dynamics._event_receive_ports
     self._analog_port_connections = dynamics._analog_port_connections
     self._event_port_connections = dynamics._event_port_connections
Exemple #12
0
 def __init__(self, name, definition, properties={}):
     """
     Create a new component_class with the given name, definition and
     properties, or create a prototype to another component_class that will
     be resolved later.
     """
     self._name = validate_identifier(name)
     BaseULObject.__init__(self)
     DocumentLevelObject.__init__(self)
     ContainerObject.__init__(self)
     if isinstance(definition, basestring):
         if "#" in definition:
             defn_url, name = definition.split("#")
         else:
             raise NineMLUsageError(
                 "Must provide name of class using '#' syntax when "
                 "providing definition as url string ('{}')"
                 .format(definition))
         definition = Definition(
             name=name,
             document=None,
             url=defn_url)
     elif (isinstance(definition, ComponentClass) or
           definition.nineml_type in ('Dynamics', 'MultiDynamics')):
         definition = Definition(definition)
     elif (isinstance(definition, Component) or
           definition.nineml_type in ('DynamicsProperties',
                                      'MultiDynamicsProperties')):
         definition = Prototype(definition)
     elif definition.nineml_type not in ('Definition', 'Prototype'):
         raise ValueError("'definition' must be either a 'Definition', "
                          "'Prototype' element or url pointing to a "
                          "dynamics class")
     self._definition = definition
     if isinstance(properties, dict):
         properties = (Property(name, qty)
                       for name, qty in properties.items())
     self.add(*properties)
     self.check_properties()
Exemple #13
0
 def __init__(self, name, u, v):
     AnnotatedNineMLObject.__init__(self)
     self._name = validate_identifier(name)
     DocumentLevelObject.__init__(self)
     self.u = u
     self.v = v
Exemple #14
0
 def __init__(self, name, x, y):
     AnnotatedNineMLObject.__init__(self)
     self._name = validate_identifier(name)
     DocumentLevelObject.__init__(self)
     self.x = x
     self.y = y
Exemple #15
0
 def __init__(self, name, operation, **kwargs):
     self._name = validate_identifier(name)
     BaseULObject.__init__(self, **kwargs)
     DocumentLevelObject.__init__(self)
     self._operation = operation
Exemple #16
0
 def __init__(self, branches=None):
     BaseAnnotations.__init__(self, branches=branches)
     DocumentLevelObject.__init__(self)