# tff.program.ProgramStateManager

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/federated/blob/v0.87.0 Version 2.0, January 2004 Licensed under the Apache License, Version 2.0 (the) |

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

A [`tff.program.ProgramStateManager`](https://www.tensorflow.org/federated/api_docs/python/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](https://github.com/tensorflow/federated/blob/v0.87.0
Version 2.0, January 2004
Licensed under the Apache License, Version 2.0 (the)

    get_versions()

Returns a list of saved versions or `None`.

<br />

<br />

<br />

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

<br />

### `load`

[View source](https://github.com/tensorflow/federated/blob/v0.87.0
Version 2.0, January 2004
Licensed under the Apache License, Version 2.0 (the)

    load(
        version, structure
    )

Returns the saved program state for the given `version`.

<br />

<br />

<br />

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

<br />

<br />

<br />

<br />

| Raises ||
|---|---|
| `ProgramStateNotFoundError` | If there is no program state for the given `version`. |

<br />

### `load_latest`

[View source](https://github.com/tensorflow/federated/blob/v0.87.0
Version 2.0, January 2004
Licensed under the Apache License, Version 2.0 (the)

    load_latest(
        structure
    )

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

<br />

<br />

<br />

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

<br />

<br />

<br />

<br />

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

<br />

### `save`

[View source](https://github.com/tensorflow/federated/blob/v0.87.0
Version 2.0, January 2004
Licensed under the Apache License, Version 2.0 (the)

    save(
        program_state, version
    )

Saves `program_state` for the given `version`.

<br />

<br />

<br />

| Args ||
|---|---|
| `program_state` | A [`tff.program.ProgramStateStructure`](https://www.tensorflow.org/federated/api_docs/python/tff/program#ProgramStateStructure) to save. |
| `version` | A strictly increasing integer representing the version of a saved `program_state`. |

<br />

<br />

<br />

<br />

| Raises ||
|---|---|
| `ProgramStateExistsError` | If there is already program state for the given `version`. |

<br />