|
| 1 | +# Copyright 2025 ACCESS-NRI and contributors. See the top-level COPYRIGHT file for details. |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +import pytest |
| 5 | + |
| 6 | +from access.parsers.cice5_profiling import CICE5ProfilingParser |
| 7 | + |
| 8 | + |
| 9 | +@pytest.fixture(scope="module") |
| 10 | +def cice5_required_metrics(): |
| 11 | + return ("min", "max", "mean") |
| 12 | + |
| 13 | +@pytest.fixture(scope="module") |
| 14 | +def cice5_parser(): |
| 15 | + """Fixture instantiating the CICE5 parser.""" |
| 16 | + return CICE5ProfilingParser() |
| 17 | + |
| 18 | + |
| 19 | +@pytest.fixture(scope="module") |
| 20 | +def cice5_profiling(): |
| 21 | + """Fixture returning a dict holding the parsed FMS timing content without hits.""" |
| 22 | + return { |
| 23 | + "region": ["Total", "TimeLoop"], |
| 24 | + "min": [16197.42, 16197.14], |
| 25 | + "max": [16197.47, 16197.19], |
| 26 | + "mean": [16197.44, 16197.16], |
| 27 | + } |
| 28 | + |
| 29 | + |
| 30 | +@pytest.fixture(scope="module") |
| 31 | +def cice5_log_file(): |
| 32 | + """Fixture returning the CICE5 timing content.""" |
| 33 | + return """ -------------------------------- |
| 34 | + CICE model diagnostic output |
| 35 | + -------------------------------- |
| 36 | + |
| 37 | + Document ice_in namelist parameters: |
| 38 | + ==================================== |
| 39 | + |
| 40 | + runtype = continue |
| 41 | + Restart read/written 17520 58159382400.0000 |
| 42 | + 0.000000000000000E+000 |
| 43 | +
|
| 44 | +Timing information: |
| 45 | +
|
| 46 | +Timer 1: Total 16197.47 seconds |
| 47 | + Timer stats (node): min = 16197.42 seconds |
| 48 | + max = 16197.47 seconds |
| 49 | + mean= 16197.44 seconds |
| 50 | + Timer stats(block): min = 0.00 seconds |
| 51 | + max = 0.00 seconds |
| 52 | + mean= 0.00 seconds |
| 53 | +Timer 2: TimeLoop 16197.19 seconds |
| 54 | + Timer stats (node): min = 16197.14 seconds |
| 55 | + max = 16197.19 seconds |
| 56 | + mean= 16197.16 seconds |
| 57 | + Timer stats(block): min = 0.00 seconds |
| 58 | + max = 0.00 seconds |
| 59 | + mean= 0.00 seconds |
| 60 | +""" |
| 61 | + |
| 62 | + |
| 63 | +def test_cice5_profiling(cice5_required_metrics, cice5_parser, cice5_log_file, cice5_profiling): |
| 64 | + """Test the correct parsing of CICE5 timing information.""" |
| 65 | + parsed_log = cice5_parser.read(cice5_log_file) |
| 66 | + |
| 67 | + # check metrics are present in parser and parsed output |
| 68 | + for metric in cice5_required_metrics: |
| 69 | + assert metric in cice5_parser.metrics, f"{metric} metric not found in CICE5 parser metrics." |
| 70 | + assert metric in parsed_log, f"{metric} metric not found in CICE5 parsed log." |
| 71 | + |
| 72 | + # check content for each metric is correct |
| 73 | + for idx, region in enumerate(cice5_profiling["region"]): |
| 74 | + assert region in parsed_log["region"], f"{region} not found in CICE5 parsed log" |
| 75 | + for metric in cice5_required_metrics: |
| 76 | + assert ( |
| 77 | + cice5_profiling[metric][idx] == parsed_log[metric][idx] |
| 78 | + ), f"Incorrect {metric} for region {region} (idx: {idx})." |
0 commit comments