nip.graph_isomorphism.agents.GraphIsomorphismCombinedBody#

class nip.graph_isomorphism.agents.GraphIsomorphismCombinedBody(*args, **kwargs)[source]#

A module which combines the agent bodies for the graph isomorphism task.

Shapes

Input:

  • “round” (…): The current round number.

  • “x” (… round channel position pair node): The graph node features (message history)

  • “adjacency” (… pair node node): The adjacency matrices.

  • “message” (… channel position pair node), optional: The most recent message.

  • “node_mask” (… pair node): Which nodes actually exist.

  • “linear_message_history” : (… round channel position linear_message), optional: The linear message history, if using.

Output:

  • (“agents”, “node_level_repr”) (… agent pair max_nodes d_representation): The output node-level representations.

  • (“agents”, “graph_level_repr”) (… agent pair d_representation): The output graph-level representations.

Parameters:

Methods Summary

__init__(hyper_params, settings, ...)

Initialize internal Module state, shared by both nn.Module and ScriptModule.

_restrict_input_to_visible_channels(...)

Restrict an agent's input to its visible message channels.

forward(data[, hooks])

Run the agent bodies and combine their outputs.

Attributes

T_destination

additional_in_keys

additional_out_keys

call_super_init

device

The device used by the agent part.

dump_patches

excluded_in_keys

excluded_out_keys

in_keys

The keys required by the module.

out_keys

The keys produced by the module.

out_keys_source

training

Methods

__init__(hyper_params: HyperParameters, settings: ExperimentSettings, protocol_handler: ProtocolHandler, bodies: dict[str, AgentBody])[source]#

Initialize internal Module state, shared by both nn.Module and ScriptModule.

_restrict_input_to_visible_channels(agent_name: str, input_array: Tensor | ndarray[Any, dtype[_ScalarType_co]], shape_spec: str) Tensor[source]#

Restrict an agent’s input to its visible message channels.

Agents only receive messages from the channels they can see. This function restricts the input to the agent to only the visible message channels.

Parameters:
  • agent_name (str) – The name of the agent.

  • input_array (Tensor | NDArray) – The input array to the agent.

  • shape_spec (str) – The shape of the input. This is a space-separated string of the dimensions of the input. One of these must be “channel”.

Returns:

restricted_input (Tensor | NDArray) – The input restricted to the visible message channels.

forward(data: TensorDictBase, hooks: GraphIsomorphismAgentHooks | None = None) TensorDict[source]#

Run the agent bodies and combine their outputs.

Parameters:
  • data (TensorDictBase) –

    The input data. A tensor dict with keys:

    • ”round” (…): The current round number.

    • ”x” (… round channel position pair node): The graph node features (message history)

    • ”adjacency” (… pair node node): The adjacency matrices.

    • ”message” (… channel position pair node), optional: The most recent message.

    • ”node_mask” (… pair node): Which nodes actually exist.

    • ”linear_message_history” : (… round channel position linear_message), optional: The linear message history, if using.

  • hooks (GraphIsomorphismAgentHooks, optional) – Hooks to run at various points in the agent forward pass.

Returns:

data (TensorDict) – The tensordict updated in place with the output of the agent bodies.