Tune.Execution (Tune v0.5.0)

Copy Markdown View Source

Per-run state threaded through application program code.

It holds the program's named parameters, the fixed model configuration for each role, the active role, the managed call allowance, the step limit, the deadline, and every completed step and failed call. Application code passes it through predict/3 and value/2 and returns the updated value.

All versions of the state share the run's call and response records. Each call counts before dispatch, including calls that fail. Call predict/3 and call_program/4 from the process running the program, before its callback returns. Use evaluation concurrency to run independent cases in parallel.

Summary

Functions

Runs a nested program inside this execution.

Returns true when a model configuration exists for the role.

Calls the named predictor with the active role's model configuration.

Returns the remaining managed call allowance, or nil when unlimited.

Returns milliseconds until the deadline, or nil without one.

Returns the managed roles.

Returns the completed steps in call order during the active program.

Returns attempted managed calls across roles.

Reads a declared JSON parameter value. Makes no model call.

Types

role()

@type role() :: :target | :teacher | :proposal

t()

@type t() :: %Tune.Execution{
  deadline: integer() | nil,
  journal: :ets.tid(),
  max_model_calls: non_neg_integer() | nil,
  max_steps: pos_integer(),
  models: %{optional(role()) => Tune.ModelConfig.t()},
  parameters: %{required(String.t()) => Tune.Predictor.t() | Tune.Parameter.t()},
  role: role(),
  scope: [String.t()]
}

Functions

call_program(execution, program, inputs, opts \\ [])

@spec call_program(t(), term(), map(), keyword()) ::
  {:ok, map(), t()} | {:error, term(), t()}

Runs a nested program inside this execution.

The nested program uses its own parameters, the given role (default: the active role), and this execution's allowance, step limit, and deadline. Its steps are recorded under scope.

has_role?(execution, role)

@spec has_role?(t(), role()) :: boolean()

Returns true when a model configuration exists for the role.

predict(execution, name, inputs)

@spec predict(t(), String.t(), map()) :: {:ok, map(), t()} | {:error, term(), t()}

Calls the named predictor with the active role's model configuration.

Returns the validated output map and the updated execution, or an error and the updated execution. The error is the original cause.

remaining_calls(execution)

@spec remaining_calls(t()) :: non_neg_integer() | nil

Returns the remaining managed call allowance, or nil when unlimited.

remaining_ms(execution)

@spec remaining_ms(t()) :: non_neg_integer() | nil

Returns milliseconds until the deadline, or nil without one.

roles()

@spec roles() :: [role()]

Returns the managed roles.

steps(execution)

@spec steps(t()) :: [Tune.Step.t()]

Returns the completed steps in call order during the active program.

total_calls(execution)

@spec total_calls(t()) :: non_neg_integer()

Returns attempted managed calls across roles.

value(execution, name)

@spec value(t(), String.t()) :: {:ok, term()} | {:error, Exception.t()}

Reads a declared JSON parameter value. Makes no model call.