# Examples

Run the companion examples to exercise different training-loop shapes against hosted InstantML and confirm what lands in the dashboard.

## Prerequisites

- Authenticate once with the CLI:

```bash
instantml login
```

- For CI or remote jobs that cannot use browser login, set an SDK key instead:

```bash
export INSTANTML_API_KEY="instantml_..."
```

The examples use the same public Python SDK calls that production training scripts use. When an example accepts `--server`, pass the hosted API URL.

## Classify Iris species

Train a real-data NumPy softmax classifier on the UCI Iris dataset.

```bash
PYTHONPATH=packages/python-sdk:examples/iris-classification \
  python3 examples/iris-classification/train.py \
  --server https://api.instantml.ai \
  --summary-json .instantml/iris-classification-summary.json
```

What to inspect:

- Project `iris-classification`.
- Metrics `val/accuracy`, `test/accuracy`, `test/macro_f1`, `test/ece`.
- Config rows for seed, learning rate, and L2.
- Uploaded artifacts: dataset profile, model JSON, predictions, confusion matrix.

## Save and resume checkpoints

Run a tiny deterministic checkpoint workflow with upload and resume.

```bash
PYTHONPATH=packages/python-sdk \
  python3 examples/checkpoints/train.py \
  --server https://api.instantml.ai \
  --api-key "$INSTANTML_API_KEY" \
  --steps 12 \
  --checkpoint-every 4
```

Open Run Detail and inspect checkpoint artifacts. The dashboard should expose download and resume-code actions.

## Log RL-style metrics

Generate deterministic CartPole-style RL metrics without a simulator dependency.

```bash
PYTHONPATH=packages/python-sdk:examples/rl-cartpole \
  python3 examples/rl-cartpole/train.py \
  --server https://api.instantml.ai
```

Use this example to test scalar logging, status transitions, and spool mode.

## Train a Q-learning gridworld

Run a small tabular Q-learning loop with checkpoints and rollout metadata.

```bash
PYTHONPATH=packages/python-sdk \
  python3 examples/q-learning-gridworld/train.py \
  --server https://api.instantml.ai
```

Compare `train/episode_return`, `train/success_rate`, `train/td_error`, and `train/epsilon`.

## Run a contextual bandit

Exercise an online bandit workflow with multiple policies and seeds.

```bash
PYTHONPATH=packages/python-sdk:examples/contextual-bandit \
  python3 examples/contextual-bandit/train.py \
  --server https://api.instantml.ai
```

Compare `eval/return_mean`, `train/click_rate_50`, `train/cumulative_regret`, `eval/optimality_gap`, and `policy/arm_entropy`.

## Sweep a supervised regression

Run a synthetic tabular regression sweep across seeds.

```bash
PYTHONPATH=packages/python-sdk:examples/supervised-regression \
  python3 examples/supervised-regression/train.py \
  --server https://api.instantml.ai \
  --seeds 11,29 \
  --epochs 30
```

Inspect train/validation loss, RMSE, MAE, R2, optimizer grad norm, and artifact metadata.

## Seed Distributed and Insights

Generate distributed-rank and sweep-analysis data for the Distributed and Insights panels.

```bash
PYTHONPATH=packages/python-sdk \
  python3 examples/rank-insights/train.py \
  --server https://api.instantml.ai
```

Open the dashboard, select the generated rank-insights project, and inspect Distributed and Insights for rank coverage, outliers, reducer differences, and clustered run groups.

## Query runs from a script

Run the post-hoc SDK query workflow for notebooks and automation.

```bash
PYTHONPATH=packages/python-sdk \
  python3 examples/query-api/query.py \
  --server https://api.instantml.ai
```

The script creates 20 short runs by default, then calls `Api.query_runs()`, `Api.iter_runs()`, `Api.query_metrics()`, `Api.query_objects(run_id=...)`, and `Api.object_rows()` and prints a compact JSON summary. Use `--skip-seed` to query an existing `query-api-demo` project.

## Verify the results

After running an example, confirm:

- The project appears in the project selector.
- Runs have expected tags, notes, and config values.
- Metrics are chartable in Runs, Metrics, and Run Detail, and visible as sortable values in Compare.
- Artifact metadata or uploaded bytes appear in Run Detail and Artifacts.
- Failed scripts mark runs as `failed` instead of leaving them `running`.

## Next steps

- [Quickstart](/docs/quickstart.md)
- [SDK examples and patterns](/docs/sdk/examples-patterns.md)
- [Query data with the SDK](/docs/sdk/querying-data.md)
- [Artifacts and checkpoints](/docs/sdk/artifacts-checkpoints.md)
- [Compare runs in the dashboard](/docs/dashboard/compare-runs.md)

## Agent navigation

- [Docs index](/llms.txt)
- [Full docs bundle](/llms-full.txt)

### Get Started

- [Overview](/docs/index.md)
- [Quickstart](/docs/quickstart.md)
- [Core Concepts](/docs/concepts/core-concepts.md)
- [Pricing](/docs/pricing.md)
- [Benchmarks](/docs/benchmarks.md)
- [Examples](/docs/guides/examples.md) (current page)
- [Troubleshooting](/docs/troubleshooting.md)

### SDK

- [Installation Auth](/docs/sdk/installation-auth.md)
- [Logging](/docs/sdk/logging.md)
- [Tracing](/docs/sdk/tracing.md)
- [Metrics Steps](/docs/sdk/metrics-steps.md)
- [Config Tags Notes](/docs/sdk/config-tags-notes.md)
- [Artifacts Checkpoints](/docs/sdk/artifacts-checkpoints.md)
- [Rich Objects](/docs/sdk/rich-objects.md)
- [Distributed Training](/docs/sdk/distributed-training.md)
- [Console System Integrations](/docs/sdk/console-system-integrations.md)
- [Reliability](/docs/sdk/reliability.md)
- [Cli Login](/docs/sdk/cli-login.md)
- [Querying Data](/docs/sdk/querying-data.md)
- [Agent Mcp](/docs/sdk/agent-mcp.md)
- [Examples Patterns](/docs/sdk/examples-patterns.md)

### Integrations

- [Overview](/docs/integrations/overview.md)
- [Pytorch Lightning](/docs/integrations/pytorch-lightning.md)
- [Huggingface Transformers](/docs/integrations/huggingface-transformers.md)
- [Keras](/docs/integrations/keras.md)
- [Wandb](/docs/integrations/wandb.md)

### Dashboard

- [Tour](/docs/dashboard/tour.md)
- [Organizations Workspaces](/docs/dashboard/organizations-workspaces.md)
- [Runs Workspace](/docs/dashboard/runs-workspace.md)
- [Metrics Charts](/docs/dashboard/metrics-charts.md)
- [Run Detail](/docs/dashboard/run-detail.md)
- [Traces](/docs/dashboard/traces.md)
- [Compare Runs](/docs/dashboard/compare-runs.md)
- [Research Dashboards](/docs/dashboard/research-dashboards.md)
- [Artifacts Files](/docs/dashboard/artifacts-files.md)
- [Run Health](/docs/dashboard/alerts.md)
- [Datasets](/docs/dashboard/datasets.md)
- [Checkpoints](/docs/dashboard/checkpoints.md)
- [Reports](/docs/dashboard/reports.md)
- [Settings Api Keys](/docs/dashboard/settings-api-keys.md)
- [Api Tab](/docs/dashboard/api-tab.md)
- [Onboarding Team Billing](/docs/dashboard/onboarding-team-billing.md)

### Data

- [Imports](/docs/guides/imports.md)
- [W&B alternative](/docs/guides/wandb-alternative.md)
- [InstantML vs MLflow](/docs/guides/instantml-vs-mlflow.md)
- [W&B import guide](/docs/guides/wandb-import-guide.md)
- [W&B and Neptune imports](/docs/guides/wandb-neptune-imports.md)
- [Export Usage Limits](/docs/guides/export-usage-limits.md)
- [Pricing Limits Billing](/docs/guides/pricing-limits-billing.md)
- [Auth Billing Storage](/docs/guides/auth-billing-storage.md)
- [Customer Owned Clickhouse](/docs/guides/customer-owned-clickhouse.md)
- [Observability](/docs/guides/observability.md)

### API

**Practical API guides**

- [Authentication](/docs/api/authentication.md)
- [Errors And Limits](/docs/api/errors-and-limits.md)
- [Health Observability](/docs/api/health-observability.md)
- [Projects Runs](/docs/api/projects-runs.md)
- [Metrics Series](/docs/api/metrics-series.md)
- [Attributes Objects](/docs/api/attributes-objects.md)
- [Artifacts](/docs/api/artifacts.md)
- [Reports](/docs/api/reports.md)
- [Iframe Embeds](/docs/api/iframe-embeds.md)
- [Import Export Usage](/docs/api/import-export-usage.md)
- [Dashboard Control State](/docs/api/dashboard-control-state.md)
**Architecture**

- [System Overview](/docs/architecture/system-overview.md)
- [Service Planes](/docs/architecture/service-planes.md)
- [Storage Model](/docs/architecture/storage-model.md)
- [Google Clickhouse](/docs/architecture/google-clickhouse.md)
- [Auth Tenancy](/docs/architecture/auth-tenancy.md)
- [Schema Reference](/docs/architecture/schema-reference.md)

### API Reference

- [API Reference](/docs/api-reference.md)
