|
| 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 | +from lark.exceptions import UnexpectedCharacters, UnexpectedEOF |
| 6 | + |
| 7 | +from access.parsers.mom_profiling import MOM5ProfilingParser, MOM6ProfilingParser |
| 8 | + |
| 9 | + |
| 10 | +@pytest.fixture(scope="module") |
| 11 | +def mom5_parser(): |
| 12 | + """Fixture instantiating the MOM5 parser.""" |
| 13 | + return MOM5ProfilingParser() |
| 14 | + |
| 15 | + |
| 16 | +@pytest.fixture(scope="module") |
| 17 | +def mom6_parser(): |
| 18 | + """Fixture instantiating the MOM6 parser.""" |
| 19 | + return MOM6ProfilingParser() |
| 20 | + |
| 21 | + |
| 22 | +@pytest.fixture(scope="module") |
| 23 | +def mom5_profiling(): |
| 24 | + """Fixture returning a dict holding the parsed content of a mom6_input file.""" |
| 25 | + return { |
| 26 | + "region": [ |
| 27 | + "Total runtime", |
| 28 | + "Ocean", |
| 29 | + "(Ocean initialization)", |
| 30 | + "(Ocean ODA)", |
| 31 | + "(Red Sea/Gulf Bay salinity fix)", |
| 32 | + "OASIS init", |
| 33 | + "oasis_recv", |
| 34 | + "oasis_send", |
| 35 | + ], |
| 36 | + "tmin": [16282.797785, 15969.542784, 4.288529, 0.0, 0.024143, 0.231678, 168.797136, 2.468914], |
| 37 | + "tmax": [16282.797792, 16000.704550, 4.296586, 0.0, 0.077235, 0.232671, 171.648384, 2.756777], |
| 38 | + "tavg": [16282.797789, 15986.765795, 4.291991, 0.0, 0.040902, 0.232397, 170.460762, 2.593809], |
| 39 | + "tstd": [0.000001, 8.643639, 0.001470, 0.0, 0.013836, 0.000242, 0.650894, 0.079459], |
| 40 | + } |
| 41 | + |
| 42 | + |
| 43 | +@pytest.fixture(scope="module") |
| 44 | +def mom5_log_file(): |
| 45 | + """Fixture returning the timing content of a mom5 log file.""" |
| 46 | + return """ MPP_DOMAINS_STACK high water mark= 747000 |
| 47 | +
|
| 48 | +Tabulating mpp_clock statistics across 49 PEs... |
| 49 | +
|
| 50 | + tmin tmax tavg tstd tfrac grain pemin pemax |
| 51 | +Total runtime 16282.797785 16282.797792 16282.797789 0.000001 1.000 0 0 48 |
| 52 | +Ocean 15969.542784 16000.704550 15986.765795 8.643639 0.982 1 0 48 |
| 53 | +(Ocean initialization) 4.288529 4.296586 4.291991 0.001470 0.000 11 0 48 |
| 54 | +(Ocean ODA) 0.000000 0.000000 0.000000 0.000000 0.000 11 0 48 |
| 55 | +(Red Sea/Gulf Bay salinity fix) 0.024143 0.077235 0.040902 0.013836 0.000 31 0 48 |
| 56 | +OASIS init 0.231678 0.232671 0.232397 0.000242 0.000 1 0 48 |
| 57 | +oasis_recv 168.797136 171.648384 170.460762 0.650894 0.010 31 0 48 |
| 58 | +oasis_send 2.468914 2.756777 2.593809 0.079459 0.000 31 0 48 |
| 59 | + MPP_STACK high water mark= 0 |
| 60 | + MOM5: --- completed --- |
| 61 | +""" |
| 62 | + |
| 63 | + |
| 64 | +@pytest.fixture(scope="module") |
| 65 | +def mom6_profiling(): |
| 66 | + """Fixture returning a dict holding the parsed content of a mom6_input file.""" |
| 67 | + return { |
| 68 | + "region": [ |
| 69 | + "Total runtime", |
| 70 | + "Initialization", |
| 71 | + "Main loop", |
| 72 | + "Termination", |
| 73 | + "Ocean Initialization", |
| 74 | + "Ocean", |
| 75 | + "Ocean dynamics", |
| 76 | + "Ocean thermodynamics and tracers", |
| 77 | + "Ocean grid generation and remapp", |
| 78 | + "Ocean Other", |
| 79 | + "(Ocean tracer advection)", |
| 80 | + ], |
| 81 | + "hits": [1, 1, 1, 1, 2, 24, 192, 72, 0, 192, 48], |
| 82 | + "tmin": [ |
| 83 | + 100.641190, |
| 84 | + 0.987726, |
| 85 | + 98.930085, |
| 86 | + 0.718969, |
| 87 | + 1.529830, |
| 88 | + 98.279247, |
| 89 | + 84.799971, |
| 90 | + 11.512013, |
| 91 | + 0.0, |
| 92 | + 1.710326, |
| 93 | + 4.427230, |
| 94 | + ], |
| 95 | + "tmax": [ |
| 96 | + 100.641190, |
| 97 | + 0.987726, |
| 98 | + 98.930085, |
| 99 | + 0.718969, |
| 100 | + 1.529830, |
| 101 | + 98.279247, |
| 102 | + 84.799971, |
| 103 | + 11.512013, |
| 104 | + 0.0, |
| 105 | + 1.710326, |
| 106 | + 4.427230, |
| 107 | + ], |
| 108 | + "tavg": [ |
| 109 | + 100.641190, |
| 110 | + 0.987726, |
| 111 | + 98.930085, |
| 112 | + 0.718969, |
| 113 | + 1.529830, |
| 114 | + 98.279247, |
| 115 | + 84.799971, |
| 116 | + 11.512013, |
| 117 | + 0.000000, |
| 118 | + 1.710326, |
| 119 | + 4.427230, |
| 120 | + ], |
| 121 | + "tstd": [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], |
| 122 | + } |
| 123 | + |
| 124 | + |
| 125 | +@pytest.fixture(scope="module") |
| 126 | +def mom6_log_file(): |
| 127 | + """Fixture returning the timing content of a mom6 log file.""" |
| 128 | + return """ MPP_DOMAINS_STACK high water mark= 380512 |
| 129 | +
|
| 130 | +Tabulating mpp_clock statistics across 1 PEs... |
| 131 | +
|
| 132 | + hits tmin tmax tavg tstd tfrac grain pemin pemax |
| 133 | +Total runtime 1 100.641190 100.641190 100.641190 0.000000 1.000 0 0 0 |
| 134 | +Initialization 1 0.987726 0.987726 0.987726 0.000000 0.010 0 0 0 |
| 135 | +Main loop 1 98.930085 98.930085 98.930085 0.000000 0.983 0 0 0 |
| 136 | +Termination 1 0.718969 0.718969 0.718969 0.000000 0.007 0 0 0 |
| 137 | +Ocean Initialization 2 1.529830 1.529830 1.529830 0.000000 0.015 11 0 0 |
| 138 | +Ocean 24 98.279247 98.279247 98.279247 0.000000 0.977 1 0 0 |
| 139 | +Ocean dynamics 192 84.799971 84.799971 84.799971 0.000000 0.843 11 0 0 |
| 140 | +Ocean thermodynamics and tracers 72 11.512013 11.512013 11.512013 0.000000 0.114 11 0 0 |
| 141 | +Ocean grid generation and remapp 0 0.000000 0.000000 0.000000 0.000000 0.000 11 0 0 |
| 142 | +Ocean Other 192 1.710326 1.710326 1.710326 0.000000 0.017 11 0 0 |
| 143 | +(Ocean tracer advection) 48 4.427230 4.427230 4.427230 0.000000 0.044 21 0 0 |
| 144 | + MPP_STACK high water mark= 0 |
| 145 | +""" |
| 146 | + |
| 147 | + |
| 148 | +def test_mom5_profiling(mom5_parser, mom5_log_file, mom5_profiling): |
| 149 | + """Test the correct parsing of MOM5 timing information.""" |
| 150 | + mom5_parsed_log = mom5_parser.read(mom5_log_file) |
| 151 | + for idx, region in enumerate(mom5_profiling.keys()): |
| 152 | + assert region in mom5_parsed_log, f"{region} not found in mom5 parsed log" |
| 153 | + for metric in ("tmin", "tmax", "tavg", "tstd"): |
| 154 | + assert ( |
| 155 | + mom5_profiling[metric][idx] == mom5_parsed_log[metric][idx] |
| 156 | + ), f"Incorrect {metric} for region {region} (idx: {idx})." |
| 157 | + |
| 158 | + |
| 159 | +def test_mom6_profiling(mom6_parser, mom6_log_file, mom6_profiling): |
| 160 | + """Test the correct parsing of MOM6 timing information.""" |
| 161 | + mom6_parsed_log = mom6_parser.read(mom6_log_file) |
| 162 | + for idx, region in enumerate(mom6_profiling.keys()): |
| 163 | + assert region in mom6_parsed_log, f"{region} not found in mom6 parsed log" |
| 164 | + for metric in ("hits", "tmin", "tmax", "tavg", "tstd"): |
| 165 | + assert ( |
| 166 | + mom6_profiling[metric][idx] == mom6_parsed_log[metric][idx] |
| 167 | + ), f"Incorrect {metric} for region {region} (idx: {idx})." |
0 commit comments