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

add file config example with the configs #1662

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open

Conversation

yhmtsai
Copy link
Member

@yhmtsai yhmtsai commented Aug 6, 2024

This PR adds the example to show the solver configuration based on the file.
This PR aims to set up config close to the existing example without any registry usage.
Note. the stopping criterion is different among these configs.

  • cg.json: simple-solver
  • blockjacobi-cg.json: preconditioned-solver
  • ir.json: iterative-refinement
  • parilu.json: ilu-preconditioned-solver (by using factoization parameter directly)
  • pgm-multigrid-cg.json: multigrid-preconditioned-solver (set min_coarse_rows additionally due to this small example matrix)
  • mixed-pgm-multigrid-cg.json: mixed-multigrid-preconditioned-solver (assuming there are always more than one level)

There will be another one example to show the registry usage.

@yhmtsai yhmtsai added the 1:ST:ready-for-review This PR is ready for review label Aug 6, 2024
@yhmtsai yhmtsai requested review from a team August 6, 2024 09:31
@yhmtsai yhmtsai self-assigned this Aug 6, 2024
@ginkgo-bot ginkgo-bot added reg:build This is related to the build system. reg:example This is related to the examples. labels Aug 6, 2024
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.

LGTM. I would prefer the json files merged.

Copy link
Member

Choose a reason for hiding this comment

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

IMO, all json files should be merged, and the filenames should be keywords instead. I think that is more realistic for acutal usecases.

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 thought user usually swap the file to choose the solver, which gives less confusing.

Copy link
Member

Choose a reason for hiding this comment

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

I would think a single file is less confusing, since it's only one file, where the keys are the previous filenames, and you can add comments for each configuration. (Ofc not in JSON, but that is arguably not a good format for this use case anyway.)

Copy link
Member

Choose a reason for hiding this comment

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

After reading through this PR, I agree with @yhmtsai.
Having one file per configuration is much simpler because it makes it easier to swap them around.
Additionally, it is easier to understand when reading the code, which is important for this example.

examples/file-config-solver/build.sh Outdated Show resolved Hide resolved
examples/file-config-solver/file-config-solver.cpp Outdated Show resolved Hide resolved
Comment on lines +128 to +129
std::ifstream f(configfile);
std::cout << f.rdbuf() << 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.

You could output the json directly:

std::cout << std::setw(4) << nlohman::json::parse(configfile) << std::endl;

see: https://json.nlohmann.me/api/operator_ltlt/
Of course, it would make more sense if the json object was stored already before.

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 this information.
I will put it when we have the example with loading json object before

@MarcelKoch MarcelKoch added this to the Ginkgo 1.9.0 milestone Aug 26, 2024
Copy link
Member

@thoasm thoasm left a comment

Choose a reason for hiding this comment

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

Right now, I only comment until the discussion is resolved.
I would like all configuration files to be tested and part of the CI.
Other than that, I only have nits.

examples/file-config-solver/doc/tooltip Outdated Show resolved Hide resolved
examples/file-config-solver/file-config-solver.cpp Outdated Show resolved Hide resolved
examples/file-config-solver/file-config-solver.cpp Outdated Show resolved Hide resolved
examples/file-config-solver/file-config-solver.cpp Outdated Show resolved Hide resolved
examples/file-config-solver/file-config-solver.cpp Outdated Show resolved Hide resolved
examples/file-config-solver/file-config-solver.cpp Outdated Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

After reading through this PR, I agree with @yhmtsai.
Having one file per configuration is much simpler because it makes it easier to swap them around.
Additionally, it is easier to understand when reading the code, which is important for this example.

// mixed-pgm-multigrid-cg.json: mixed-multigrid-preconditioned-solver
// (assuming there are always more than one
// level)
auto config = gko::ext::config::parse_json_file(configfile);
Copy link
Member

Choose a reason for hiding this comment

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

My main concern is that this only tests a single file as part of our automatic tests. It doesn't check the other files, so we couldn't detect if we broke the compatibility.

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 am not sure whether using examples as kind of integration test is a good idea.
I have add the test to check they can be runnable

@@ -20,6 +20,7 @@ set(EXAMPLES_EXEC_LIST
set(EXAMPLES_LIST
${EXAMPLES_EXEC_LIST}
custom-stopping-criterion
file-config-solver
Copy link
Member

Choose a reason for hiding this comment

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

Does this mean they are not run as part of our CI?
Is there a reason why we don't?

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 have added test which only checks it can run properly.

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 do not reuse the existing one because it needs to accept additional parameter

yhmtsai and others added 2 commits September 9, 2024 22:06
Co-authored-by: Marcel Koch <marcel.koch@kit.edu>
Co-authored-by: Thomas Grützmacher <thomas.gruetzmacher@kit.edu>
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.

I still think that

  1. JSON is not the right format
  2. The files should be combined, and annotated with comments

But I won't hold up the PR.

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.

you also need to add the file to doc/examples/examples.hpp.in

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 reg:build This is related to the build system. reg:example This is related to the examples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants