Skip to content

Commit

Permalink
Adding failure information to failure file. (#247)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaheba committed Aug 16, 2019
1 parent 68bee6d commit 47f272c
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions src/gluonts/shell/__main__.py
Expand Up @@ -14,6 +14,7 @@
# Standard library imports
import logging
import pydoc
import traceback
from pathlib import Path
from typing import Optional, Type, Union, cast

Expand Down Expand Up @@ -151,22 +152,26 @@ def train_command(data_path: str, forecaster: Optional[str]) -> None:
from gluonts.shell import train

logging.info("Run 'train' command")

env = TrainEnv(Path(data_path))

if forecaster is None:
try:
forecaster = env.hyperparameters["forecaster_name"]
except KeyError:
msg = (
"Forecaster shell parameter is `None`, but "
"the `forecaster_name` key is not defined in the "
"hyperparameters.json dictionary."
)
raise GluonTSForecasterNotFoundError(msg)

assert forecaster is not None
train.run_train_and_test(env, forecaster_type_by_name(forecaster))
try:
if forecaster is None:
try:
forecaster = env.hyperparameters["forecaster_name"]
except KeyError:
msg = (
"Forecaster shell parameter is `None`, but "
"the `forecaster_name` key is not defined in the "
"hyperparameters.json dictionary."
)
raise GluonTSForecasterNotFoundError(msg)

assert forecaster is not None
train.run_train_and_test(env, forecaster_type_by_name(forecaster))
except Exception:
with open(env.path.output / "failure", "w") as out_file:
out_file.write(traceback.format_exc())
raise


if __name__ == "__main__":
Expand Down

0 comments on commit 47f272c

Please sign in to comment.