# tff.learning.templates.DistributionProcess

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/federated/blob/v0.87.0 Version 2.0, January 2004 Licensed under the Apache License, Version 2.0 (the) |

A stateful process that distributes values.

Inherits From: [`MeasuredProcess`](https://www.tensorflow.org/federated/api_docs/python/tff/templates/MeasuredProcess), [`IterativeProcess`](https://www.tensorflow.org/federated/api_docs/python/tff/templates/IterativeProcess)

    tff.learning.templates.DistributionProcess(
        initialize_fn, next_fn
    )

A `DistributionProcess` is a [`tff.templates.MeasuredProcess`](https://www.tensorflow.org/federated/api_docs/python/tff/templates/MeasuredProcess) that formalizes
the type signature of `initialize_fn` and `next_fn` for distribution.

The `initialize_fn` and `next_fn` must have the following type signatures:

      - initialize_fn: ( -> S@SERVER)
      - next_fn: (<S@SERVER, U@SERVER> ->
                  <state=S@SERVER, result=V@CLIENTS, measurements=M@SERVER>)

`DistributionProcess` requires `next_fn` with a second input argument, which
is a value placed at `SERVER` and to be distributed to `CLIENTS`.

The `result` field of the returned [`tff.templates.MeasuredProcessOutput`](https://www.tensorflow.org/federated/api_docs/python/tff/templates/MeasuredProcessOutput) must
be placed at `CLIENTS`. Its type singature, `U'`, need not be the same as the
type signature of the second input argument, `U`. Note these will be
equivalent for a number of implementations of this process, though.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `initialize_fn` | A no-arg [`tff.Computation`](https://www.tensorflow.org/federated/api_docs/python/tff/Computation) that returns the initial state of the measured process. Let the type of this state be called `S`. |
| `next_fn` | A [`tff.Computation`](https://www.tensorflow.org/federated/api_docs/python/tff/Computation) that represents the iterated function. The first or only argument must be assignable from ( [`tff.types.Type.is_assignable_from`](https://www.tensorflow.org/federated/api_docs/python/tff/types/Type#is_assignable_from) must return `True`) the state type `S`. The return value must be a `MeasuredProcessOutput` whose `state` member is assignable to the first argument (same requirement as the `S` type). |
| `next_is_multi_arg` | An optional boolean indicating that `next_fn` will receive more than just the state argument (if `True`) or only the state argument (if `False`). This parameter is primarily used to provide better error messages. |

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `TypeError` | If `initialize_fn` and `next_fn` are not instances of [`tff.Computation`](https://www.tensorflow.org/federated/api_docs/python/tff/Computation). |
| `TemplateInitFnParamNotEmptyError` | If `initialize_fn` has any input arguments. |
| `TemplateStateNotAssignableError` | If the `state` returned by either `initialize_fn` or `next_fn` is not assignable to the first input argument of `next_fn`. |
| `TemplateNotMeasuredProcessOutputError` | If `next_fn` does not return a `MeasuredProcessOutput`. |

<br />

<br />

<br />

<br />

| ## Attributes ||
|---|---|
| `initialize` | A no-arg [`tff.Computation`](https://www.tensorflow.org/federated/api_docs/python/tff/Computation) that returns the initial state. |
| `next` | A [`tff.Computation`](https://www.tensorflow.org/federated/api_docs/python/tff/Computation) that produces the next state. <br /> Its first argument should always be the current state (originally produced by [`tff.templates.IterativeProcess.initialize`](https://www.tensorflow.org/federated/api_docs/python/tff/templates/IterativeProcess#initialize)), and the first (or only) returned value is the updated state. |
| `state_type` | The [`tff.Type`](https://www.tensorflow.org/federated/api_docs/python/tff/types/Type) of the state of the process. |

<br />