federer
Version:
Experiments in asynchronous federated learning and decentralized learning
64 lines • 2.47 kB
TypeScript
/**
* Helper class to keep track of the state of clients. Clients can be marked as
* either "available" (meaning that they are not currently training, and are
* eligible to start training), or "training" (meaning that they have been given
* a training task, and we are awaiting results).
*
* Clients are tracked by their socket ID, which is a `string`.
*
* The methods in this class use assertions to enforce the following invariants:
*
* - All clients start in the available state
* - A client is either training or available, but never both
* - A client can only transition from available to training, or from training
* to available; it cannot transition to the state that it is currently in
*
* These invariants are helpful to debug server implementations, and to ensure
* the reported numbers are accurate.
*/
export declare class ClientPool {
/**
* Adds a client to the pool, in the "available" state.
*
* @throws if the client is already in the pool.
*/
addAvailableClient(client: string): void;
/** Returns whether the client is in the "available" state */
isAvailable(client: string): boolean;
/** Returns whether the client is in the "training" state. */
isTraining(client: string): boolean;
/**
* Changes the state of a client.
*
* @throws if the client is already in the target state
*/
transition(client: string, newState: "training" | "available"): void;
/**
* Removes a client from the pool.
*
* @returns `true` if it was removed, `false` if it wasn't in the pool.
*/
delete(client: string): boolean;
/** Returns whether a client is in the pool. */
has(client: string): boolean;
/** Number of clients in the pool in total. */
get size(): number;
/** Number of clients in the "training" state. */
get numberTraining(): number;
/** Number of clients in the "available" state. */
get numberAvailable(): number;
get clients(): ReadonlySet<string>;
get available(): ReadonlySet<string>;
get training(): ReadonlySet<string>;
get percentTraining(): number;
/**
* Samples `n` clients without replacement from the list of available clients,
* using reservoir sampling.
*
* @returns array of `n` sampled client IDs
* @throws if there are not enough available clients
*/
sampleAvailable(n: number): string[];
}
//# sourceMappingURL=ClientPool.d.ts.map