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

Big rework of P3 around new BFB baseline unit tests #3096

Merged
merged 30 commits into from
Nov 12, 2024

Conversation

jgfouca
Copy link
Member

@jgfouca jgfouca commented Nov 5, 2024

This turned into a huge PR.

Change list:

  1. Main change: For all the BFB P3 unit tests, use baseline files instead of calling fortran!
  2. Remove most of the CXX->f90 bridge code
  3. Cleanup of very confusing p3_init situation. It's just another p3::Function now.
  4. Reorg by moving some less-interesting testing stuff into p3/tests/infra. Now, the files presented in the public interface (just p3 directory) is a lot cleaner.
  5. All p3 tests (bfb and run_and_cmp) accept the same set of arguments (-c for compare, -g for generate, -b for baseline dir, and -n for no baselines).
  6. Some of the tests that just confirm that DIFFs are caught do need to do thread count spreads.
  7. Refactor some of the PhysicsTestData macro stuff to be much cleaner.
  8. All PhysicsTestData structs now know how to read/write themselves.

Follow on work:

  1. I think the last of the fortran, the p3_init stuff, should be converted to CXX
  2. If people are happy with this new pattern, we need to apply it to SHOC.

Notes:

  1. With this change, we are no longer testing different random seeds each night. The need to match the baseline file means we have to use fixed seeds. (This has been somewhat mitigated thanks to suggestion from Luca that we can use a random seen when generating or doing no comparison).

@AaronDonahue
Copy link
Contributor

This is great @jgfouca! Thanks for putting this together.

@jgfouca
Copy link
Member Author

jgfouca commented Nov 5, 2024

@AaronDonahue , thanks! My fingers are bleeding but I'm quite happy with the result.

mahf708
mahf708 previously approved these changes Nov 6, 2024
Copy link
Contributor

@mahf708 mahf708 left a comment

Choose a reason for hiding this comment

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

skimmed it and looks good to me. v excited for the future

i defer to others more involved in the creation of the tests to weigh in

bartgol
bartgol previously approved these changes Nov 7, 2024
Copy link
Contributor

@bartgol bartgol left a comment

Choose a reason for hiding this comment

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

Looks good. From what I can tell, we are replacing Fortran data with data from baselines, and then everything else is somewhat the same as before right?

@@ -26,4 +26,21 @@ PhysicsTestData& PhysicsTestData::assignment_impl(const PhysicsTestData& rhs)
return *this;
}

void PhysicsTestData::read(const ekat::FILEPtr& fid)
Copy link
Contributor

Choose a reason for hiding this comment

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

At some point we should get rid of the ekat FILEPtr data structure and work directly with fstream from the std library...

@jgfouca
Copy link
Member Author

jgfouca commented Nov 7, 2024

@bartgol , yes. You can look at the change list in the PR description for the summation of what changed because this PR is probably too big to review in the source code.

@bartgol
Copy link
Contributor

bartgol commented Nov 7, 2024

  1. With this change, we are no longer testing different random seeds each night. The need to match the baseline file means we have to use fixed seeds.

Do you think there would be added value in doing

  • use a random seed when we generate baselines
  • when doing cmp, start by loading the rng seed from the baseline file

? It would only make us change rand seed when we regen baselines, but maybe on the long run it may help uncover hidden bugs?

ambrad
ambrad previously approved these changes Nov 7, 2024
@bartgol
Copy link
Contributor

bartgol commented Nov 7, 2024

@jgfouca just to make sure you noticed it: the FPE build fails, and since that should have no baselines tests, it means something is really off.

@jgfouca
Copy link
Member Author

jgfouca commented Nov 7, 2024

@bartgol ,

Do you think there would be added value in doing
use a random seed when we generate baselines
when doing cmp, start by loading the rng seed from the baseline file

That's a really good idea.

@jgfouca jgfouca dismissed stale reviews from ambrad, bartgol, and mahf708 via abf91a6 November 7, 2024 23:04
scream::p3::P3GlobalForFortran::deinit();
}

std::mt19937_64 get_engine()
Copy link
Member Author

Choose a reason for hiding this comment

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

@bartgol , I added the feature you wanted here.

Copy link
Contributor

@bartgol bartgol left a comment

Choose a reason for hiding this comment

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

I think the way we pass parameters to p3_tests needs to be changed.

if (SCREAM_ENABLE_BASELINE_TESTS)
CreateUnitTest (p3_sk_tests_fail p3_rain_sed_unit_tests.cpp
LIBS p3_sk p3_test_infra
EXE_ARGS "--flags=\\'${BASELINE_FILE_ARG}\\'"
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure this is the way --flags is to be used in ekat's test main. This is meant to be used for stuff like "verbose", and is meant to set a "bool" in the test session. Here, you are trying to pass actual executable flags, but catch2 will likely complain about them, since they are not recognized.

Copy link
Contributor

Choose a reason for hiding this comment

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

For run_and_cmp, this works b/c it uses its own main. Here, we need to work around it.

  • For boolean, you can use stuff like --flags generate,verbose, which will set "verbose" and "generate" as valid keys in the map string->bool in the test session
  • For args that are not boolean, we need to use --ekat-test-params (which I want to sometime shorten to --params), and the syntax could be --ekat-test-params baseline-dir=${SCREAM_BASELINES_DIR}/data.

Copy link
Contributor

Choose a reason for hiding this comment

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

I tried a simple program that prints the test session flags/params:

  std::cout << "flags:\n";
  for (auto it : ts.flags) {
    std::cout << it.first << " -> " << it.second << "\n";
  }
  std::cout << "params:\n";
  for (auto it : ts.params) {
    std::cout << it.first << " -> " << it.second << "\n";
  }
  std::cout << "DONE!\n";

I got

$ ./test --flags='-c -b /path/to/something'
Calling initialize_kokkos
 ExecSpace name: Serial
 ExecSpace initialized: yes
 active avx set: -AVX512F-AVX2-AVX
 compiler id: GCC
 FPE support is disabled
 #host threads: 1

Starting catch session on rank 0 out of 1
flags:
-c -b /path/to/something -> 1
params:
DONE!

Copy link
Contributor

Choose a reason for hiding this comment

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

The core pb is that catch2 does not let you pass arbitrary flags. So I had to come up with the whole --flags f1,f2,f3 --ekat-test-params p1=v1,p2=v2,p3=v3 syntax...

…_f90

* origin/master: (64 commits)
  EAMxx: adapt to changes in ekat's catch main logic
  Update ekat submodule
  Update .mergify.yml
  EAMxx: fix query-scream util script
  Update .mergify.yml
  Workflows: nano-fixes to eamxx workflows
  Mergify: fix syntax
  ci(Mergify): configuration update
  Workflows: reworked how to skip eamxx testing jobs
  Workflows: added more eamxx workflows
  Workflows: fix logic for eamxx jobs skipping
  Workflows: allow to generate ALL baselines at ones for eamxx
  EAMxx: Use the main branch of mam4xx.
  EAMxx: Add tracer_reader_utils.hpp to microphysics.hpp.
  EAMxx: Remove temporary CPP macro.
  EAMxx: Update description of dry aerosol particle diameters.
  EAMxx: Use a temporary branch for mam4xx to test changes in the photo table code.
  EAMxx: Move read utils files to readfiles folder.
  EAMxx: Refine linoz parameter handling and class member references
  Correcting data types for variables, refining comments, and updating YAML input configurations.
  ...
Copy link
Contributor

mergify bot commented Nov 11, 2024

Merge Protections

Your pull request matches the following merge protections and will not be merged until they are valid.

🔴 Enforce checks passing

This rule is failing.

Make sure that checks are not failing on the PR, and reviewers approved

  • any of:
    • check-skipped="gcc-openmp / dbg"
    • check-success="gcc-openmp / dbg"
  • any of:
    • check-skipped="gcc-openmp / sp"
    • check-success="gcc-openmp / sp"
  • any of:
    • check-skipped="gcc-openmp / opt"
    • check-success="gcc-openmp / opt"
  • any of:
    • check-skipped="gcc-cuda / dbg"
    • check-success="gcc-cuda / dbg"
  • any of:
    • check-skipped="gcc-cuda / sp"
    • check-success="gcc-cuda / sp"
  • any of:
    • check-skipped="gcc-cuda / opt"
    • check-success="gcc-cuda / opt"
  • #approved-reviews-by >= 1
  • #changes-requested-reviews-by == 0
  • any of:
    • check-success="gcc-openmp / fpe"
    • check-skipped="gcc-openmp / fpe"
  • any of:
    • check-success="cpu-gcc / ERS_Ln9.ne4_ne4.F2000-SCREAMv1-AQP1.scream-output-preset-2"
    • check-skipped="cpu-gcc / ERS_Ln9.ne4_ne4.F2000-SCREAMv1-AQP1.scream-output-preset-2"
  • any of:
    • check-success="cpu-gcc / ERS_P16_Ln22.ne30pg2_ne30pg2.FIOP-SCREAMv1-DP.scream-dpxx-arm97"
    • check-skipped="cpu-gcc / ERS_P16_Ln22.ne30pg2_ne30pg2.FIOP-SCREAMv1-DP.scream-dpxx-arm97"
  • any of:
    • check-success="cpu-gcc / ERS_Ln22.ne4pg2_ne4pg2.F2010-SCREAMv1.scream-small_kernels--scream-output-preset-5"
    • check-skipped="cpu-gcc / ERS_Ln22.ne4pg2_ne4pg2.F2010-SCREAMv1.scream-small_kernels--scream-output-preset-5"
  • any of:
    • check-success="cpu-gcc / SMS_D_Ln5.ne4pg2_oQU480.F2010-SCREAMv1-MPASSI.scream-mam4xx-all_mam4xx_procs"
    • check-skipped="cpu-gcc / SMS_D_Ln5.ne4pg2_oQU480.F2010-SCREAMv1-MPASSI.scream-mam4xx-all_mam4xx_procs"
  • any of:
    • check-skipped=cpu-gcc
    • check-success=cpu-gcc

@jgfouca jgfouca requested a review from bartgol November 12, 2024 17:14
@jgfouca
Copy link
Member Author

jgfouca commented Nov 12, 2024

All the fails are expected due to missing baselines.

@jgfouca jgfouca merged commit 12ed756 into master Nov 12, 2024
11 of 18 checks passed
@jgfouca jgfouca deleted the jgfouca/bfb_unit_no_f90 branch November 12, 2024 17:44
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.

5 participants