app.train module

File: app/train.py Project: 22HLT01 QUMPHY Contact: oskar.pfeffer@ptb.de Gitlab: https://gitlab.com/qumphy Description: Entry point for training, testing and predicting QUMPHY models.

app.train.load_config(args)[source]

Merge YAML config files and command-line overrides into a single dict.

Reads each YAML file listed in args.config (later files override earlier ones) and then applies the parameter overrides in args.parameters.

Parameters:

args (argparse.Namespace) – Parsed command-line arguments. Must expose config (list of YAML paths) and parameters (iterable of dotted-key/value overrides).

Returns:

Combined configuration dictionary.

Return type:

dict

app.train.main()[source]

CLI entry point: parse arguments and dispatch to Optuna or plain training.

app.train.objective(trial, args, config)[source]

Optuna objective: sample hyperparameters, train, return early-stop score.

For each parameter listed in config["optuna"]["parameters"], the matching Optuna trial.suggest_* function is called with its arguments and the sampled value is written back into config before training.

Return type:

float

Parameters:
  • trial (optuna.trial.Trial) – Trial object provided by the Optuna study.

  • args (argparse.Namespace) – Parsed command-line arguments forwarded to train().

  • config (dict) – Training configuration; mutated in-place with the sampled parameters.

Returns:

Best validation score recorded by the trainer’s early-stopping callback.

Return type:

float

app.train.run_optuna(args, config)[source]

Create and run an Optuna study around objective().

Parameters:
  • args (argparse.Namespace) – Parsed command-line arguments forwarded to objective().

  • config (dict) – Configuration with an "optuna" section providing sampler, direction, optional sampler_arguments, n_trials and timeout.

Returns:

The completed study. Best trial, value and parameters are also printed.

Return type:

optuna.study.Study

app.train.train(args, config)[source]

Run the QUMPHY trainer for the tasks selected in config / args.

Executes fit, test and/or predict depending on whether each task is listed in config["tasks"] or enabled by the matching CLI flag.

Parameters:
  • args (argparse.Namespace) – Parsed command-line arguments providing the fit, test and predict boolean flags.

  • config (dict) – Combined training configuration.

Returns:

The trainer instance after the requested tasks have run.

Return type:

qumphy.trainer.Trainer