chap_core.runners package

Submodules

chap_core.runners.command_line_runner module

class chap_core.runners.command_line_runner.CommandLineRunner(working_dir: str | Path)[source]

Bases: Runner

run_command(command)[source]
store_file()[source]
class chap_core.runners.command_line_runner.CommandLineTrainPredictRunner(runner: CommandLineRunner, train_command: str, predict_command: str, model_configuration_filename: str | None = None)[source]

Bases: TrainPredictRunner

predict(model_file_name, historic_data, future_data, output_file, polygons_file_name=None)[source]
train(train_file_name, model_file_name, polygons_file_name=None)[source]
chap_core.runners.command_line_runner.run_command(command: str, working_directory=PosixPath('.'))[source]

Runs a unix command using subprocess

chap_core.runners.conda_runner module

class chap_core.runners.conda_runner.CondaRunner(conda_yaml_file: str)[source]

Bases: Runner

chap_core.runners.docker_runner module

class chap_core.runners.docker_runner.DockerRunner(docker_name: str, working_dir: str | Path, model_configuration_filename: str | None = None)[source]

Bases: Runner

Runs through a docker image specified by name (e.g. on dockerhub), not a Dockerfile

run_command(command)[source]
teardown()[source]

To be called after the runner is done with train and predict. This is to clean up the runner, e.g. to remove docker images, etc

class chap_core.runners.docker_runner.DockerTrainPredictRunner(runner: DockerRunner, train_command: str, predict_command: str, model_configuration_filename: str | None = None)[source]

Bases: CommandLineTrainPredictRunner

This is basically a CommandLineTrainPredictRunner, but with a DockerRunner instead of a CommandLineRunner as runner

teardown()[source]

chap_core.runners.helper_functions module

chap_core.runners.helper_functions.get_train_predict_runner(mlproject_file: Path, runner_type: Literal['mlflow', 'docker'], skip_environment=False) TrainPredictRunner[source]

Returns a TrainPredictRunner based on the runner_type. If runner_type is “mlflow”, returns an MlFlowTrainPredictRunner. If runner_type is “docker”, the mlproject file is parsed to create a runner if skip_environment, mlflow and docker is not used, instead returning a TrainPredictRunner that uses the command line

chap_core.runners.helper_functions.get_train_predict_runner_from_model_template_config(model_template_config: ModelTemplateConfigV2, working_dir: Path, skip_environment=False, model_configuration: ModelConfiguration | None = None) TrainPredictRunner[source]

Utility function that returns a suitbale runner for a model given a ModelTemplateConfig (which contains information about what runner the Template says that its models shold use) Returns a TrainPredictRunner (e.g. a MlFlowTrainPredictRunner or a DockerTrainPredictRunner) by parsing the config for the template.

chap_core.runners.mlflow_runner module

class chap_core.runners.mlflow_runner.MlFlowTrainPredictRunner(model_path, model_configuration_filename=None, train_params=None)[source]

Bases: TrainPredictRunner

predict(model_file_name, historic_data, future_data, output_file, polygons_file_name=None)[source]
train(train_file_name, model_file_name, polygons_file_name=None)[source]

chap_core.runners.runner module

class chap_core.runners.runner.Runner[source]

Bases: object

An interface for Runners. A runner is able to run “something”, e.g. a command on the command line through Docker.

run_command(command)[source]
store_file(file_path)[source]
teardown()[source]

To be called after the runner is done with train and predict. This is to clean up the runner, e.g. to remove docker images, etc

class chap_core.runners.runner.TrainPredictRunner[source]

Bases: ABC

Specific wrapper for runners that only run train/predict commands

abstractmethod predict(model_file_name: str, historic_data: str, future_data: str, output_file: str, polygons_file_name: str | None)[source]
teardown()[source]
abstractmethod train(train_data: str, model_file_name: str, polygons_file_name: str | None)[source]

Module contents