nineml.abstraction_layer.component.ComponentClass

class nineml.abstraction_layer.component.ComponentClass(name, parameters=None, analog_ports=None, event_ports=None, dynamics=None, subnodes=None, portconnections=None, regimes=None, aliases=None, state_variables=None)

A ComponentClass object represents a component in NineML.

Todo

For more information, see

__init__(name, parameters=None, analog_ports=None, event_ports=None, dynamics=None, subnodes=None, portconnections=None, regimes=None, aliases=None, state_variables=None)

Constructs a ComponentClass

Parameters:
  • name – The name of the component.
  • parameters – A list containing either Parameter objects or strings representing the parameter names. If None, then the parameters are automatically inferred from the Dynamics block.
  • analog_ports – A list of AnalogPorts, which will be the local AnalogPorts for this object.
  • event_ports – A list of EventPorts objects, which will be the local event-ports for this object. If this is None, then they will be automatically inferred from the dynamics block.
  • dynamics – A Dynamics object, defining the local dynamics of the component.
  • subnodes – A dictionary mapping namespace-names to sub-component. [Type: {string:|ComponentClass|, string:|ComponentClass|, string:|ComponentClass|} ] describing the namespace of subcomponents for this component.
  • portconnections – A list of pairs, specifying the connections between the ports of the subcomponents in this component. These can be (|NamespaceAddress|, |NamespaceAddress|)’ or ``(string, string)`.
  • interface – A shorthand way of specifying the interface for this component; Parameters, AnalogPorts and EventPorts. interface takes a list of these objects, and automatically resolves them by type into the correct types.

Examples:

>>> a = ComponentClass(name='MyComponent1')

Todo

Point this towards and example of constructing ComponentClasses. This can’t be here, because we also need to know about dynamics. For examples

Methods

__init__(name[, parameters, analog_ports, ...]) Constructs a ComponentClass
accept_visitor(visitor, **kwargs) link to something about visitation.
backsub_all() Expand all alias definitions in local equations.
connect_ports(src, sink) Connects the ports of 2 subcomponents.
get_node_addr() Get the namespace address of this component
get_parent_model() Gets the parent component for this component
get_subnode(addr) Gets a subnode from this component recursively.
insert_subnode(namespace, subnode) Insert a subnode into this component
is_flat() Is this component flat or does it have subcomponents?
set_flattener(flattener) Specifies the flattening object used to create this component, if
set_parent_model(parentmodel) Sets the parent component for this component
was_flattened() Returns True if this component was created by flattening another
write(file[, flatten]) Export this model to an XML file.

Attributes

aliases Forwarding function to self.dynamics.aliases
aliases_map Forwarding function to self.dynamics.alias_map
analog_ports Returns an iterator over the local AnalogPort objects
dynamics Returns the local Dynamics object
event_ports Returns an iterator over the local EventPort objects
flattener If this component was made by flattening other components, return the
name Returns the name of the component
parameters Returns an iterator over the local Parameter objects
portconnections
query Returns the ComponentQuery object associated with this class
regimes Forwarding function to self.dynamics.regimes
regimes_map Forwarding function to self.dynamics.regimes_map
state_variables Forwarding function to self.dynamics.state_variables
state_variables_map Forwarding function to self.dynamics.state_variables_map
transitions Forwarding function to self.dynamics.transitions
accept_visitor(visitor, **kwargs)

link to something about visitation.

backsub_all()

Expand all alias definitions in local equations.

This function finds Aliases, TimeDerivatives, send AnalogPorts, StateAssignments and Conditions which are defined in terms of other Aliases, and expands them, such that each only has Parameters, StateVariables and recv/reduce AnalogPorts on the RHS.

connect_ports(src, sink)

Connects the ports of 2 subcomponents.

The ports can be specified as string s or NamespaceAddresses.

Parameters:
  • src – The source port of one sub-component; this should either an EventPort or AnalogPort, but it must be a send port.
  • sink – The sink port of one sub-component; this should either an EventPort or AnalogPort, but it must be either a ‘recv’ or a ‘reduce’ port.
get_node_addr()

Get the namespace address of this component

get_parent_model()

Gets the parent component for this component

get_subnode(addr)

Gets a subnode from this component recursively.

insert_subnode(namespace, subnode)

Insert a subnode into this component

Parameters:
  • subnode – An object of type ComponentClass.
  • namespace – A string specifying the name of the component in this components namespace.
Raises :

NineMLRuntimeException if there is already a subcomponent at the same namespace location

Note

This method will clone the subnode.

is_flat()

Is this component flat or does it have subcomponents?

Returns a Boolean specifying whether this component is flat; i.e. has no subcomponent

set_flattener(flattener)

Specifies the flattening object used to create this component, if this component was flattened from a hierarchical component

set_parent_model(parentmodel)

Sets the parent component for this component

was_flattened()

Returns True if this component was created by flattening another component

write(file, flatten=True)

Export this model to an XML file.

Params file:A filename or fileobject
Params flatten:Boolean specifying whether the component should be flattened before saving
aliases

Forwarding function to self.dynamics.aliases

aliases_map

Forwarding function to self.dynamics.alias_map

analog_ports

Returns an iterator over the local AnalogPort objects

dynamics

Returns the local Dynamics object

event_ports

Returns an iterator over the local EventPort objects

flattener

If this component was made by flattening other components, return the ComponentFlattener object. This is useful for finding initial-regimes

name

Returns the name of the component

parameters

Returns an iterator over the local Parameter objects

portconnections
query

Returns the ComponentQuery object associated with this class

regimes

Forwarding function to self.dynamics.regimes

regimes_map

Forwarding function to self.dynamics.regimes_map

state_variables

Forwarding function to self.dynamics.state_variables

state_variables_map

Forwarding function to self.dynamics.state_variables_map

transitions

Forwarding function to self.dynamics.transitions