Ejemplo n.º 1
0
 def test_call(self):
     with tempfile.TemporaryDirectory() as workdir:
         params = Params({"message": "good morning"})
         storage = Storage(Path(workdir))
         self.worker(params=params, storage=storage)
         assert self.worker.message == "good morning"
         assert self.worker.params["message"] == "good morning"
Ejemplo n.º 2
0
    def from_json(cls, info_dict: tp.Dict[str, tp.Any]) -> RunInfo:
        git_info: tp.Optional[GitInfo] = None
        if info_dict["git"] is not None:
            git_info = GitInfo.from_json(info_dict["git"])

        report: tp.Optional[Report] = None
        if info_dict["report"] is not None:
            report = Report.from_json(info_dict["report"])

        runinfo = RunInfo(
            version=info_dict["version"],
            uuid=info_dict["uuid"],
            name=info_dict["name"],
            module=info_dict["module"],
            execution_path=Path(info_dict["execution_path"]),
            experiment_id=int(info_dict["experiment_id"]),
            experiment_name=info_dict["experiment_name"],
            worker_name=info_dict["worker_name"],
            status=Status(info_dict["status"]),
            params=Params.from_json(info_dict["params"]),
            storage=Storage.from_json(info_dict["storage"]),
            report=report,
            note=info_dict["note"],
            stdout=info_dict["stdout"],
            stderr=info_dict["stderr"],
            platform=PlatformInfo.from_json(info_dict["platform"]),
            git=git_info,
            start_time=_str_to_datetime(info_dict["start_time"]),
            end_time=_str_to_datetime(info_dict["end_time"]),
        )
        return runinfo
Ejemplo n.º 3
0
    def __call__(self,
                 params: Params = None,
                 storage: Storage = None) -> tp.Optional[Report]:
        if params is not None:
            with self.config_scope():
                for key, value in params.items():
                    setattr(self, key, value)

        if storage is not None:
            self._storage = storage

        return self.run()
Ejemplo n.º 4
0
    def __init__(self, name: str) -> None:
        self._name = name

        self._within_config_scope = False
        self.__init_done = True

        self._storage: tp.Optional[Storage] = None

        self._params = Params()

        with self.config_scope():
            self.config()
Ejemplo n.º 5
0
class TestParams:
    def setup(self):
        self.params = Params({"foo": 123})

    def test_set_and_get(self):
        self.params["bar"] = "abc"

        assert self.params["foo"] == 123
        assert self.params["bar"] == "abc"

    def test_to_json(self):
        params_json = self.params.to_json()

        assert isinstance(params_json, dict)
        assert params_json["foo"] == 123
Ejemplo n.º 6
0
    def test_delete_run(self):
        with tempfile.TemporaryDirectory() as tempdir:
            rootdir = Path(tempdir)

            store = LogStore(rootdir)

            experiment_id = store.create_experiment(self.experiment)
            run_id = store.create_run(experiment_id, self.worker_name)

            run_info = RunInfo(
                version=VERSION,
                uuid=run_id,
                name="test run",
                module="test_module",
                execution_path=Path("test/path"),
                experiment_id=experiment_id,
                experiment_name=self.experiment_name,
                worker_name=self.worker_name,
                status=Status.FINISHED,
                params=Params({"test": "params"}),
                report=Report({"test": "report"}),
                storage=store.get_storage(experiment_id, run_id),
                platform=get_platform_info(),
                git=get_git_info(),
                note="test note",
                stdout="test stdout",
                stderr="test stderr",
                start_time=datetime.datetime.now(),
                end_time=datetime.datetime.now(),
            )

            store.save_run(run_info)

            assert (rootdir / str(experiment_id) / self.worker_name /
                    run_id).exists()

            runinfos = store.delete_run(run_id)

            assert not (rootdir / str(experiment_id) / self.worker_name /
                        run_id).exists()
Ejemplo n.º 7
0
def load_params_from_jsonnet(path: str) -> Params:
    ext_vars = _environment_variables()
    jsondict = json.loads(evaluate_file(str(path), ext_vars=ext_vars))
    return Params.from_json(jsondict)
Ejemplo n.º 8
0
 def _load_params(path: Path):
     with open(path, "r") as f:
         params_dict = json.load(f)
     return Params.from_json(params_dict)
Ejemplo n.º 9
0
 def setup(self):
     self.params = Params({"foo": 123})