libmuscle.api_guard module

class libmuscle.api_guard.APIGuard(uses_checkpointing: bool)[source]

Bases: object

Keeps track of and checks in which phase the model is.

The verify_* functions are called when the corresponding function on Instance is called, to check that we’re in the right phase. They raise a RuntimeError if there’s a problem. The *_done functions are called to signal that the corresponding function finished successfully, and that we are moving on to the next phase.

load_snapshot_done() None[source]

Update phase on successful load_snapshot()

resuming_done(resuming: bool) None[source]

Update phase on successful resuming().

Parameters:

resuming – Whether we’re resuming or not.

reuse_instance_done(reusing: bool) None[source]

Update phase on successful reuse_instance().

Parameters:

reusing – Whether we are reusing or not.

save_final_snapshot_done() None[source]

Updates state on successful save_final_snapshot()

save_snapshot_done() None[source]

Update phase on successful save_snapshot()

should_init_done() None[source]

Update phase on successful should_init()

should_save_final_snapshot_done(should_save: bool) None[source]

Update phase on successful should_save_snapshot().

Parameters:

should_save – Whether we should save or not.

should_save_snapshot_done(should_save: bool) None[source]

Update phase on successful should_save_snapshot().

Parameters:

should_save – Whether we should save or not.

verify_load_snapshot() None[source]

Check load_snapshot()

verify_resuming() None[source]

Check resuming()

verify_reuse_instance() None[source]

Check reuse_instance()

verify_save_final_snapshot() None[source]

Check should_save_final_snapshot()

verify_save_snapshot() None[source]

Check save_snapshot()

verify_should_init() None[source]

Check should_init()

verify_should_save_final_snapshot() None[source]

Check should_save_final_snapshot().

verify_should_save_snapshot() None[source]

Check should_save_snapshot()

class libmuscle.api_guard.APIPhase(value)[source]

Bases: Enum

Different phases that the user code traverses.

These values describe different regions that the model code can be in for the case where checkpointing is implemented. By tracking the phase that the model should be in, we can detect incorrect API usage.

This does not match the yMMSL operators, as it is more fine-grained and concerns checkpointing, which is not represented in the SEL.

AFTER_REUSE_LOOP = 9

After the final call to reuse_instance()

BEFORE_FIRST_REUSE_INSTANCE = 1

Before the first time calling reuse_instance

BEFORE_LOAD_SNAPSHOT = 4

Between resuming and load_snapshot

BEFORE_RESUMING = 3

Between reuse_instance and resuming

BEFORE_REUSE_INSTANCE = 2

Before calling reuse_instance

BEFORE_SAVE_FINAL_SNAPSHOT = 8

Between should_save_final_snapshot and save_final_snapshot

BEFORE_SAVE_SNAPSHOT = 7

Between should_save_snapshot and save_snapshot

BEFORE_SHOULD_INIT = 5

After resuming, before should_init

BEFORE_SHOULD_SAVE_SNAPSHOT = 6

Between should_init and should_save*