ServerApp¶
- class ServerApp(server: Server | None = None, config: ServerConfig | None = None, strategy: Strategy | None = None, client_manager: ClientManager | None = None, server_fn: Callable[[Context], ServerAppComponents] | None = None)[source]¶
Bases:
object
Flower ServerApp.
实例
Use the ServerApp with an existing Strategy:
>>> def server_fn(context: Context): >>> server_config = ServerConfig(num_rounds=3) >>> strategy = FedAvg() >>> return ServerAppComponents( >>> strategy=strategy, >>> server_config=server_config, >>> ) >>> >>> app = ServerApp(server_fn=server_fn)
Use the ServerApp with a custom main function:
>>> app = ServerApp() >>> >>> @app.main() >>> def main(driver: Driver, context: Context) -> None: >>> print("ServerApp running")
Methods
main
()Return a decorator that registers the main fn with the server app.