Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] Variable deregistry #12554

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft

[core] Variable deregistry #12554

wants to merge 3 commits into from

Conversation

jcotela
Copy link
Member

@jcotela jcotela commented Jul 17, 2024

📝 Description
Each application should deregister the variables it registered. They are not being removed from the registry currently, and I suspect this is causing memory errors on tests. (It definitely did for the tests at Altair involving multiple applications).

I'm creating this as a draft for now, just to see if it passes CI. If this ends up going in, I think we need an implementation of something like RegistryItem::IsSameType (added in this PR) that does not rely on a try/catch.

FYI @loumalouomega @pooyan-dadvand @roigcarlo

🆕 Changelog

  • Add RegistryItem::IsSameType
  • Each application de-registers the variables it registered now.

@jcotela jcotela self-assigned this Jul 17, 2024
@jcotela jcotela requested a review from a team as a code owner July 17, 2024 15:13
@jcotela jcotela marked this pull request as draft July 17, 2024 15:15
Copy link
Member

@loumalouomega loumalouomega left a comment

Choose a reason for hiding this comment

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

Thanks, okay from my side

Comment on lines +321 to +331
void Register() const {
const std::string variable_path("variables.all."+Name());
if (!Registry::HasItem(variable_path)) {
Registry::AddItem<VariableType>(variable_path, *this);
Registry::AddItem<VariableType>("variables."+Registry::GetCurrentSource()+"."+Name(), *this);
} else if(!Registry::GetItem(variable_path).IsSameType(*this)) {
KRATOS_ERROR << "Attempting to register " << Name()
<< " but a variable with the same name and different type already exists"
<< std::endl;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

I am curious, since registering the same variable from multiple apps causes some seg fault at the moment, shoudn't we throw an error if it exists, rather than checking the type?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that Kratos should be able to support registering the same variable from multiple applications, as long as the type is the same. Using the registry in this way would be a step in that direction, since users of the registry are sure to always get the same thing when retrieving a given variable (something that is not so clear with components if Kratos allows overwriting variables as is happening now).

Comment on lines +322 to +332
void KratosApplication::DeregisterVariables() {
const std::string path = "variables."+mApplicationName;
if (Registry::HasItem(path)) {
auto& r_variables = Registry::GetItem(path);
// Iterate over items at path. For each item, remove it from the mappers.all branch too
for (auto i_key = r_variables.KeyConstBegin(); i_key != r_variables.KeyConstEnd(); ++i_key) {
Registry::RemoveItem("variables.all."+*i_key);
}
Registry::RemoveItem(path);
}
}
Copy link
Member

@sunethwarna sunethwarna Jul 18, 2024

Choose a reason for hiding this comment

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

This removes the variables registered by the application from the all, hence we don't allow registering same variable from multiple apps. So, I would as mentioned in the earlier comment, throw an error if the same variable name is registered from multiple places.

Copy link
Member Author

Choose a reason for hiding this comment

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

Please note that the scope of this PR is very narrow (it is intended only for testing, it is not a general "unload application" mechanism). What I am doing here is just ensuring that whoever registered the variable takes care of de-registering it, not ensuring that the kernel remains in a complete state after application de-registry. I understand that this is consistent with what the de-registration logic does for other types of objects.

@jcotela
Copy link
Member Author

jcotela commented Jul 18, 2024

Ok, it seems that this PR is not helping with the pipeline errors. We do need this capability it on the Altair side to avoid memory errors (since we have tests involving multiple applications and this becomes more of an issue), but we can work around it if it is not taken care of by the application de-registry automatically.

I will keep the PR open for a while for discussion.

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.

3 participants