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

Durable champion/challenger lifecycle for portable optimizer outputs.

Artifacts contain checksummed `Imp.Saving` program states or explicit
parameter-only snapshots and redacted provenance. Applying a candidate copies
only optimizable predictor parameters onto a compatible live program,
preserving its runtime LMs, adapters, and trusted callbacks. Persisted names
remain strings and are resolved against that trusted live program; artifact
bytes never create atoms or depend on unrelated modules preloading them.

# `artifact`

```elixir
@type artifact() :: %{required(String.t()) =&gt; term()}
```

# `candidate`

```elixir
@type candidate() :: %{required(String.t()) =&gt; term()}
```

# `selection`

```elixir
@type selection() :: :champion | String.t()
```

# `apply`

```elixir
@spec apply(artifact(), struct(), selection(), keyword()) :: struct()
```

Applies one candidate's portable parameters and canonical report to a compatible live program.

# `candidate`

```elixir
@spec candidate(String.t(), struct(), keyword()) :: candidate()
```

Builds a checksummed candidate from a portable optimizer output.

# `compare`

```elixir
@spec compare(artifact(), selection(), selection(), keyword()) :: map()
```

Compares candidate scores and named predictor parameters.

# `from_optimized_program`

```elixir
@spec from_optimized_program(struct(), keyword()) :: artifact()
```

Captures the selected parameters and attached report from an optimized program.

This is the shared durable handoff for program optimizers. The returned
artifact contains no consumer module or runtime binding; deploying code must
reconstruct a trusted compatible program and call `apply/4`.

# `inspect`

```elixir
@spec inspect(artifact()) :: map()
```

Returns an operational summary without rehydrating program callbacks.

# `new`

```elixir
@spec new(candidate(), [candidate()], keyword()) :: artifact()
```

Creates a versioned artifact from one champion and zero or more challengers.

# `parameter_candidate`

```elixir
@spec parameter_candidate(String.t(), struct(), keyword()) :: candidate()
```

Builds a checksummed candidate containing only named predictor parameters.

Use this for consumer-defined multi-predictor modules that cannot and should
not be serialized as arbitrary structs. The artifact retains each predictor's
signature, demonstrations, and config, but never the consumer module, LM,
adapter, callbacks, or other runtime state. Reconstruct the trusted program in
the deploying application, then pass it to `apply/4`.

# `promote`

```elixir
@spec promote(artifact(), String.t()) :: artifact()
```

Promotes a challenger and records the prior champion for rollback.

# `read!`

```elixir
@spec read!(Path.t()) :: artifact()
```

Reads and validates a supported optimizer artifact schema.

# `rollback`

```elixir
@spec rollback(artifact()) :: artifact()
```

Restores the most recently preserved champion.

# `value`

```elixir
@spec value(artifact(), selection()) :: term()
```

Returns one selected portable value without restoring executable code.

# `value_candidate`

```elixir
@spec value_candidate(String.t(), term(), keyword()) :: candidate()
```

Builds a checksummed candidate containing one canonical JSON value.

# `write!`

```elixir
@spec write!(artifact(), Path.t()) :: :ok
```

Atomically writes a validated artifact as owner-readable JSON.

---

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