| 198 | |
| 199 | |
| 200 | class ChunkBalancerTest(unittest.TestCase): |
| 201 | @parameterized.parameterized.expand( |
| 202 | [ |
| 203 | (TEST_SIM_1, False), |
| 204 | (TEST_SIM_DUPLICATE_PROC_ID, True), |
| 205 | ] |
| 206 | ) |
| 207 | def test_validate_sim(self, test_sim_constructor, should_raise_exception): |
| 208 | test_sim = test_sim_constructor() |
| 209 | test_sim.init_sim() |
| 210 | |
| 211 | chunk_balancer = ChunkBalancer() |
| 212 | |
| 213 | if should_raise_exception: |
| 214 | with self.assertRaises(ValueError): |
| 215 | chunk_balancer._validate_sim(test_sim) |
| 216 | else: |
| 217 | chunk_balancer._validate_sim(test_sim) |
| 218 | |
| 219 | @parameterized.parameterized.expand( |
| 220 | [ |
| 221 | (TEST_SIM_1,), |
| 222 | (TEST_SIM_2,), |
| 223 | (TEST_SIM_3,), |
| 224 | (TEST_SIM_4,), |
| 225 | ] |
| 226 | ) |
| 227 | def test_chunk_layout_improvement(self, test_sim_constructor): |
| 228 | """Tests that chunk_balancer improves balance after 1 iteration.""" |
| 229 | test_sim = test_sim_constructor() |
| 230 | test_sim.init_sim() |
| 231 | |
| 232 | old_timing_measurements = MeepTimingMeasurements.new_from_simulation( |
| 233 | test_sim, -1 |
| 234 | ) |
| 235 | |
| 236 | chunk_balancer = ChunkBalancer() |
| 237 | |
| 238 | chunk_balancer.adjust_chunk_layout(test_sim, sensitivity=1.0) |
| 239 | |
| 240 | new_timing_measurements = MeepTimingMeasurements.new_from_simulation( |
| 241 | test_sim, -1 |
| 242 | ) |
| 243 | |
| 244 | old_step_times = np.array(old_timing_measurements.measurements["time_stepping"]) |
| 245 | new_step_times = np.array(new_timing_measurements.measurements["time_stepping"]) |
| 246 | |
| 247 | old_max_time = np.max(old_step_times) |
| 248 | new_max_time = np.max(new_step_times) |
| 249 | |
| 250 | old_min_time = np.min(old_step_times) |
| 251 | new_min_time = np.min(new_step_times) |
| 252 | |
| 253 | self.assertLess(new_max_time, old_max_time) |
| 254 | self.assertGreater(new_min_time, old_min_time) |
| 255 | |
| 256 | @parameterized.parameterized.expand( |
| 257 | [ |
nothing calls this directly
no outgoing calls
no test coverage detected