/// <reference types="node" />
import type * as tf from "@tensorflow/tfjs-node";
import { ClientStartOptions, ServerStartOptions } from "../start-options";
import { SerializedWeights } from "../weights";
/**
 * Base interface for parent-to-child IPC communication.
 *
 * In our framework, the coordinator is always the parent, and the child is
 * either a client or a server. We use the term "IPC" to distinguish these
 * communications from the client/server communications that make up the FL
 * process, but these IPC communications are also happening over socket.io.
 *
 * When a child connects to a parent, we do something akin to a 3-way handshake,
 * to ensure that the child is fully loaded and ready when we send messages to
 * it.
 *
 * 1. The child sends a `ready` message
 * 2. The parent sends back a `start` message, with some start options
 * 3. The child starts itself according to the options, and sends back a
 *    `started` message
 */
export interface ParentToChildIPCMessages<StartOptions> {
    /** Request the child to start running with these options */
    start: (options: StartOptions) => void;
    /** Stop and reset the child process */
    stop: () => void;
    /** Kill the child process */
    kill: () => void;
}
/**
 * Base interface for child-to-parent IPC communication.
 *
 * @see {@link ParentToChildIPCMessages}
 */
export interface ChildToParentIPCMessages {
    /**
     * Signal to the parent that the child is ready to receive commands through
     * IPC.
     */
    ready: () => void;
    /** ACK a `start` message, indicating that the child has started. */
    started: () => void;
    /** ACK a `stop` message, indicating that the child has been stopped. */
    stopped: () => void;
    /** ACK a `kill` message, indicating that the child has been killed. */
    killed: (reason: string) => void;
}
/**
 * Mapping of message names to message contents, of IPC messages being sent from
 * the coordinator to the client.
 */
export interface CoordinatorToClientIPCMessages extends ParentToChildIPCMessages<ClientStartOptions> {
}
/**
 * Mapping of message names to message contents, of IPC messages being sent from
 * the client to the coordinator.
 */
export interface ClientToCoordinatorIPCMessages extends ChildToParentIPCMessages {
}
/**
 * Mapping of message names to message contents, of IPC messages being sent from
 * the coordinator to the server.
 */
export interface CoordinatorToServerIPCMessages extends ParentToChildIPCMessages<ServerStartOptions> {
}
/**
 * Mapping of message names to message contents, of IPC messages being sent from
 * the server to the coordinator.
 */
export interface ServerToCoordinatorIPCMessages extends ChildToParentIPCMessages {
    /** Indicate to the coordinator that the server has ended a round. */
    roundEnd: (summary: RoundSummary) => void;
}
/**
 * Describes a few key metrics of a Federated Learning round. Objects
 * implementing this interface are sent from the server to the coordinator at
 * the end of each round, so that the coordinator can evaluate and log the
 * performance of the system.
 */
export interface RoundSummary {
    /** Number of the round that just ended. */
    roundNumber: number;
    /** Aggregated weights from the round. */
    weights: SerializedWeights;
    /** Number of epochs of training that have been aggregated, in total. */
    numberEpochs: number;
    /** Wall-clock time, in ms, since the start of training. */
    timeSinceStart: number;
    /** Total number of uploads received since the start of the training. */
    numberUploads: number;
    /** Number of clients currently training. */
    numberClientsTraining: number;
    /** Optionally, additional metrics reported by instrumentation. */
    instrumentation?: InstrumentationMetrics;
}
export interface InstrumentationMetrics {
    /** Mapping of message ages to message counts */
    stalenessCounts?: Record<number, number>;
    /** Stats about memory usage on the server. Useful for debugging. */
    memory?: Readonly<MemoryInfo>;
}
/** Type of an object holding metrics about memory usage. */
export interface MemoryInfo {
    tf: tf.MemoryInfo;
    node: NodeJS.MemoryUsage;
}
//# sourceMappingURL=coordinator-child.d.ts.map