start_simulation#

start_simulation(*, client_fn: ~typing.Callable[[str], ~flwr.client.client.Client], num_clients: int | None = None, clients_ids: ~typing.List[str] | None = None, client_resources: ~typing.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: ~typing.Dict[str, ~typing.Any] | None = None, keep_initialised: bool | None = False, actor_type: ~typing.Type[~flwr.simulation.ray_transport.ray_actor.VirtualClientEngineActor] = <flwr.simulation.ray_transport.ray_actor.ActorClass(ClientAppActor) object>, actor_kwargs: ~typing.Dict[str, ~typing.Any] | None = None, actor_scheduling: str | ~ray.util.scheduling_strategies.NodeAffinitySchedulingStrategy = 'DEFAULT') History[source]#

Start a Ray-based Flower simulation server.

Paramètres:
  • client_fn (ClientFn) – A function creating client instances. The function must take a single str argument called cid. 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 (Optional[int]) – The total number of clients in this simulation. This must be set if clients_ids is not set and vice-versa.

  • clients_ids (Optional[List[str]]) – 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.

  • 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).) – Currently supported values are num_rounds (int, default: 1) and round_timeout in seconds (float, default: None).

  • 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

Renvoie:

hist – Object containing metrics from training.

Type renvoyé:

flwr.server.history.History