Exemplo n.º 1
0
    def save(self, configs_path: PurePath):
        configs = {
            'values': self.parser.values,
            'options': {},
            'list_appends': {k: True for k in self.parser.list_appends},
            'computed': {},
            'order': self.calculator.topological_order
        }

        for k, opts in self.parser.options.items():
            configs['options'][k] = list(opts.keys())

        for k in self.parser.types:
            computed = getattr(self.calculator.configs, k, None)
            if computed is None:
                continue

            computed_str = str(computed)
            if len(computed_str) > 100:
                computed_str = computed_str[:150]

            configs['computed'][k] = computed_str

        with open(str(configs_path), "w") as file:
            file.write(util.yaml_dump(configs))
Exemplo n.º 2
0
    def save_info(self):
        run_path = Path(self.run_path)
        if not run_path.exists():
            run_path.mkdir(parents=True)

        with open(str(self.info_path), "w") as file:
            file.write(util.yaml_dump(self.to_dict()))
Exemplo n.º 3
0
    def save(self, configs_path: PurePath):
        orders = {k: i for i, k in enumerate(self.calculator.topological_order)}
        configs = {}
        for k, v in self.parser.types.items():
            configs[k] = {
                'name': k,
                'type': str(v),
                'value': self.__to_yaml(self.parser.values.get(k, None)),
                'order': orders.get(k, -1),
                'options': list(self.parser.options.get(k, {}).keys()),
                'computed': self.__to_yaml(getattr(self.calculator.configs, k, None))
            }

        with open(str(configs_path), "w") as file:
            file.write(util.yaml_dump(configs))
Exemplo n.º 4
0
    def _log_trial(self, is_add: bool):
        """
        ### Log trial

        This will add or update a trial in the `trials.yaml` file
        """
        try:
            with open(str(self.info.trials_log_file), "r") as file:
                trials = util.yaml_load(file.read())
        except FileNotFoundError:
            trials = []

        if is_add:
            trials.append(self.trial.to_dict())
        else:
            trials[-1] = self.trial.to_dict()

        with open(str(self.info.trials_log_file), "w") as file:
            file.write(util.yaml_dump(trials))
Exemplo n.º 5
0
    def save_artifactors(self, file: PurePath):
        self.__artifacts_file = file

        artifacts = {k: art.to_dict() for k, art in self.artifacts.items()}
        with open(str(file), "w") as file:
            file.write(util.yaml_dump(artifacts))
Exemplo n.º 6
0
    def save_indicators(self, file: PurePath):
        self.__indicators_file = file

        indicators = {k: ind.to_dict() for k, ind in self.indicators.items()}
        with open(str(file), "w") as file:
            file.write(util.yaml_dump(indicators))