A stateful process that produces metrics.

Inherits From: IterativeProcess

This class inherits the constraints documented by tff.templates.IterativeProcess.

A tff.templates.MeasuredProcess is a tff.templates.IterativeProcess that formalizes the output signature of the next property to be a containet with named attributes <state,result,measurements>. This definition enables tff.templates.MeasuredProcess to be composed following the rules below, something that is not generally possible with the more generic, less defined tff.templates.IterativeProcess.

Guidance for Composition Given two MeasuredProcess F(x) and G(y), a new composition C is also a MeasuredProcess where:

  • C.state is the concatenation <F.state, G.state>.
  • C.result is the result of G applied to the result of F: G(G.state, F(F.state, x).result).result.
  • C.measurements is the concatenation <F.measurements, G.measurements>.

The resulting composition C would have the following type signatures: initialize: ( -> <F.initialize, G.initialize>) next: (<<F.state, G.state>, F.input> -> <state=<F.state, G.State>, result=G.result, measurements=<F.measurements, G.measurements>)

Note that the guidance for composition is not strict and details are allowed to differ.

initialize_fn A no-arg tff.Computation that creates the initial state of the measured process.
next_fn A tff.Computation that defines an iterated function. If initialize_fn returns a non-federated type S, then next_fn must return a MeasuredProcessOutput where the state attribute matches the non-federated type S, and accept either a single argument of non-federated type S or multiple arguments where the first argument must be of non-federated type S.

TypeError If initialize_fn and next_fn are not instances of 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.

initialize A no-arg tff.Computation that returns the initial state.
next A tff.Computation that runs one iteration of the process.

Its first argument should always be the current state (originally produced by tff.templates.MeasuredProcess.initialize), and the return type must be a tff.templates.MeasuredProcessOutput.

state_type The tff.Type of the state of the process.