Run your first experiment
This guide takes a small Python program from a local run to a cloud experiment. You will search for the value of x that gives the lowest loss, then inspect the settings behind each result.
The example uses a simple function, not a model or backtest. It needs no dataset, external service, or Python packages. Once it works, replace the calculation with your own workload.
Before you start
Section titled “Before you start”- Locally: Docker with Buildx, running on your computer.
- For cloud execution: a HyperOptimizer account, a project, and an active trial or subscription with available compute. See plans and compute usage.
- For the CLI path: the HPO CLI. You can also launch from the dashboard.
Local checks do not use your HyperOptimizer allowance. Launching cloud trials does.
1. Create a trial program
Section titled “1. Create a trial program”Create a new directory and save these two files inside it.
import argparseimport jsonimport math
parser = argparse.ArgumentParser()parser.add_argument("--hpo-x", type=float, required=True)args = parser.parse_args()
if not math.isfinite(args.hpo_x): raise ValueError("x must be finite")
loss = (args.hpo_x - 3.0) ** 2print(f"hpo.metrics.loss={json.dumps(loss, allow_nan=False)}", flush=True)The lowest possible loss is 0, at x = 3. Each run evaluates exactly one value of x and exits.
FROM python:3.12-slimWORKDIR /appCOPY main.py .ENTRYPOINT ["python", "-u", "main.py"]ENTRYPOINT keeps the Python command in place when trial arguments are supplied. -u makes Python print without buffering. See image commands and arguments when adapting an existing image.
2. Verify a local trial
Section titled “2. Verify a local trial”Run from the directory containing the two files:
docker buildx build --platform linux/amd64 --load -t hpo-quickstart .docker run --rm --platform linux/amd64 hpo-quickstart --hpo-x=2Expected output:
hpo.metrics.loss=1.0Try --hpo-x=3 as well: the loss should be 0.0. This checks that the argument reaches your calculation and the metric changes with it.
3. Configure and launch
Section titled “3. Configure and launch”Choose one path. Both run the same image with the same parameter and objective.
Log in, then create a configuration for an existing project:
hpo loginhpo initSelect your project when prompted. If you need a new project, use hpo init --create-project quickstart instead of hpo init.
Replace the generated hpo.toml with the following, keeping your actual project ID in [target]:
schemaVersion = 2algorithm = "bayesian"machineSizeId = "nano"maxTrialCount = 10parallelTrialCount = 1maxFailedTrialCount = 3maxRuntimeSecondsPerTrial = 60fixedArgs = []requiredEnv = []
[target]projectId = "YOUR_PROJECT_ID"
[build]context = "."dockerfile = "Dockerfile"repository = "quickstart"platform = "linux/amd64"
[[parameters]]name = "x"slug = "x"type = "double"min = -5max = 5
[[objectives]]name = "loss"type = "minimize"Add .hpo/ to your .gitignore, then validate:
hpo fmthpo validateWhen you are ready to use cloud compute, launch:
hpo optimizeThe CLI builds the image, pushes it to your workspace registry, launches an experiment, and displays trial updates. Open the experiment URL it prints to see results in the dashboard. Validation alone does not launch trials or reserve capacity.
- Open Container Images, copy your registry details, and publish
hpo-quickstart. - Open your project and choose New experiment. Select the published image and tag.
- Add a Continuous value parameter named
x, with slugx, minimum-5, and maximum5. - Keep the default
--hpo-flags. The command arguments should include--hpo-x {{x}}; the image entrypoint already runs Python. - Add objective
losswith direction Minimize. - Choose Bayesian, Nano, 10 trials, 1 parallel trial, a 60-second timeout, and a 3-trial failure limit.
- Review the settings, then launch when you are ready to use cloud compute.
See create an experiment for the full dashboard workflow.
4. Check the results
Section titled “4. Check the results”Open a successful trial and confirm that:
- Its parameters contain
xwithin your configured range. - Its metrics contain a numeric
loss. - Its logs include the same
hpo.metrics.lossline. - Lower loss corresponds to
xcloser to3.
Ten trials are enough to check the integration; they do not guarantee the exact minimum. If trials fail or metrics are absent, use troubleshooting.
Use your own workload
Section titled “Use your own workload”Replace the loss calculation with one evaluation of your model, strategy, or simulation. Update the parser, parameter slugs, and objective names together. Keep the local check before each new cloud experiment.
Next: read and compare results, connect a Python workload, or adapt any Docker image.