Network
- class phantom.network.Network(agents=None, resolver=None, connections=None, ignore_connection_errors=False)[source]
P2P messaging network.
This class is responsible for monitoring connections and tracking state/flow between adjacent agents in a peer-to-peer network. The underlying representation is based on dictionaries via the NetworkX library.
- Parameters:
agents (
Optional
[Iterable
[Agent
]]) – Optional list of agents to add to the network.resolver (
Optional
[Resolver
]) – Optional custom resolver to use, by default will use the BatchResolver with a round_limit of 2.connections (
Optional
[Iterable
[Tuple
[Hashable
,Hashable
]]]) – Optional initial list of connections to create in the network.ignore_connection_errors (
bool
) – If True will not raise errors if an attempt is made to send a message along an non-existant connection.
- agents
Mapping between IDs and the corresponding agents in the network.
- graph
Directed graph modelling the connections between agents.
- add_connections_with_adjmat(agent_ids, adjacency_matrix)[source]
Connect a subset of agents to one another via an adjacency matrix.
- context_for(agent_id, env_view)[source]
Returns the local context for agent
agent_id
.Here we define a neighbourhood as being the first-order ego-graph with
agent_id
set as the focal node.
- get_agents_with_type(agent_type)[source]
Returns a collection of agents in the network with a given type.
- get_agents_without_type(agent_type)[source]
Returns a collection of agents in the network without a given type.
- class phantom.network.StochasticNetwork(agents=None, resolver=None, connections=None, ignore_connection_errors=False)[source]
Stochastic P2P messaging network.
This class builds on the base Network class but adds the ability to resample the connectivity of all connections.
- Parameters:
agents (
Optional
[Iterable
[Agent
]]) – Optional list of agents to add to the network.resolver (
Optional
[Resolver
]) – Optional custom resolver to use, by default will use the BatchResolver with a round_limit of 2.connections (
Optional
[Iterable
[Tuple
[Hashable
,Hashable
]]]) – Optional initial list of connections to create in the network.ignore_connection_errors (
bool
) – If True will not raise errors if an attempt is made to send a message along an non-existant connection.
- agents
Mapping between IDs and the corresponding agents in the network.
- graph
Directed graph modelling the connections between agents.
- add_agent(agent)
Add a new agent node to the network.
- add_agents(agents)
Add new agent nodes to the network.
- add_connections_with_adjmat(agent_ids, adjacency_matrix)
Connect a subset of agents to one another via an adjacency matrix.
- context_for(agent_id, env_view)
Returns the local context for agent
agent_id
.Here we define a neighbourhood as being the first-order ego-graph with
agent_id
set as the focal node.
- get_agents_where(pred)
Returns the set of agents in the network that satisfy a predicate.
- get_agents_with_type(agent_type)
Returns a collection of agents in the network with a given type.
- get_agents_without_type(agent_type)
Returns a collection of agents in the network without a given type.
- has_edge(sender_id, receiver_id)
Returns whether two agents are connected.
- resolve(contexts)
Resolve all messages in the network and clear volatile memory.
- send(sender_id, receiver_id, payload)
Send message batches across the network.