Simulator checkpointing
Simulator Integration for Checkpointing
This module provides the integration layer between the JUNE simulator and the checkpointing system, offering methods for checkpoint creation and restoration during simulation runs.
SimulatorCheckpointing
Interface for checkpoint operations during simulation.
This class provides methods for creating and restoring checkpoints from within the simulation loop.
Source code in june/checkpointing/simulator_checkpointing.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
|
__init__(simulator, checkpoint_dir='checkpoints', checkpoint_read_dir=None, auto_checkpoint_interval=None, checkpoint_dates=None)
Initialise simulator checkpointing.
Parameters
simulator : Simulator The JUNE simulator instance checkpoint_dir : str Base directory for storing/writing checkpoints checkpoint_read_dir : str, optional Directory for reading existing checkpoints from (defaults to checkpoint_dir) auto_checkpoint_interval : float Automatic checkpoint interval in simulation days (only used in automatic mode) checkpoint_dates : list Specific simulation days when checkpoints should be created
Source code in june/checkpointing/simulator_checkpointing.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
|
create_checkpoint(checkpoint_name=None)
Create a simulation checkpoint.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
checkpoint_name
|
Optional[str]
|
Name for the checkpoint directory. If None, auto-generated. (Default value = None) |
None
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if checkpoint creation was successful |
Source code in june/checkpointing/simulator_checkpointing.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
|
disable_auto_checkpoints()
Disable automatic checkpoint creation.
Source code in june/checkpointing/simulator_checkpointing.py
335 336 337 338 |
|
enable_auto_checkpoints(interval_days=7.0)
Enable automatic checkpoint creation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
interval_days
|
float
|
Interval between automatic checkpoints in simulation days (Default value = 7.0) |
7.0
|
Source code in june/checkpointing/simulator_checkpointing.py
324 325 326 327 328 329 330 331 332 333 |
|
list_available_checkpoints()
List all available checkpoints.
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
List of available checkpoint information |
Source code in june/checkpointing/simulator_checkpointing.py
314 315 316 317 318 319 320 321 322 |
|
restore_from_checkpoint(checkpoint_name)
Restore simulation from a checkpoint.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
checkpoint_name
|
str
|
Name of the checkpoint directory to restore from |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if restoration was successful |
Source code in june/checkpointing/simulator_checkpointing.py
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
|
restore_from_latest_checkpoint()
Restore from the most recent checkpoint.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if restoration was successful |
Source code in june/checkpointing/simulator_checkpointing.py
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
|
should_create_checkpoint()
Check if an automatic checkpoint should be created now.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if a checkpoint should be created |
Source code in june/checkpointing/simulator_checkpointing.py
209 210 211 212 213 214 215 216 217 218 219 220 221 |
|
add_checkpointing_from_config(simulator, config_path, checkpoint_dir='checkpoints')
Add checkpointing capabilities to simulator using configuration file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulator
|
Simulator
|
The JUNE simulator instance |
required |
config_path
|
str
|
Path to the YAML configuration file |
required |
checkpoint_dir
|
str
|
Directory for storing checkpoints (Default value = "checkpoints") |
'checkpoints'
|
Returns:
Name | Type | Description |
---|---|---|
SimulatorCheckpointing |
SimulatorCheckpointing
|
The checkpointing interface object |
Source code in june/checkpointing/simulator_checkpointing.py
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 |
|
add_checkpointing_from_config_with_directories(simulator, config_path, checkpoint_read_dir='checkpoints', checkpoint_write_dir='checkpoints')
Add checkpointing capabilities to simulator with separate read/write directories.
This version supports checkpoint chaining by allowing child runs to read from parent checkpoints while writing new checkpoints to their own directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulator
|
Simulator
|
The JUNE simulator instance |
required |
config_path
|
str
|
Path to the YAML configuration file |
required |
checkpoint_read_dir
|
str
|
Directory for reading existing checkpoints from (parent's directory for child runs) (Default value = "checkpoints") |
'checkpoints'
|
checkpoint_write_dir
|
str
|
Directory for writing new checkpoints to (child's own directory) (Default value = "checkpoints") |
'checkpoints'
|
Returns:
Name | Type | Description |
---|---|---|
SimulatorCheckpointing |
SimulatorCheckpointing
|
The checkpointing interface object |
Source code in june/checkpointing/simulator_checkpointing.py
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 |
|
add_checkpointing_to_simulator(simulator, checkpoint_dir='checkpoints', auto_interval=None, checkpoint_dates=None)
Add checkpointing capabilities to an existing simulator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulator
|
Simulator
|
The JUNE simulator instance |
required |
checkpoint_dir
|
str
|
Directory for storing checkpoints (Default value = "checkpoints") |
'checkpoints'
|
auto_interval
|
float
|
Automatic checkpoint interval in simulation days (Default value = None) |
None
|
checkpoint_dates
|
list
|
Specific simulation days when checkpoints should be created (Default value = None) |
None
|
Returns:
Name | Type | Description |
---|---|---|
SimulatorCheckpointing |
SimulatorCheckpointing
|
The checkpointing interface object |
Source code in june/checkpointing/simulator_checkpointing.py
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 |
|
add_checkpointing_to_simulator_with_directories(simulator, checkpoint_read_dir='checkpoints', checkpoint_write_dir='checkpoints', auto_interval=None, checkpoint_dates=None)
Add checkpointing capabilities with separate read/write directories for checkpoint chaining.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulator
|
Simulator
|
The JUNE simulator instance |
required |
checkpoint_read_dir
|
str
|
Directory for reading existing checkpoints from (Default value = "checkpoints") |
'checkpoints'
|
checkpoint_write_dir
|
str
|
Directory for writing new checkpoints to (Default value = "checkpoints") |
'checkpoints'
|
auto_interval
|
float
|
Automatic checkpoint interval in simulation days (Default value = None) |
None
|
checkpoint_dates
|
list
|
Specific simulation days when checkpoints should be created (Default value = None) |
None
|
Returns:
Name | Type | Description |
---|---|---|
SimulatorCheckpointing |
SimulatorCheckpointing
|
The checkpointing interface object |
Source code in june/checkpointing/simulator_checkpointing.py
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 |
|
integrate_checkpointing_in_simulation_loop(simulator_checkpointing, force_checkpoint=False)
Check and potentially create a checkpoint during simulation loop.
This function should be called within the main simulation time step loop.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulator_checkpointing
|
SimulatorCheckpointing
|
The checkpointing interface |
required |
force_checkpoint
|
bool
|
Force creation of a checkpoint regardless of interval (Default value = False) |
False
|
Returns:
Name | Type | Description |
---|---|---|
bool |
True if a checkpoint was created |
Source code in june/checkpointing/simulator_checkpointing.py
626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 |
|
parse_checkpoint_config_from_yaml(config_path, simulator)
Parse checkpoint configuration from YAML file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config_path
|
str
|
Path to the YAML configuration file |
required |
simulator
|
Simulator
|
The JUNE simulator instance to get initial date |
required |
Returns:
Name | Type | Description |
---|---|---|
tuple |
tuple
|
(checkpoint_dates: List[float] or None, interval_days: float) |
tuple
|
checkpoint_dates is None for automatic interval mode, empty list for no checkpoints |
Source code in june/checkpointing/simulator_checkpointing.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
|
print_validation_summary(simulator, stage='FINAL')
Print key numerical metrics for validation comparison.
This function prints standardised metrics that can be easily compared between continuous runs and checkpoint/restore runs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulator
|
Simulator
|
The JUNE simulator instance |
required |
stage
|
str
|
Stage identifier (e.g., "AT_CHECKPOINT", "AFTER_RESTORE", "FINAL") (Default value = "FINAL") |
'FINAL'
|
Source code in june/checkpointing/simulator_checkpointing.py
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 |
|