# Examples

Use this reference when the step contract is clear but you want concrete construction patterns.

## Function-style entry

```python
report = run_experiment(
    name='demo',
    params=params,
    root_dir=params.RECORD_DIR,
    prepare_run=prepare_run,
    plan=build_trial_plan,
    build_data=build_data,
    build_model=build_model,
    train_model=train_model,
    effects=ExperimentEffects(
        record=RecordConfig(
            inject_namespaces=('default', 'train'),
            export_rule=('default', 'result', 'env'),
        )
    ),
)
```

## Class-style entry

```python
class DemoExperiment(BasicExperiment[Params]):
    name = 'demo'
    root_dir = 'temp/experiment'
    Params = Params
    effects = ExperimentEffects(
        record=RecordConfig(export_rule=('default', 'result', 'env'))
    )

    def prepare_run(self, ctx):
        return {...}

    def get_trial_plan(self, ctx):
        return TrialPlan.repeat(...)

    def build_data(self, ctx):
        return ExperimentData(...)

    def build_model(self, ctx):
        return ModelSetup(...)

    def train_model(self, ctx, model_setup, data):
        return {'accuracy': 0.91}
```

## Explicit seed schedule pattern

Use this when the script precomputes the real per-trial split/model seed schedule.

```python
def prepare_run(ctx):
    seed_everything(ctx.params.RANDOM_SEED)
    trial_seeds = build_seed_schedule(ctx.params)
    return {'trial_seeds': trial_seeds}


def build_trial_plan(ctx):
    return TrialPlan.repeat(
        ctx.params.N_TRIALS,
        trial_seeds=ctx.shared['trial_seeds'],
        base_seed=ctx.params.RANDOM_SEED,
    )


def build_data(ctx):
    split_seed = ctx.trial_seed
    ...
```

## Minimal record usage pattern

```python
def build_data(ctx):
    ctx.set('split_seed', ctx.trial_seed, namespace='result')
    return ExperimentData(train_loader, val_loader, test_loader, info={'fold': ctx.trial_no})
```

## Current real example

See `examples/experiment/example_asd_baseline.py` when you want a full experiment file that exercises:

- `prepare_run`
- explicit `TrialPlan`
- `ExperimentEffects` + `RecordConfig`
- Fabric-based training integration
