# `Imp.Optimizer.Trajectory`
[🔗](https://github.com/deepfates/imp/blob/v0.18.1/lib/imp/optimizer/trajectory.ex#L1)

Versioned, provider-neutral execution envelope shared by all optimizers.

The original evaluation fields remain directly available. `project/3` adds a
runtime identity and typed events for GEPA, MIPROv2, SIMBA, RLM, ReAct, and
generic evaluation adapters. `dump/1` is the canonical cross-runtime wire
representation: it is JSON-safe, deterministic, and redacts secrets in
structured fields. Opaque attachment bytes are preserved unchanged. An
`Imp.History` is written by `Imp.History.dump/1` and read by
`Imp.History.load!/1`. `load/1` validates the complete envelope and fails
closed.

Map keys load as the atoms or strings they were written as, with one
exception: loading never creates an atom, so a key written as an atom that
does not exist in the loading VM loads as its name, a string. A prediction's
metadata keys that are strings (written that way, or loaded as names) become
their atoms when those atoms exist, so `Imp.Prediction.get_lm_usage/1` and
`Imp.Prediction.complete?/1` read them. A map that holds a key as both an
atom and a string is refused on load, as on dump.

# `runtime`

```elixir
@type runtime() ::
  :evaluation
  | :gepa
  | :mipro_v2
  | :simba
  | :rlm
  | :agent
  | :react
  | :optimize_anything
```

# `t`

```elixir
@type t() :: %Imp.Optimizer.Trajectory{
  cache: struct() | nil,
  error: term(),
  events: list(),
  example: term(),
  feedback: term(),
  index: integer(),
  metadata: map(),
  metric_metadata: map() | nil,
  named_parameters: list(),
  prediction: term(),
  program_id: term(),
  rollout_id: term(),
  runtime: runtime(),
  schema_version: pos_integer(),
  score: number(),
  timing: struct(),
  trace: list() | nil,
  usage: struct()
}
```

# `dump`

```elixir
@spec dump(t()) :: map()
```

Dumps every trajectory field into a deterministic JSON-safe versioned map.

# `killed?`

```elixir
@spec killed?(t()) :: boolean()
```

True when this trajectory's failure came from a killed evaluation task
(timeout or deadline exhaustion), not from model or metric behavior.

# `load`

```elixir
@spec load(map()) :: {:ok, t()} | {:error, struct()}
```

Loads and strictly validates a canonical trajectory wire map.

# `load!`

```elixir
@spec load!(map()) :: t()
```

Loads a trajectory or raises `DecodeError` for any malformed field.

# `project`

```elixir
@spec project(runtime(), t() | Imp.Prediction.t() | map(), keyword()) :: t()
```

Projects an existing trajectory or runtime prediction into the canonical contract.

# `redact`

```elixir
@spec redact(t(), [atom() | String.t()]) :: t()
```

Returns a secret-redacted trajectory while preserving all typed structs.

# `schema_version`

Returns the current trajectory wire schema version.

# `validate!`

```elixir
@spec validate!(t()) :: t()
```

Validates ordering, tool alignment, accounting, cache, and named parameter invariants.

# `validate_aligned!`

```elixir
@spec validate_aligned!([t()]) :: [t()]
```

Validates a batch as index-aligned, ordered canonical trajectories.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
