start_simulation¶
- start_simulation(*, client_fn: ~typing.Callable[[~flwr.common.context.Context], ~flwr.client.client.Client], num_clients: int, clients_ids: list[str] | None = None, client_resources: dict[str, float] | None = None, server: ~flwr.server.server.Server | None = None, config: ~flwr.server.server_config.ServerConfig | None = None, strategy: ~flwr.server.strategy.strategy.Strategy | None = None, client_manager: ~flwr.server.client_manager.ClientManager | None = None, ray_init_args: dict[str, ~typing.Any] | None = None, keep_initialised: bool | None = False, actor_type: type[~flwr.simulation.ray_transport.ray_actor.VirtualClientEngineActor] = <flwr.simulation.ray_transport.ray_actor.ActorClass(ClientAppActor) object>, actor_kwargs: dict[str, ~typing.Any] | None = None, actor_scheduling: str | ~ray.util.scheduling_strategies.NodeAffinitySchedulingStrategy = 'DEFAULT') History [source]¶
Start a Ray-based Flower simulation server.
- 参数:
client_fn (ClientFnExt) -- A function creating Client instances. The function must have the signature client_fn(context: Context). It should return a single client instance of type `Client. Note that the created client instances are ephemeral and will often be destroyed after a single method invocation. Since client instances are not long-lived, they should not attempt to carry state over method invocations. Any state required by the instance (model, dataset, hyperparameters, ...) should be (re-)created in either the call to client_fn or the call to any of the client methods (e.g., load evaluation data in the evaluate method itself).
num_clients (int) -- The total number of clients in this simulation.
clients_ids (Optional[List[str]]) -- UNSUPPORTED, WILL BE REMOVED. USE num_clients INSTEAD. List client_id`s for each client. This is only required if `num_clients is not set. Setting both num_clients and clients_ids with len(clients_ids) not equal to num_clients generates an error. Using this argument will raise an error.
client_resources (Optional[Dict[str, float]] (default: {"num_cpus": 1, "num_gpus": 0.0})) -- CPU and GPU resources for a single client. Supported keys are num_cpus and num_gpus. To understand the GPU utilization caused by num_gpus, as well as using custom resources, please consult the Ray documentation.
server (Optional[flwr.server.Server] (default: None).) -- An implementation of the abstract base class flwr.server.Server. If no instance is provided, then start_server will create one.
config (ServerConfig (default: None).) -- 目前支持的值有:`num_rounds`(int,默认值:1)和以秒为单位的`round_timeout`(float,默认值:无)。
strategy (Optional[flwr.server.Strategy] (default: None)) -- An implementation of the abstract base class flwr.server.Strategy. If no strategy is provided, then start_server will use flwr.server.strategy.FedAvg.
client_manager (Optional[flwr.server.ClientManager] (default: None)) -- An implementation of the abstract base class flwr.server.ClientManager. If no implementation is provided, then start_simulation will use flwr.server.client_manager.SimpleClientManager.
ray_init_args (Optional[Dict[str, Any]] (default: None)) --
Optional dictionary containing arguments for the call to ray.init. If ray_init_args is None (the default), Ray will be initialized with the following default args:
{ "ignore_reinit_error": True, "include_dashboard": False }
An empty dictionary can be used (ray_init_args={}) to prevent any arguments from being passed to ray.init.
keep_initialised (Optional[bool] (default: False)) -- Set to True to prevent ray.shutdown() in case ray.is_initialized()=True.
actor_type (VirtualClientEngineActor (default: ClientAppActor)) -- Optionally specify the type of actor to use. The actor object, which persists throughout the simulation, will be the process in charge of executing a ClientApp wrapping input argument client_fn.
actor_kwargs (Optional[Dict[str, Any]] (default: None)) -- If you want to create your own Actor classes, you might need to pass some input argument. You can use this dictionary for such purpose.
actor_scheduling (Optional[Union[str, NodeAffinitySchedulingStrategy]]) -- (default: "DEFAULT") Optional string ("DEFAULT" or "SPREAD") for the VCE to choose in which node the actor is placed. If you are an advanced user needed more control you can use lower-level scheduling strategies to pin actors to specific compute nodes (e.g. via NodeAffinitySchedulingStrategy). Please note this is an advanced feature. For all details, please refer to the Ray documentation: https://docs.ray.io/en/latest/ray-core/scheduling/index.html
- 返回:
hist -- Object containing metrics from training.
- 返回类型: