> 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/how-to-guides/create-a-replayable-config.md).

# Create a Replayable Config

Use this recipe when you want a small config that can be inspected, instantiated, logged, and replayed later.

The config is a normal Python function. Keep it cheap and side-effect-free so `explore()` can run it to inspect parameters and replay tools can execute it safely.

## 1. Define A Typed Config

{% code overflow="wrap" %}

```python
from hypster import HP
from my_app.data import CsvDataset


def data_config(hp: HP) -> CsvDataset:
    path = hp.text("data/train.csv", name="path")
    batch_size = hp.int(64, name="batch_size", min=1)
    shuffle = hp.bool(True, name="shuffle")
    return CsvDataset(path=path, batch_size=batch_size, shuffle=shuffle)
```

{% endcode %}

## 2. Inspect The Parameters

Print the active tree when you want a quick human check:

{% code overflow="wrap" %}

```python
from hypster import explore

explore(data_config)
```

{% endcode %}

Use structured metadata when another tool needs to render fields:

{% code overflow="wrap" %}

```python
schema = explore(data_config, return_schema=True)
fields = schema.to_dict()["parameters"]
```

{% endcode %}

## 3. Instantiate With Overrides

{% code overflow="wrap" %}

```python
from hypster import instantiate

dataset = instantiate(data_config, values={"batch_size": 128})

assert dataset.path == "data/train.csv"
assert dataset.batch_size == 128
assert dataset.shuffle is True
```

{% endcode %}

## 4. Capture Params For Replay

{% code overflow="wrap" %}

```python
from hypster import instantiate_with_params

run = instantiate_with_params(data_config, values={"batch_size": 128})

assert run.value.batch_size == dataset.batch_size
assert run.params == {
    "path": "data/train.csv",
    "batch_size": 128,
    "shuffle": True,
}
```

{% endcode %}

## 5. Store And Replay

{% code overflow="wrap" %}

```python
import json

payload = json.dumps(run.params, sort_keys=True)
restored_params = json.loads(payload)

replayed = instantiate(data_config, values=restored_params)
assert replayed.batch_size == run.value.batch_size
```

{% endcode %}

Because `run.params` includes defaulted values, replay does not silently change if the config's defaults are edited later.


---

# 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/how-to-guides/create-a-replayable-config.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.
