Skip to content

Commit

Permalink
addressed changes in docs and exception error
Browse files Browse the repository at this point in the history
  • Loading branch information
icedoom888 committed Dec 19, 2024
1 parent d3611d3 commit 5cc3ca8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 40 deletions.
48 changes: 10 additions & 38 deletions docs/graphs/edge_attributes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,26 +53,12 @@ Attributes can also be copied from nodes to edges. This is done using
the `AttributeFromNode` base class, with specialized versions for source
and target nodes.

*************
From Source
*************
From Source
===========

This attribute copies a specific property of the source node to the
edge.

.. code:: yaml
edges:
- source_name: ...
target_name: ...
edge_builders: ...
attributes:
comes_from_source_node:
_target_: anemoi.graphs.edges.attributes.AttributeFromSourceNode
node_attr_name: "attribute_name"
Example usage for copying the cutout mask from nodes to edges in the
encoder:
edge. Example usage for copying the cutout mask from nodes to edges in
the encoder:

.. code:: yaml
Expand All @@ -82,30 +68,16 @@ encoder:
target_name: hidden
edge_builders: ...
attributes:
cutout:
cutout: # Assigned name to the edge attribute, can be different than node_attr_name
_target_: anemoi.graphs.edges.attributes.AttributeFromSourceNode
node_attr_name: cutout
*************
From Target
*************
From Target
===========

This attribute copies a specific property of the target node to the
edge.

.. code:: yaml
edges:
- source_name: ...
target_name: ...
edge_builders: ...
attributes:
comes_from_target_node:
_target_: anemoi.graphs.edges.attributes.AttributeFromTargetNode
node_attr_name: "attribute_name"
Example usage for copying the coutout mask from nodes to edges in the
decoder:
edge. Example usage for copying the coutout mask from nodes to edges in
the decoder:

.. code:: yaml
Expand All @@ -115,6 +87,6 @@ decoder:
target_name: data
edge_builders: ...
attributes:
cutout:
cutout: # Assigned name to the edge attribute, can be different than node_attr_name
_target_: anemoi.graphs.edges.attributes.AttributeFromTargetNode
node_attr_name: cutout
9 changes: 7 additions & 2 deletions src/anemoi/graphs/edges/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,13 @@ def get_raw_values(self, graph: HeteroData, source_name: str, target_name: str)
node_name = self.get_node_name(source_name, target_name)

edge_index = graph[(source_name, "to", target_name)].edge_index
assert hasattr(graph[node_name], self.node_attr_name)
return graph[node_name][self.node_attr_name].numpy()[edge_index[self.idx]]
try:
return graph[node_name][self.node_attr_name].numpy()[edge_index[self.idx]]

except AttributeError:
raise AttributeError(
f"{self.__class__.__name__} failed because the attribute '{self.node_attr_name}' is not defined for the nodes."
)


class AttributeFromSourceNode(AttributeFromNode):
Expand Down

0 comments on commit 5cc3ca8

Please sign in to comment.