> For the complete documentation index, see [llms.txt](https://gilad-rubin.gitbook.io/hypster/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gilad-rubin.gitbook.io/hypster/in-depth/values-and-overrides.md).

# Values & Overrides

`values=` is the dictionary you pass to `instantiate()`, `instantiate_with_params()`, or `explore()` to select concrete parameter values.

{% code overflow="wrap" %}

```python
from hypster import HP, instantiate

def child(hp: HP):
    return {
        "x": hp.int(10, name="x"),
        "y": hp.int(20, name="y"),
    }

def parent(hp: HP):
    return {"child": hp.nest(child, name="child")}
```

{% endcode %}

## Top-Level Values

{% code overflow="wrap" %}

```python
def config(hp: HP):
    return {"batch_size": hp.int(32, name="batch_size")}

instantiate(config, values={"batch_size": 64})
# => {"batch_size": 64}
```

{% endcode %}

## Dotted Keys

Use dotted keys for nested parameters:

{% code overflow="wrap" %}

```python
instantiate(parent, values={"child.x": 15})
# => {"child": {"x": 15, "y": 20}}
```

{% endcode %}

## Nested Dictionaries

Nested dictionaries are normalized to the same dotted paths:

{% code overflow="wrap" %}

```python
instantiate(parent, values={"child": {"x": 25}})
# => {"child": {"x": 25, "y": 20}}
```

{% endcode %}

You can mix dotted keys and nested dictionaries as long as each final parameter path appears once.

## Nested Scope Names Are Not Leaves

A nested scope name is a prefix for child parameters, not a parameter leaf by itself. These forms are valid because they target `child.x`:

{% code overflow="wrap" %}

```python
instantiate(parent, values={"child.x": 15})
instantiate(parent, values={"child": {"x": 15}})
```

{% endcode %}

This raises because `child` is a scope, not a selectable parameter:

{% code overflow="wrap" %}

```python
instantiate(parent, values={"child": 123})
# ValueError: Unknown or unreachable parameters
```

{% endcode %}

## Duplicate Paths

This raises because both entries target `child.x`:

{% code overflow="wrap" %}

```python
instantiate(
    parent,
    values={
        "child.x": 100,
        "child": {"x": 100},
    },
)
# ValueError: Duplicate value for 'child.x'
```

{% endcode %}

Hypster raises even when the duplicate values are identical. A single canonical path keeps experiment logs and replay payloads unambiguous.

## Conditional Reachability

Only parameters touched by the active branch may appear in `values=`.

{% code overflow="wrap" %}

```python
from sklearn.base import ClassifierMixin
from sklearn.ensemble import RandomForestClassifier
from sklearn.linear_model import LogisticRegression

def linear_model(hp: HP) -> LogisticRegression:
    C = hp.float(1.0, name="C", min=1e-4, max=100.0)
    return LogisticRegression(C=C, max_iter=1000)

def forest_model(hp: HP) -> RandomForestClassifier:
    n_estimators = hp.int(200, name="n_estimators", min=10)
    return RandomForestClassifier(n_estimators=n_estimators, random_state=42)

model_options = {"linear": linear_model, "forest": forest_model}

def model_config(hp: HP) -> ClassifierMixin:
    selected_config = hp.select(model_options, name="family", default="linear", options_only=True)
    return hp.nest(selected_config, name="model")

instantiate(model_config, values={"family": "linear", "model.n_estimators": 500})
# ValueError: Unknown or unreachable parameters
```

{% endcode %}

Use `explore(model_config, values={"family": "forest"})` to inspect the branch before instantiating it.

## Unknown Policies

`instantiate()`, `instantiate_with_params()`, and `explore()` accept the same `on_unknown` policy:

| Policy     | Behavior                                         |
| ---------- | ------------------------------------------------ |
| `"raise"`  | Default. Raise on unknown or unreachable values. |
| `"warn"`   | Emit a warning and continue.                     |
| `"ignore"` | Ignore unknown or unreachable values.            |

Prefer the default for experiments and production replay. Softer policies are useful when migrating old payloads or rendering exploratory UIs.

### Conditional Options Under Each Policy

A later `hp.select`'s option list can depend on an earlier one, so a parameter name can exist in one branch and not another. Overriding a parameter that only exists in a branch you did not take is the same "unreachable" case as above, worked through under each `on_unknown` policy:

{% code overflow="wrap" %}

```python
from hypster import HP, instantiate

def pipeline_config(hp: HP) -> dict:
    stage = hp.select(["ingest", "transform"], name="stage", default="ingest", options_only=True)
    if stage == "ingest":
        source = hp.select(["csv", "json"], name="source", default="csv", options_only=True)
        return {"stage": stage, "source": source}
    else:
        strategy = hp.select(["normalize", "aggregate"], name="strategy", default="normalize", options_only=True)
        return {"stage": stage, "strategy": strategy}
```

{% endcode %}

Taking the `"ingest"` branch and overriding `strategy` — a parameter that only exists on the untaken `"transform"` branch:

{% code overflow="wrap" %}

```python
# on_unknown="raise" (default): raises
instantiate(pipeline_config, values={"stage": "ingest", "strategy": "aggregate"})
# ValueError: Unknown or unreachable parameters

# on_unknown="warn": warns, then returns the ingest branch's own default for "source"
instantiate(pipeline_config, values={"stage": "ingest", "strategy": "aggregate"}, on_unknown="warn")
# UserWarning: Unknown or unreachable parameters
# => {"stage": "ingest", "source": "csv"}

# on_unknown="ignore": same result, no warning
instantiate(pipeline_config, values={"stage": "ingest", "strategy": "aggregate"}, on_unknown="ignore")
# => {"stage": "ingest", "source": "csv"}
```

{% endcode %}

Under `"warn"` and `"ignore"`, the override for the untaken branch is dropped, not redirected or coerced onto the active branch: the active branch (`"ingest"`) still resolves `source` to its own default, `"csv"`. Nothing about `strategy="aggregate"` leaks into the result.

## Select Keys vs Complex Values

Nested dictionaries inside `values=` are interpreted as nested parameter paths. If you need a select option whose runtime value is a dictionary, use dict-backed `select`:

{% code overflow="wrap" %}

```python
def config(hp: HP):
    return hp.select(
        {
            "small": {"layers": 2},
            "large": {"layers": 4},
        },
        name="model",
        default="small",
    )

instantiate(config, values={"model": "large"})
# => {"layers": 4}
```

{% endcode %}

Do not pass `values={"model": {"layers": 4}}`; Hypster will treat that as a nested parameter path.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://gilad-rubin.gitbook.io/hypster/in-depth/values-and-overrides.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
