Skip to content

Conversation

@upsj
Copy link
Member

@upsj upsj commented Nov 10, 2025

This replaces typed stopping criteria like

.with_criteria(gko::stop::ResidualNorm<float>::build().with_baseline(gko::stop::mode::absolute).with_reduction_factor(1e-5))

by the simpler

.with_criteria(gko::stop::abs_residual_norm(1e-5))

@upsj upsj requested a review from a team November 10, 2025 15:43
@upsj upsj self-assigned this Nov 10, 2025
@ginkgo-bot ginkgo-bot added reg:testing This is related to testing. mod:core This is related to the core module. mod:reference This is related to the reference module. type:solver This is related to the solvers type:stopping-criteria This is related to the stopping criteria labels Nov 10, 2025
@MarcelKoch MarcelKoch added this to the Ginkgo 1.11 milestone Nov 13, 2025
@upsj upsj marked this pull request as ready for review November 13, 2025 10:35
@MarcelKoch
Copy link
Member

Note: ensure that the naming is the same as for the config parameters, see #1613

@upsj upsj force-pushed the simpler_stop_interface branch from e45cab5 to b6bfe6e Compare November 14, 2025 13:39
@upsj upsj added the 1:ST:ready-for-review This PR is ready for review label Nov 14, 2025
@MarcelKoch MarcelKoch self-requested a review November 14, 2025 13:47

#include "ginkgo/core/stop/iteration.hpp"

#include "ginkgo/core/base/abstract_factory.hpp"
Copy link
Member Author

Choose a reason for hiding this comment

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

a few of the headers need fixing

upsj and others added 3 commits November 20, 2025 13:46
- rename functions to match configuration keys
- add documentation
- add missing tests

Co-authored-by: Marcel Koch <[email protected]>
Co-authored-by: Yu-Hsiang M. Tsai <[email protected]>
@upsj upsj force-pushed the simpler_stop_interface branch from f33c0d0 to 89fe7e0 Compare November 20, 2025 12:46
Copy link
Member

@MarcelKoch MarcelKoch left a comment

Choose a reason for hiding this comment

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

Only the testing of the correct dynamic type of the resulting residual stopping criterion is required. The rest are suggestions.

};


TEST_F(Iteration, NewInterface)
Copy link
Member

Choose a reason for hiding this comment

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

nit: this test could probably have a more descriptive name, e.g. SimplifiedInterface as the other ones, or FreeFunctionInterface.

auto crit_red =
gko::as<gko::stop::ResidualNorm<TypeParam>>(factory_red->generate(
nullptr, rhs, initial_guess.get(), initial_res.get()));

Copy link
Member

Choose a reason for hiding this comment

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

nit:

Suggested change

Comment on lines +525 to +533
auto crit_abs =
gko::as<gko::stop::ResidualNorm<TypeParam>>(factory_abs->generate(
nullptr, rhs, initial_guess.get(), initial_res.get()));
auto crit_rel =
gko::as<gko::stop::ResidualNorm<TypeParam>>(factory_rel->generate(
nullptr, rhs, initial_guess.get(), initial_res.get()));
auto crit_red =
gko::as<gko::stop::ResidualNorm<TypeParam>>(factory_red->generate(
nullptr, rhs, initial_guess.get(), initial_res.get()));
Copy link
Member

Choose a reason for hiding this comment

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

This should probably also be part of the Assert block. Especially since the value type is determined by the input arguments.

}


TYPED_TEST(ImplicitResidualNorm, SimplifiedInterface)
Copy link
Member

Choose a reason for hiding this comment

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

same here.

}


TEST_F(Time, CanCreateFactoryNewInterface)
Copy link
Member

Choose a reason for hiding this comment

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

nit: consistent naming

struct residual_norm_factory_parameters
: public enable_parameters_type<residual_norm_factory_parameters,
ResidualNormFactory> {
double GKO_FACTORY_PARAMETER_SCALAR(threshold, 0.0);
Copy link
Member

Choose a reason for hiding this comment

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

nit: maybe call this reduction_factor to be consistent with the original residual norm parameters.

}
result = ResidualNorm<value_type>::build()
.with_baseline(this->parameters_.baseline)
.with_reduction_factor(this->parameters_.threshold)
Copy link
Member

Choose a reason for hiding this comment

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

nit:

Suggested change
.with_reduction_factor(this->parameters_.threshold)
.with_reduction_factor(cast_threshold)

};


class ImplicitResidualNormFactory
Copy link
Member

Choose a reason for hiding this comment

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

If you want to reduce code duplication between this and the ResidualNormFactory, you could add a template for the actual stopping criteria type.

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

Labels

1:ST:ready-for-review This PR is ready for review mod:core This is related to the core module. mod:reference This is related to the reference module. reg:testing This is related to testing. type:solver This is related to the solvers type:stopping-criteria This is related to the stopping criteria

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants