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

Minimal stopping criteria config #1613

Merged
merged 5 commits into from
Feb 18, 2025
Merged

Minimal stopping criteria config #1613

merged 5 commits into from
Feb 18, 2025

Conversation

MarcelKoch
Copy link
Member

@MarcelKoch MarcelKoch commented May 17, 2024

This PR adds a minimal specification for configuring stopping criteria. The test now contains an example for this configuration. Since the main implementation to configure the criteria is already implemented, this adds only a bit of dispatching.

This is intended to continue the discussion in #1392, while not blocking the release.

Todo:

  • discuss the specification
  • test all allowed key-value pairs

The stopping criteria can now be defined as:

criteria:
  value_type: float32 # optional 
  # only one of the following is required 
  relative_residual_norm: 1e-6
  initial_residual_norm: 1e-6
  absolute_residual_norm: 1e-6
  relative_implicit_residual_norm: 1e-6
  initial_implicit_residual_norm: 1e-6
  absolute_implicit_residual_norm: 1e-6
  time: 1000

@MarcelKoch MarcelKoch self-assigned this May 17, 2024
@ginkgo-bot ginkgo-bot added reg:testing This is related to testing. mod:core This is related to the core module. type:solver This is related to the solvers labels May 17, 2024
@MarcelKoch MarcelKoch mentioned this pull request May 17, 2024
}

if (config.get_tag() == pnode::tag_t::map) {
return parse_minimal_criteria(config, context, td);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return parse_minimal_criteria(config, context, td);
auto updated = config::update_type(td);
return parse_minimal_criteria(config, context, updated);

It is to support no valuetype available outside

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'm not sure what you mean here. I can specify the value type of the residual nom criterion, as you can see in the tests.

Copy link
Member

Choose a reason for hiding this comment

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

It's based on the type_descriptor from the outer loop.
I mean something like

"stop": {
  "value_type": "float64",
  "residual_norm": ...
}

in case no precision information from outside or want to specify certain precision for stop.

Copy link
Member

Choose a reason for hiding this comment

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

following the above comment,

"stop": [
  {
    "type": "ResidualNorm",
    "value_type": "float32",
    ...
  }
]

in multigrid or some solver without precision information.
it can be mapped to

"stop": {
  "value_type": "float32",
  "residual_norm": ...
}

Copy link
Member

Choose a reason for hiding this comment

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

Or, we can say this rare case should use the map version not minimal version

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 will try a bit to make it work. If it's a reasonable effort I will adapt it.

Copy link
Member Author

Choose a reason for hiding this comment

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

It was pretty simple to add, so it's now available.

parse_or_get_criteria(const pnode& config, const registry& context,
const type_descriptor& td)
{
if (config.get_tag() == pnode::tag_t::array) {
Copy link
Member

Choose a reason for hiding this comment

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

The array can not accept 1 object now. you can use type to distinguish the path and reuse the parse_or_get_factory

@yhmtsai yhmtsai force-pushed the factory_config branch 2 times, most recently from 7735cc5 to 2629167 Compare May 27, 2024 09:22
Base automatically changed from factory_config to develop May 27, 2024 14:51
@MarcelKoch MarcelKoch force-pushed the minimal-stop-config branch from 0126f7d to 829b991 Compare May 29, 2024 07:49
@MarcelKoch MarcelKoch added the 1:ST:WIP This PR is a work in progress. Not ready for review. label Aug 15, 2024
@MarcelKoch MarcelKoch added this to the Ginkgo 1.9.0 milestone Aug 26, 2024
@MarcelKoch MarcelKoch modified the milestones: Ginkgo 1.9.0, Ginkgo 1.10.0 Dec 9, 2024
@MarcelKoch MarcelKoch marked this pull request as ready for review February 13, 2025 11:56
@fritzgoebel fritzgoebel self-requested a review February 13, 2025 11:57
}

if (config.get_tag() == pnode::tag_t::map) {
return parse_minimal_criteria(config, context, td);
Copy link
Member

Choose a reason for hiding this comment

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

following the above comment,

"stop": [
  {
    "type": "ResidualNorm",
    "value_type": "float32",
    ...
  }
]

in multigrid or some solver without precision information.
it can be mapped to

"stop": {
  "value_type": "float32",
  "residual_norm": ...
}

}

if (config.get_tag() == pnode::tag_t::map) {
return parse_minimal_criteria(config, context, td);
Copy link
Member

Choose a reason for hiding this comment

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

Or, we can say this rare case should use the map version not minimal version

@MarcelKoch MarcelKoch requested a review from yhmtsai February 13, 2025 15:08
@MarcelKoch MarcelKoch added 1:ST:ready-for-review This PR is ready for review and removed 1:ST:WIP This PR is a work in progress. Not ready for review. labels Feb 13, 2025
Copy link
Member

@yhmtsai yhmtsai left a comment

Choose a reason for hiding this comment

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

LGTM! only nit left is that the updated_td can reuse the existing function

Comment on lines 113 to 119
auto value_type_it = config.get_map().find("value_type");
type_descriptor updated_td =
value_type_it == config.get_map().end()
? td
: type_descriptor(value_type_it->second.get_string(),
td.get_local_index_typestr(),
td.get_global_index_typestr());
Copy link
Member

Choose a reason for hiding this comment

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

you can also use updated_td = config::update_type(td);

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the hint!

@MarcelKoch MarcelKoch added 1:ST:ready-to-merge This PR is ready to merge. and removed 1:ST:ready-for-review This PR is ready for review labels Feb 17, 2025
Copy link

codecov bot commented Feb 18, 2025

Codecov Report

Attention: Patch coverage is 98.16514% with 2 lines in your changes missing coverage. Please review.

Project coverage is 89.48%. Comparing base (efbf245) to head (d89b027).
Report is 2 commits behind head on develop.

Files with missing lines Patch % Lines
core/config/config_helper.cpp 94.87% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1613      +/-   ##
===========================================
+ Coverage    88.77%   89.48%   +0.70%     
===========================================
  Files          808      808              
  Lines        66686    66723      +37     
===========================================
+ Hits         59201    59706     +505     
+ Misses        7485     7017     -468     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@MarcelKoch MarcelKoch requested a review from yhmtsai February 18, 2025 08:22
Copy link
Member

@upsj upsj left a comment

Choose a reason for hiding this comment

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

LGTM!

MarcelKoch and others added 5 commits February 18, 2025 09:58
Signed-off-by: Marcel Koch <marcel.koch@kit.edu>
Signed-off-by: Marcel Koch <marcel.koch@kit.edu>
- allow changing the value_type
- fix docs
- call `parse_or_get_criteria` directly from solver config

Co-authored-by: Yu-Hsiang M. Tsai <yhmtsai@gmail.com>
@MarcelKoch MarcelKoch merged commit dcd910f into develop Feb 18, 2025
7 of 11 checks passed
@MarcelKoch MarcelKoch deleted the minimal-stop-config branch February 18, 2025 09:01
@ginkgo-bot
Copy link
Member

Error: PR already merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1:ST:ready-to-merge This PR is ready to merge. mod:core This is related to the core module. reg:testing This is related to testing. type:solver This is related to the solvers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants