Skip to content

Unify hierarchical mesh edge level metadata#66

Open
SIDDHANTCOOKIE wants to merge 5 commits intomllam:mainfrom
SIDDHANTCOOKIE:fix/45-unify-hierarchical-edge-level-metadata
Open

Unify hierarchical mesh edge level metadata#66
SIDDHANTCOOKIE wants to merge 5 commits intomllam:mainfrom
SIDDHANTCOOKIE:fix/45-unify-hierarchical-edge-level-metadata

Conversation

@SIDDHANTCOOKIE
Copy link
Copy Markdown

@SIDDHANTCOOKIE SIDDHANTCOOKIE commented Feb 21, 2026

Description

Hey @leifdenby @observingClouds @joeloskarsson
This PR standardizes hierarchical mesh edge level metadata to avoid mixed edge attribute keys/types that can cause downstream conversion issues.

Main changes:

  • Replace inconsistent edge metadata (level on same-level edges vs levels /on cross-level edges) with a consistent schema on all hierarchical meshedges:
    • from_level: int
    • to_level: int
    • direction: str (existing, retained)
    • connection: str (derived, e.g. "1>0")
  • Remove legacy edge keys (level, levels) from hierarchical mesh edges.
  • Update hierarchical handling in graph creation logic to identify bottom-level
    same-level mesh edges using direction/from_level/to_level.
  • Update archetype docstring to document the new edge metadata.
  • Add regression test test_hierarchical_edges_have_consistent_level_metadata
    to verify:
    • required new keys exist
    • types are consistent
    • same edges satisfy from_level == to_level
    • legacy keys are absent

Issue Link

Fixes issue #45

Type of change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📖 Documentation (Addition or improvements to documentation)

Checklist before requesting a review

  • My branch is up-to-date with the target branch - if not update your fork with the changes from the target branch (use pull with --rebase option if possible).
  • I have performed a self-review of my code
  • For any new/modified functions/classes I have added docstrings that clearly describe its purpose, expected inputs and returned values
  • I have placed in-line comments to clarify the intent of any hard-to-understand passages of my code
  • I have updated the documentation to cover introduced code changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have given the PR a name that clearly describes the change, written in imperative form (context).
  • I have requested a reviewer and an assignee (assignee is responsible for merging)

Checklist for reviewers

Each PR comes with its own improvements and flaws. The reviewer should check the following:

  • the code is readable
  • the code is well tested
  • the code is documented (including return types and parameters)
  • the code is easy to maintain

Author checklist after completed review

  • I have added a line to the CHANGELOG describing this change, in a section
    reflecting type of change (add section where missing):
    • added: when you have added new functionality
    • changed: when default behaviour of the code has been changed
    • fixes: when your contribution fixes a bug

Checklist for assignee

  • PR is up to date with the base branch
  • the tests pass
Screenshot 2026-02-21 061122 Screenshot 2026-02-21 061803
  • author has added an entry to the changelog (and designated the change as added, changed or fixed)
  • Once the PR is ready to be merged, squash commits and merge the PR.

@observingClouds
Copy link
Copy Markdown
Contributor

Thanks @SIDDHANTCOOKIE for this PR. Please use the entire PR template, it helps us to keep a better overview about the process.

@SIDDHANTCOOKIE
Copy link
Copy Markdown
Author

@observingClouds Thanks for the clarification, I've updated the description with everything that was missing.

@SIDDHANTCOOKIE
Copy link
Copy Markdown
Author

Hey @observingClouds CI notebook was failing due to the earlier metadata rename.
I pushed a follow-up update to docs.

@SIDDHANTCOOKIE
Copy link
Copy Markdown
Author

@observingClouds how should I proceed with this?

@observingClouds
Copy link
Copy Markdown
Contributor

Hi @SIDDHANTCOOKIE thanks for asking. Please document the changes in the CHANGELOG.md and we will put this PR on the milestone for the next release

@SIDDHANTCOOKIE
Copy link
Copy Markdown
Author

Hey @observingClouds I've added the entry to CHANGELOG.md. Please let me know if any changes are needed.

Also, I was curious on how to contribute further. Should I wait for existing issues to be assigned, or should I open new ones as I discover improvements in the codebase? If there are other repositories in the MLLAM ecosystem that currently need help, I’d be happy to contribute there as well.

Looking forward to your guidance. Thank you!

Comment on lines +123 to +124
data.pop("level", None)
data.pop("levels", None)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(Same as earlier) Do we actually add these keys now? Or why do we need to drop them here instead of not adding them to begin with?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for pointing this out, those data.pop("level", None) / data.pop("levels", None) For G_up(hierarchial.py), we copy edge metadata from G_down, in current flow G_down is already normalized, so these keys should not be present. So yes, these two pop lines are redundant now, and I can remove them to keep the code simpler.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yea if they do nothing now I think you can drop them

Comment on lines +405 to +407
first_level_graph = split_graph_by_edge_attribute(
level_subgraph, "level"
)[0]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Here we are splitting on "level" again. Will this work?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes, this works.

That split on "level" is only in the non-hierarchical fallback branch (when edges do not have from_level/to_level). Hierarchical graphs take the branch above and use direction + from_level/to_level, so they don’t rely on "level" there.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Also @joeloskarsson I forgot to run precommit in my last commit that caused the CI to fail. I've resolved it in my latest commit

@joeloskarsson
Copy link
Copy Markdown
Contributor

Thinking a bit more about this, does it make sense to restrict the scope of this to only hierarchical graphs? Or are we creating another inconsistency now between hierarchical graphs and flat (potentially multi-scale graphs)? In my view we could always view a flat graph as a hierarchical one with from_level=1, to_level=1, direction=same. But now the flat graphs will still have this level attribute. Interested to hear @observingClouds view.

I am thinking that it would make sense to make these attributes consistent across all graphs really.

@SIDDHANTCOOKIE
Copy link
Copy Markdown
Author

I agree, @joeloskarsson . Restricting this to hierarchical graphs leaves us with two schemas (from_level/to_level vs level) and that’s not ideal.

I can extend this so all mesh edges use a consistent schema:

  • from_level
  • to_level
  • direction
  • optional connection

For flat/flat-multiscale, this would be:

  • direction="same"
  • from_level=to_level= (or fixed 0 for single-level flat, depending on convention)


### Fixed

- Fix issue #45 about inconsistent edge metadata and improves compatibility
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would be helpful if you summarised what the attributes that have been removed are and what they have been replaced with

@leifdenby
Copy link
Copy Markdown
Member

For flat/flat-multiscale, this would be:

* `direction`="same"

* `from_level=to_level`= (or fixed 0 for single-level flat, depending on convention)

Maybe we just do away with any notion of level for the flat/flat-multiscale meshes? For flat-multiscale this is only the because the multiscale mesh is built by collapsing the individual graphs representing each level of refinement, but we could remove it once we know we're not trying to build a hierarchical mesh?

@leifdenby
Copy link
Copy Markdown
Member

@SIDDHANTCOOKIE are you still looking at this?

@SIDDHANTCOOKIE
Copy link
Copy Markdown
Author

Hey so sorry I had my uni exams and totally forgot about it can you please tell me what should be the next steps

@leifdenby
Copy link
Copy Markdown
Member

Hey so sorry I had my uni exams and totally forgot about it can you please tell me what should be the next steps

No worries! You should absolutely concentrate foremost on your exams!

Once you are ready the first steps would be to engage with the ongoing discussions :) For example the question I asked in #66 (comment), and this one #66 (comment).

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants