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