Skip to content

add mesh bp remove util#1607

Merged
cyrush merged 21 commits into
developfrom
task/2026_05_mesh_bp_remove_util
May 22, 2026
Merged

add mesh bp remove util#1607
cyrush merged 21 commits into
developfrom
task/2026_05_mesh_bp_remove_util

Conversation

@cyrush

@cyrush cyrush commented May 15, 2026

Copy link
Copy Markdown
Member

add conduit::mesh::blueprint::remove, which allows you to remove components of a mesh (like topologies, fields, etc) along with there dependencies.

For example, removing a topology will remove any fields defined on that topology, removing a matset will remove references and matset specific values for any related fields.

@cyrush

cyrush commented May 15, 2026

Copy link
Copy Markdown
Member Author

TODO: Test cases are WIP, need to add many more:

  • add multi domain test cases
  • add matset, adjset, and nestset test cases
  • make sure matset test cases include a field that with matset_values
  • think about other bad options scenarios

@cyrush

cyrush commented May 18, 2026

Copy link
Copy Markdown
Member Author

presence of * as category name indicates that we should remove everything from that category

fields: ["den","radial"]
matsets: *
state: *

will fully remove state and all matsets, along with the fields den and radial

for state, other than *, any entry is assumed to be a path

fields: ["den","radial"]
matsets: *
state: time

@cyrush

cyrush commented May 20, 2026

Copy link
Copy Markdown
Member Author

added specset test and python interface and python test

@JustinPrivitera

Copy link
Copy Markdown
Member

There are many places we could leverage this (perhaps in Silo tests) that would provide additional testing coverage.

@cyrush cyrush requested a review from JustinPrivitera May 20, 2026 19:01
Comment thread src/tests/blueprint/t_blueprint_mesh_remove.cpp

@JustinPrivitera JustinPrivitera left a comment

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.

Reviewing now. Are you going to add a changelog entry?

@cyrush

cyrush commented May 20, 2026

Copy link
Copy Markdown
Member Author

Thanks, yes I will add Change log entry

@JustinPrivitera JustinPrivitera left a comment

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.

Love the lambdas. I have some comments about a few things.

Comment thread src/libs/blueprint/conduit_blueprint_mesh.cpp Outdated
Comment on lines +9370 to +9375
std::regex comp_regex(comp_pat_adj);
if(std::regex_match(comp_name, comp_regex))
{
//std::cout << "true" << std::endl;
n_comp.remove(comp_name);
}

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.

I don't understand why we need to do regex match again. We already used it earlier to populate the set, so can't we just remove everything in the set unconditionally?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The set contains the regex, not the expanded names.

The prior walk explicitly records dependents, but the outer matches are not explicitly recorded.

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.

I see. The set gets populated even further above in init_set_from_opts.

Comment on lines +9407 to +9413
// past to clean up matsets
// matsets: for any field that refs a matset,
// remove that ref and any matset values

for(size_t i = 0; i < domains.size(); i++)
{
conduit::Node *dom = domains[i];

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.

Why not remove fields that depend on a matset entirely? The field may or may not be in a valid state after the operation you've implemented here. If the field is material-dependent, then it will still be valid, but if it is mixed (https://llnl-conduit.readthedocs.io/en/latest/blueprint_mesh.html#fields), then it is no longer valid and should be removed entirely.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

fully material-dependent is rare, usually values exists and is useful even without the matset values. That said, I this should check for that case.

Matset values can be very large, removing them when not needed is a savings if folks only want to save or process the overall field values.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

  • check for material-dependent case (no values), and remove field if when no useful data is left over.

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.

I think it is sufficient to check for the existence of values after scrubbing the matset association, and remove if there are no values. However, fields are handled differently from everything else in remove. Maybe there is an option to aggressively remove fields versus conservatively removing them? It just seems like an unexpected behavior of the function. If I am removing a matset would I not want associated fields to also be removed? I think both choices are valid.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The relationship between fields and matsets is a bit different.

I think removing the entire field is too aggressive in this case b/c it removes data that is still useful.
Most viz uses cases will use values and never touch matset values unless the user is doing something sophisticated.

They can always remove any field fully by name or pattern.

Comment on lines +253 to +255
// removing the matset should remove the specset as well
EXPECT_TRUE(n_mesh.has_path("matsets/mesh"));
EXPECT_FALSE(n_mesh.has_path("specsets/mesh"));

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.

Suggested change
// removing the matset should remove the specset as well
EXPECT_TRUE(n_mesh.has_path("matsets/mesh"));
EXPECT_FALSE(n_mesh.has_path("specsets/mesh"));
// removing the matset should remove the specset as well
EXPECT_FALSE(n_mesh.has_path("matsets/mesh"));
EXPECT_FALSE(n_mesh.has_path("specsets/mesh"));

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.

looks like this was copied from above and not updated to reflect the comment. It doesn't test what the comment says it does.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It is a copy and paste problem -- but the above comment is what is wrong.
In this case we are removing the specset, that matset should still exist.

@JustinPrivitera JustinPrivitera May 21, 2026

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.

No, look closer - this test is copied from the case right before it. Right now both tests are identical. It makes sense to test three cases for specsets:

  1. removing a specset, which is tested twice
  2. removing a matset which should remove the specset also, which your comment suggested you wanted to test, but is not tested as things currently stand
  3. removing a topo which should remove the matset which should remove the specset, which is tested at the end

I think you want to keep the original comment and fix the options that are tested and the resulting EXPECT_***.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

thank, you I think have this sorted out now. Can you take one more look?

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.

yes looks good

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.

currently we can either give a name or give "*"? Do we want to support "*_name" or any other regex stuff?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

See my comment about glob vs regex, I will work on support for that so that * isn't a special case

Co-authored-by: Justin Privitera <35237779+JustinPrivitera@users.noreply.github.com>
@cyrush

cyrush commented May 21, 2026

Copy link
Copy Markdown
Member Author

For filtering, what we really want is glob matching, not regex matching.

We can convert glob style matching into a regex, I will add a utility to do that.

This will also be useful in other cases (extending mesh blueprint read to read subsets of a mesh with same style of args used here)

Comment thread src/tests/blueprint/t_blueprint_mesh_remove.cpp
Comment on lines +236 to +255
{
conduit::blueprint::mesh::examples::generate("misc",n_mesh);
EXPECT_TRUE(n_mesh.has_path("topologies/mesh"));
EXPECT_TRUE(n_mesh.has_path("fields/radial"));
EXPECT_TRUE(n_mesh.has_path("matsets/mesh"));
EXPECT_TRUE(n_mesh.has_path("specsets/mesh"));

n_opts.reset();
n_opts["specsets"] = "mesh";

echo_node("[before]",n_mesh);
echo_node("[options]",n_opts);
conduit::blueprint::mesh::remove(n_opts,n_mesh);
EXPECT_TRUE(conduit::blueprint::mesh::verify(n_mesh, n_info));
echo_node("[after]",n_mesh);
echo_node("[info]",n_info);

// after removing specset, matset should remain
EXPECT_TRUE(n_mesh.has_path("matsets/mesh"));
EXPECT_FALSE(n_mesh.has_path("specsets/mesh"));

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.

this test should be updated to test removing a matset: #1607 (comment)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think this is sorted, please give it one more look (sorry for the double comment)

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.

yes looks good

@cyrush

cyrush commented May 21, 2026

Copy link
Copy Markdown
Member Author

I created a glob match util and remove refactored to use it.

@cyrush cyrush merged commit 1890886 into develop May 22, 2026
25 of 26 checks passed
@cyrush cyrush deleted the task/2026_05_mesh_bp_remove_util branch May 22, 2026 16:38
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.

2 participants