Interfaces

The neet.interfaces module provides a collection of functions for determining if types adhere to various network interfaces, and generic functions for operating upon them. This done primarily through the is_network(), is_fixed_sized() and is_boolean_network() functions.

API Documentation

Interface Testing

neet.interfaces.is_network(thing)[source]

Determine whether an object or type meets the interface requirement of a network. Specifically, to be considered a network, a class must provide the following methods:

  1. update which updates the state of a lattice
  2. state_space which returns a neet.statespace.StateSpace() object
  3. neighbors which returns the neighbors of a given node

Example:

>>> class IsNetwork(object):
...     def update(self):
...         pass
...     def state_space(self):
...         return StateSpace(1)
...     def neighbors(self, i):
...         return []
...
>>> class IsNotNetwork(object):
...     pass
...
>>> is_network(IsNetwork())
True
>>> is_network(IsNetwork)
True
>>> is_network(IsNotNetwork())
False
>>> is_network(IsNotNetwork)
False
>>> is_network(5)
False
Parameters:thing – an object or a type
Returns:True if thing has the minimum interface of a network
neet.interfaces.is_fixed_sized(thing)[source]

Determine whether an object or type is a network and has a fixed size.

Example

>>> class IsNetwork(object):
...     def update(self):
...         pass
...     def state_space(self):
...         return StateSpace(1)
...     def neighbors(self, i):
...         return []
...
>>> class FixedSized(IsNetwork):
...     def size():
...         return 5
...
>>> is_fixed_sized(IsNetwork)
False
>>> is_fixed_sized(FixedSized)
True
Parameters:thing – an object or a type
Returns:True if thing is a network with a size attribute
See:is_network().
neet.interfaces.is_boolean_network(thing)[source]

Determine whether an object is a network with all Boolean states.d

Interface Functions

neet.interfaces.neighbors(net, index, direction='both', **kwargs)[source]

Return a set of neighbors for a specified node, or a list of sets of neighbors for all nodes in the network.

For ECAs, in the cases of the lattices having fixed boundary conditions, the left boundary, being on the left of the leftmost index 0, has an index of -1, while the right boundary’s index is the size+1. The full state of the lattices and the boundaries is equavolent to: [cell0, cell1, …, cellN, right_boundary, left_boundary] if it is ever presented as a single list in Python.

Parameters:
  • index – node index, if neighbors desired for one node only
  • direction – type of node neighbors to return (‘in’, ‘out’, or ‘both’)
  • size – size of ECA, required if network is an ECA
Returns:

a set of neighbors of a node

Example

>>> net = ECA(30)
>>> neighbors(net, index=2, size=3, direction='out')
{0, 1, 2}
>>> net.boundary = (1,1)
>>> neighbors(net, index=2, size=3, direction='out')
{1, 2}

See ECA.neighbors(),`LogicNetwork.neighbors()` or WTNetwork.neighbors() docstrings for more details and basic use examples.

neet.interfaces.to_networkx_graph(net, size=None, labels='indices', **kwargs)[source]

Return networkx graph given neet network. Requires networkx.

Parameters:
  • labels – how node is labeled and thus identified in networkx graph (‘names’ or ‘indices’), only used if net is a LogicNetwork or WTNetwork
  • size – size of ECA, required if network is an ECA
Returns:

a networkx DiGraph