decent_bench.algorithms#
- class decent_bench.algorithms.Algorithm[source]#
-
Base class for decentralized algorithms.
- abstractmethod initialize(network: NetworkT) None[source]#
Initialize the algorithm.
- Parameters:
network – provides the agents and topology for this algorithm.
- abstractmethod step(network: NetworkT, iteration: int) None[source]#
Perform one iteration of the algorithm.
- Parameters:
network – provides the agents and topology for this algorithm.
iteration – current iteration number.
- abstractmethod cleanup_agents(network: NetworkT) Iterable[Agent][source]#
Return the agents whose auxiliary variables should be cleared.
- Parameters:
network – provides the agents and topology for this algorithm.
- cleanup(network: NetworkT) None[source]#
Clean up the algorithm state by clearing auxiliary variables from agents.
This method is used to free up memory used by auxiliary variables that are not needed after training. Can be overridden to control what gets cleaned up.
Note
Override
cleanup_agents()to control which agents are cleaned up.- Parameters:
network – provides the agents and topology for this algorithm.
- final run(network: NetworkT, start_iteration: int = 0, progress_callback: Callable[[int], None] | None = None) None[source]#
Run the algorithm.
This method first calls
initialize(), thenstep()for the specified number of iterations. Optionally callcleanup()afterrun()to clear auxiliary variables and free up memory.- Parameters:
network – provides the agents and topology for this algorithm.
start_iteration – iteration number to start from, used when resuming from a checkpoint. If greater than 0,
initialize()will be skipped.progress_callback – optional callback to report progress after each iteration.
- Raises:
ValueError – if start_iteration is not in [0, iterations]
Warning
Do not override this method. Instead, override
initialize()andstep()as needed.Note
The algorithm saves the agents’ states every
state_snapshot_period.