Skip to content

Conversation

@mpvginde
Copy link
Contributor

@mpvginde mpvginde commented Nov 21, 2025

Description

Building MultiScaleEdges for a Triangular refined Icosahedron with resolution > 8 can become increasingly time consuming.
This PR introduces a new strategy to optimise the creation of 1-hop multiscale edges (TriNodesEdgeBuilder), relying only on the trimesh package.

What problem does this change solve?

What issue or task does this change relate to?

Additional notes

The code is currently still only a proof-of-concept, and will need some refactoring before merging.

Currently implemented:

  • 1-hop multiscale edge creation for TriNodes: TriNodesEdgeBuilder
  • 1-hop multiscale edge creation for StretchedTriNodes: StretchedTriNodesEdgeBuilder
  • 1-hop multiscale edge creation for LimitedAreaTriNodes: TriNodesEdgeBuilder with area_mask_builder

As a contributor to the Anemoi framework, please ensure that your changes include unit tests, updates to any affected dependencies and documentation, and have been tested in a parallel setting (i.e., with multiple GPUs). As a reviewer, you are also responsible for verifying these aspects and requesting changes if they are not adequately addressed. For guidelines about those please refer to https://anemoi.readthedocs.io/en/latest/

By opening this pull request, I affirm that all authors agree to the Contributor License Agreement.

@mpvginde
Copy link
Contributor Author

mpvginde commented Nov 21, 2025

Logs from building a graph with following recipe:

nodes:
  hidden:
    node_builder:
      _target_: anemoi.graphs.nodes.TriNodes
      resolution: 8
  hidden_new:
    node_builder:
      _target_: anemoi.graphs.nodes.TriNodes
      resolution: 8
edges:
  - source_name: hidden
    target_name: hidden
    edge_builders:
      - _target_: anemoi.graphs.edges.MultiScaleEdges
        x_hops: 1
        new_method: False

  - source_name: hidden_new
    target_name: hidden_new
    edge_builders:
      - _target_: anemoi.graphs.edges.MultiScaleEdges
        x_hops: 1
        new_method: True

LOGS

2025-11-21 14:33:12 DEBUG Time to register node coordinates (TriNodes): 2.54 s
2025-11-21 14:33:12 DEBUG Time to register node coordinates (TriNodes): 0.00 s
2025-11-21 14:33:14 DEBUG Time to register node coordinates (TriNodes): 2.13 s
2025-11-21 14:33:14 DEBUG Time to register node coordinates (TriNodes): 0.00 s
2025-11-21 14:33:14 INFO Using existing strategy for multiscale-edge building.
2025-11-21 14:33:16 DEBUG Adding 60 edges for resolution 0
2025-11-21 14:33:16 DEBUG Adding 240 edges for resolution 1
2025-11-21 14:33:16 DEBUG Adding 960 edges for resolution 2
2025-11-21 14:33:16 DEBUG Adding 3840 edges for resolution 3
2025-11-21 14:33:17 DEBUG Adding 15360 edges for resolution 4
2025-11-21 14:33:18 DEBUG Adding 61440 edges for resolution 5
2025-11-21 14:33:22 DEBUG Adding 245760 edges for resolution 6
2025-11-21 14:33:39 DEBUG Adding 983040 edges for resolution 7
2025-11-21 14:34:46 DEBUG Adding 3932160 edges for resolution 8
2025-11-21 14:34:56 DEBUG edge_index.shape : torch.Size([2, 5242860])
2025-11-21 14:34:56 DEBUG **Time to register edge indices (MultiScaleEdges): 101.80 s**
2025-11-21 14:34:56 INFO Using new strategy for x_hops=1 multiscale-edge building.
2025-11-21 14:34:56 DEBUG Nodes coordinates shape: torch.Size([655362, 2])
2025-11-21 14:34:56 DEBUG Adding 60 1-hop edges for resolution 0
2025-11-21 14:34:56 DEBUG Adding 240 1-hop edges for resolution 1
2025-11-21 14:34:56 DEBUG Adding 960 1-hop edges for resolution 2
2025-11-21 14:34:56 DEBUG Adding 3840 1-hop edges for resolution 3
2025-11-21 14:34:56 DEBUG Adding 15360 1-hop edges for resolution 4
2025-11-21 14:34:56 DEBUG Adding 61440 1-hop edges for resolution 5
2025-11-21 14:34:56 DEBUG Adding 245760 1-hop edges for resolution 6
2025-11-21 14:34:56 DEBUG Adding 983040 1-hop edges for resolution 7
2025-11-21 14:34:56 DEBUG Adding 3932160 1-hop edges for resolution 8
2025-11-21 14:34:57 DEBUG multiscale_edges_shape: (2, 5242860)
2025-11-21 14:34:57 DEBUG edge_index.shape : torch.Size([2, 5242860])
2025-11-21 14:34:57 DEBUG **Time to register edge indices (MultiScaleEdges): 0.63 s**
2025-11-21 14:34:57 INFO Cleaning graph.
2025-11-21 14:34:57 INFO _grid_reference_distance deleted from graph.
2025-11-21 14:34:57 INFO _resolutions deleted from graph.
2025-11-21 14:34:57 INFO _node_ordering deleted from graph.
2025-11-21 14:34:57 INFO _nx_graph deleted from graph.
2025-11-21 14:34:57 INFO _grid_reference_distance deleted from graph.
2025-11-21 14:34:57 INFO _resolutions deleted from graph.
2025-11-21 14:34:57 INFO _node_ordering deleted from graph.
2025-11-21 14:34:57 INFO _nx_graph deleted from graph.
2025-11-21 14:34:57 INFO _multiscale_edges deleted from graph.
2025-11-21 14:34:57 INFO Graph saved at graphs/trimesh_multiscale-8-old+new.pt.

1-hop Multiscale connections for refinement level 4 with the current strategy:

image

1-hop Multiscale connections for refinement level 4 with the new strategy:

image

@mpvginde mpvginde added the ATS Approval Not Needed No approval needed by ATS label Nov 21, 2025
x_hops=x_hops,
area_mask_builder=nodes.get("_area_mask_builder", None),
)
if new_method:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we think of another name? "new methods" can become "old methods", and it is not a replacement in the sense that it only supports 1 hop.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ssmmnn11, totally agree. For now this is just a proof of concept code. It will need some refactor before it can get merged. I'll make it more clear in the PR description.

@mpvginde mpvginde marked this pull request as draft November 24, 2025 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ATS Approval Not Needed No approval needed by ATS graphs

Projects

Status: To be triaged

Development

Successfully merging this pull request may close these issues.

3 participants