コード例 #1
0
ファイル: base.py プロジェクト: apdavison/lib9ML
    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)
コード例 #2
0
 def __init__(self, name, es, f, t):
     AnnotatedNineMLObject.__init__(self)
     ContainerObject.__init__(self)
     self.name = name
     self.add(*es)
     self.f = f
     self.t = t
コード例 #3
0
ファイル: base.py プロジェクト: apdavison/lib9ML
    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)
コード例 #4
0
ファイル: base_test.py プロジェクト: apdavison/lib9ML
 def __init__(self, name, es, f, t):
     AnnotatedNineMLObject.__init__(self)
     ContainerObject.__init__(self)
     self.name = name
     self.add(*es)
     self.f = f
     self.t = t
コード例 #5
0
ファイル: component.py プロジェクト: apdavison/lib9ML
 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()
コード例 #6
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
コード例 #7
0
ファイル: base_test.py プロジェクト: apdavison/lib9ML
 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
コード例 #8
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)
コード例 #9
0
 def __init__(self, name, populations=[], projections=[], selections=[]):
     # better would be *items, then sort by type, taking the name from the
     # item
     self._name = validate_identifier(name)
     BaseULObject.__init__(self)
     DocumentLevelObject.__init__(self)
     ContainerObject.__init__(self)
     self.add(*populations)
     self.add(*projections)
     self.add(*selections)
コード例 #10
0
    def __init__(self, *args, **kwargs):
        BaseALObject.__init__(self)
        ContainerObject.__init__(self)
        valid_kwargs = ('name', 'transitions', 'on_events', 'on_conditions',
                        'time_derivatives', 'aliases')
        for arg in kwargs:
            if arg not in valid_kwargs:
                err = 'Unexpected Arg: %s' % arg
                raise NineMLUsageError(err)

        name = kwargs.get('name', None)
        if name is None:
            self._name = 'default'
        else:
            self._name = validate_identifier(name)
            validate_identifier(self._name)

        # Get Time derivatives from args or kwargs
        kw_tds = normalise_parameter_as_list(
            kwargs.get('time_derivatives', None))
        time_derivatives = list(args) + kw_tds
        # Un-named arguments are time_derivatives:
        time_derivatives = normalise_parameter_as_list(time_derivatives)
        # time_derivatives.extend( args )
        td_types = (basestring, TimeDerivative)
        td_type_dict = filter_discrete_types(time_derivatives, td_types)
        td_from_str = [TimeDerivative.from_str(o)
                       for o in td_type_dict[basestring]]
        time_derivatives = td_type_dict[TimeDerivative] + td_from_str
        # Check for double definitions:
        td_dep_vars = [td.variable for td in time_derivatives]
        assert_no_duplicates(
            td_dep_vars,
            ("Multiple time derivatives found for the same state variable "
                 "in regime '{}' (found '{}')".format(
                     self.name,
                     "', '".join(td.variable for td in time_derivatives))))
        self.add(*time_derivatives)

        # We support passing in 'transitions', which is a list of both OnEvents
        # and OnConditions as well as separate on_conditions and on_events.
        transitions = normalise_parameter_as_list(
            kwargs.get('transitions', None))
        self.add(*transitions)
        on_conditions = normalise_parameter_as_list(
            kwargs.get('on_conditions', None))
        self.add(*on_conditions)
        on_events = normalise_parameter_as_list(
            kwargs.get('on_events', None))
        self.add(*on_events)

        # Add regime specific aliases
        aliases = normalise_parameter_as_list(kwargs.get('aliases', None))
        self.add(*aliases)
コード例 #11
0
 def __init__(self, branches=None):
     ContainerObject.__init__(self)
     if isinstance(branches, OrderedDefaultListDict):
         self._branches = branches
     else:
         self._branches = OrderedDefaultListDict()
         if branches is not None:
             for i, branch in enumerate(branches):
                 branch._abs_index = i
                 branch._rel_index = len(self._branches[(branch.name,
                                                         branch.ns)])
                 self._branches[(branch.name, branch.ns)].append(branch)
コード例 #12
0
ファイル: with_synapses.py プロジェクト: CNS-OIST/PyPe9
 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
コード例 #13
0
ファイル: with_synapses.py プロジェクト: CNS-OIST/PyPe9
 def __init__(self, name, dynamics_properties, port_connections=None,
              analog_port_connections=None, event_port_connections=None):
     super(SynapseProperties, self).__init__()
     ContainerObject.__init__(self)
     self._name = validate_identifier(name)
     self._dynamics_properties = dynamics_properties.clone()
     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_conn in chain(port_connections, analog_port_connections,
                            event_port_connections):
         self.add(port_conn.clone())
コード例 #14
0
ファイル: with_synapses.py プロジェクト: tclose/PyPe9
 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
コード例 #15
0
ファイル: with_synapses.py プロジェクト: nsk6999/pype9
 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
コード例 #16
0
ファイル: projection.py プロジェクト: apdavison/lib9ML
 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)
コード例 #17
0
ファイル: transitions.py プロジェクト: apdavison/lib9ML
    def __init__(self,
                 state_assignments=None,
                 output_events=None,
                 target_regime_name=None):
        """Abstract class representing a transition from one Regime to
        another.

        Transition objects are not created directly, but via the subclasses
        OnEvent and OnCondition.

        Parameters
        ----------
        state_assignments: list(StateAssignment)
            A list of the state-assignments performed
            when this transition occurs. Objects in this list are either
            `string` (e.g A = A+13) or StateAssignment objects.
        output_events: list(OutputEvent)
            A list of OutputEvent objects emitted when
            this transition occurs.
        target_regime_name: str | None
            The name of the regime to go into after this
            transition.  `None` implies staying in the same regime. This has
            to be specified as a string, not the object, because in general the
            |Regime| object is not yet constructed. This is automatically
            resolved by the Dynamics during construction.
        """
        BaseALObject.__init__(self)
        ContainerObject.__init__(self)

        # Load state-assignment objects as strings or StateAssignment objects
        state_assignments = state_assignments or []

        sa_types = (basestring, StateAssignment)
        sa_type_dict = filter_discrete_types(state_assignments, sa_types)
        sa_from_str = [
            StateAssignment.from_str(o) for o in sa_type_dict[basestring]
        ]

        self.add(*(sa_type_dict[StateAssignment] + sa_from_str))
        self.add(*normalise_parameter_as_list(output_events))

        self._target_regime_name = (validate_identifier(target_regime_name) if
                                    target_regime_name is not None else None)
        self._target_regime = None
        self._source_regime = None
コード例 #18
0
ファイル: with_synapses.py プロジェクト: tclose/PyPe9
 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
コード例 #19
0
ファイル: transitions.py プロジェクト: apdavison/lib9ML
    def __init__(self, state_assignments=None, output_events=None,
                 target_regime_name=None):
        """Abstract class representing a transition from one Regime to
        another.

        Transition objects are not created directly, but via the subclasses
        OnEvent and OnCondition.

        Parameters
        ----------
        state_assignments: list(StateAssignment)
            A list of the state-assignments performed
            when this transition occurs. Objects in this list are either
            `string` (e.g A = A+13) or StateAssignment objects.
        output_events: list(OutputEvent)
            A list of OutputEvent objects emitted when
            this transition occurs.
        target_regime_name: str | None
            The name of the regime to go into after this
            transition.  `None` implies staying in the same regime. This has
            to be specified as a string, not the object, because in general the
            |Regime| object is not yet constructed. This is automatically
            resolved by the Dynamics during construction.
        """
        BaseALObject.__init__(self)
        ContainerObject.__init__(self)

        # Load state-assignment objects as strings or StateAssignment objects
        state_assignments = state_assignments or []

        sa_types = (basestring, StateAssignment)
        sa_type_dict = filter_discrete_types(state_assignments, sa_types)
        sa_from_str = [StateAssignment.from_str(o)
                       for o in sa_type_dict[basestring]]

        self.add(*(sa_type_dict[StateAssignment] + sa_from_str))
        self.add(*normalise_parameter_as_list(output_events))

        self._target_regime_name = (
            validate_identifier(target_regime_name)
            if target_regime_name is not None else None)
        self._target_regime = None
        self._source_regime = None
コード例 #20
0
ファイル: with_synapses.py プロジェクト: nsk6999/pype9
 def __init__(self,
              name,
              dynamics_properties,
              port_connections=None,
              analog_port_connections=None,
              event_port_connections=None):
     super(SynapseProperties, self).__init__()
     ContainerObject.__init__(self)
     self._name = validate_identifier(name)
     self._dynamics_properties = dynamics_properties.clone()
     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_conn in chain(port_connections, analog_port_connections,
                            event_port_connections):
         self.add(port_conn.clone())
コード例 #21
0
ファイル: component.py プロジェクト: apdavison/lib9ML
 def elements(self, local=False):
     """
     Overrides the elements method in ContainerObject base class to allow
     for "local" kwarg to only iterate the members that are declared in
     this instance (i.e. not the prototype)
     """
     if local:
         return iter(self._properties.values())
     else:
         return ContainerObject.elements(self)
コード例 #22
0
ファイル: component.py プロジェクト: apdavison/lib9ML
 def elements(self, local=False):
     """
     Overrides the elements method in ContainerObject base class to allow
     for "local" kwarg to only iterate the members that are declared in
     this instance (i.e. not the prototype)
     """
     if local:
         return iter(self._properties.values())
     else:
         return ContainerObject.elements(self)
コード例 #23
0
 def __init__(self, items, **kwargs):
     BaseULObject.__init__(self, **kwargs)
     ContainerObject.__init__(self, **kwargs)
     items = list(items)
     if all(isinstance(it, Item) for it in items):
         indices = [it.index for it in items]
         if min(indices) < 0 or max(indices) > len(indices):
             raise NineMLUsageError(
                 "Indices are not contiguous, have duplicates, or don't "
                 "start from 0 ({})"
                 .format(', '.join(str(i) for i in indices)))
         self.add(*items)
     elif any(isinstance(it, Item) for it in items):
         raise NineMLUsageError(
             "Cannot mix Items and Populations/Selections in Concatenate "
             "__init__ method ({})".format(', '.join(str(it)
                                                     for it in items)))
     else:
         self.add(*(Item(i, p) for i, p in enumerate(items)))
     assert(self.num_items)
コード例 #24
0
ファイル: component.py プロジェクト: apdavison/lib9ML
 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()
コード例 #25
0
ファイル: with_synapses.py プロジェクト: nsk6999/pype9
 def __init__(self,
              name,
              dynamics,
              synapses=[],
              connection_parameter_sets=[]):
     BaseALObject.__init__(self)
     DocumentLevelObject.__init__(self)
     ContainerObject.__init__(self)
     WithSynapses.__init__(self, name, dynamics, synapses,
                           connection_parameter_sets)
     # 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_port_exposures = dynamics._analog_send_port_exposures
     self._analog_receive_port_exposures = (
         dynamics._analog_receive_port_exposures)
     self._analog_reduce_port_exposures = (
         dynamics._analog_reduce_port_exposures)
     self._event_send_port_exposures = dynamics._event_send_port_exposures
     self._event_receive_port_exposures = (
         dynamics._event_receive_port_exposures)
     self._analog_port_connections = dynamics._analog_port_connections
     self._event_port_connections = dynamics._event_port_connections
コード例 #26
0
ファイル: with_synapses.py プロジェクト: CNS-OIST/PyPe9
 def __init__(self, port, properties):
     super(ConnectionPropertySet, self).__init__()
     ContainerObject.__init__(self)
     self._port = validate_identifier(port)
     for prop in properties:
         self.add(prop.clone(as_class=Property))
コード例 #27
0
ファイル: with_synapses.py プロジェクト: CNS-OIST/PyPe9
 def __init__(self, port, parameters):
     super(ConnectionParameterSet, self).__init__()
     ContainerObject.__init__(self)
     self._port = validate_identifier(port)
     for param in parameters:
         self.add(param.clone(as_class=Parameter))
コード例 #28
0
ファイル: with_synapses.py プロジェクト: nsk6999/pype9
 def __init__(self, port, parameters):
     super(ConnectionParameterSet, self).__init__()
     ContainerObject.__init__(self)
     self._port = validate_identifier(port)
     for param in parameters:
         self.add(param.clone(as_class=Parameter))
コード例 #29
0
ファイル: with_synapses.py プロジェクト: nsk6999/pype9
 def __init__(self, port, properties):
     super(ConnectionPropertySet, self).__init__()
     ContainerObject.__init__(self)
     self._port = validate_identifier(port)
     for prop in properties:
         self.add(prop.clone(as_class=Property))