tff.program.ProgramStateManager

Stay organized with collections Save and categorize content based on your preferences.

An interface for saving and loading program state in a federated program.

A tff.program.ProgramStateManager is used to implement fault tolerance in a federated program. The structure or type of the program state that is saved is unknown at construction time and can change as the program runs.

Methods

get_versions

View source

Returns a list of saved versions or None.

Returns
A list of saved versions or None if there is no saved program state.

load

View source

Returns the saved program state for the given version.

Args
version A integer representing the version of a saved program state.
structure The nested structure of the saved program state for the given version used to support serialization and deserailization of user-defined classes in the structure.

Raises
ProgramStateManagerStateNotFoundError If there is no program state for the given version.
ProgramStateManagerStructureError If structure does not match the value loaded for the given version.

load_latest

View source

Returns the latest saved program state and version or (None, 0).

Args
structure The nested structure of the saved program state for the given version used to support serialization and deserailization of user-defined classes in the structure.

Returns
A tuple of the latest saved (program state, version) or (None, 0) if there is no latest saved program state.

save

View source

Saves program_state for the given version.

Args
program_state A materialized value, a value reference, or a structure of materialized values and value references representing the program state to save.
version A strictly increasing integer representing the version of a saved program_state.

Raises
ProgramStateManagerStateAlreadyExistsError If there is already program state for the given version.