# Workflows and Controllers

A workflow has one or more controllers, each implementing a specific coordination strategy. For example, the ScatterAndGather
(SAG) controller implements a popular strategy that is typically used for the fed-average type of federated training. The
CrossSiteValidation controller implements a strategy to let every client site evaluate every other site’s model. You can put together
a workflow that uses any number of controllers.

We provide the FLModel-based [ModelController API](controllers/model_controller.md#model-controller) which provides a straightforward way for users to write controllers.
We also have the original [Controller API](controllers/controllers.md#controllers) with more FLARE-specific functionalities, which many of our existing workflows are based upon.

We have implemented several server controlled federated learning workflows (fed-average, cyclic controller, cross-site evaluation) with the server-side controllers.
In these workflows, FL clients get tasks assigned by the controller, execute the tasks, and submit results back to the server.

In certain cases, if the server cannot be trusted, it should not be involved in communication with sensitive information.
To address this concern, NVFlare introduces Client Controlled Workflows (CCWF) to facilitate peer-to-peer communication among clients.

Controllers can be configured in `config_fed_server.json` in the workflows section:

```default
workflows = [
    {
        id = "fedavg_ctl",
        path = "nvflare.app_common.workflows.fedavg.FedAvg",
        args {
            min_clients = 2,
            num_rounds = 3,
            persistor_id = "persistor"
        }
    }
]
```

To configure controllers using the JobAPI, define the controller and send it to the server.
This code will automatically generate the server configuration for the controller:

```python
controller = FedAvg(
    num_clients=2,
    num_rounds=3,
    persistor_id = "persistor"
)
job.to(controller, "server")
```

Please refer to the following sections for more details about the different types of controllers.

* [ModelController API](controllers/model_controller.md)
  * [Core Concepts](controllers/model_controller.md#core-concepts)
  * [Communication](controllers/model_controller.md#communication)
    * [send_model_and_wait](controllers/model_controller.md#send-model-and-wait)
    * [send_model](controllers/model_controller.md#send-model)
  * [Saving & Loading](controllers/model_controller.md#saving-loading)
    * [persistor](controllers/model_controller.md#persistor)
    * [custom save & load](controllers/model_controller.md#custom-save-load)
  * [Additional Functionalities](controllers/model_controller.md#additional-functionalities)
  * [Examples](controllers/model_controller.md#examples)
* [Controllers and Controller API](controllers/controllers.md)
  * [Controller/Worker Interactions](controllers/controllers.md#controller-worker-interactions)
  * [Controller API](controllers/controllers.md#controller-api)
    * [Scatter and Gather Workflow](controllers/scatter_and_gather_workflow.md)
    * [Cross Site Model Evaluation / Federated Evaluation](controllers/cross_site_model_evaluation.md)
    * [Cyclic Workflow](controllers/cyclic_workflow.md)
    * [Initialize Global Weights Workflow for Client-Side Global Model Initialization](controllers/initialize_global_weights.md)
  * [Task Lifecycle](controllers/controllers.md#task-lifecycle)
* [Client Controlled Workflows](controllers/client_controlled_workflows.md)
  * [Client Controlled Workflow Development Framework](controllers/client_controlled_workflows.md#client-controlled-workflow-development-framework)
    * [Server Side Controller](controllers/client_controlled_workflows.md#server-side-controller)
    * [Client Side Controller](controllers/client_controlled_workflows.md#client-side-controller)
  * [Cyclic Learning](controllers/client_controlled_workflows.md#cyclic-learning)
    * [Cyclic Learning: Server Side Controller](controllers/client_controlled_workflows.md#cyclic-learning-server-side-controller)
    * [Cyclic Learning: Client Side Controller](controllers/client_controlled_workflows.md#cyclic-learning-client-side-controller)
    * [Example Cyclic Learning Configuration](controllers/client_controlled_workflows.md#example-cyclic-learning-configuration)
  * [Swarm Learning](controllers/client_controlled_workflows.md#swarm-learning)
    * [Best Model Selection](controllers/client_controlled_workflows.md#best-model-selection)
    * [Swarm Learning: Server Side Controller](controllers/client_controlled_workflows.md#swarm-learning-server-side-controller)
    * [Swarm Learning: Client Side Controller](controllers/client_controlled_workflows.md#swarm-learning-client-side-controller)
    * [Example Swarm Learning](controllers/client_controlled_workflows.md#example-swarm-learning)
    * [Swarm Learning Parameters for Large Models](controllers/client_controlled_workflows.md#swarm-learning-parameters-for-large-models)
  * [Cross Site Evaluation](controllers/client_controlled_workflows.md#cross-site-evaluation)
    * [Cross Site Evaluation: Server Side Controller](controllers/client_controlled_workflows.md#cross-site-evaluation-server-side-controller)
    * [Cross Site Evaluation: Client Side Controller](controllers/client_controlled_workflows.md#cross-site-evaluation-client-side-controller)
    * [Example Cross Site Evaluation](controllers/client_controlled_workflows.md#example-cross-site-evaluation)
    * [Cross Site Evaluation Parameters for Large Models](controllers/client_controlled_workflows.md#cross-site-evaluation-parameters-for-large-models)
