Ejemplo n.º 1
0
    def _update_trial_info(self, expr_dir):
        """Update information for given trial.

        Meta file will be loaded if exists, and the trial information
        in db backend will be updated.

        Args:
            expr_dir(str)
        """
        trial_id = expr_dir[-8:]

        meta_file = os.path.join(expr_dir, EXPR_META_FILE)
        meta = parse_json(meta_file)

        result_file = os.path.join(expr_dir, EXPR_RESULT_FILE)
        offset = self._result_offsets.get(trial_id, 0)
        results, new_offset = parse_multiple_json(result_file, offset)
        self._add_results(results, trial_id)
        self._result_offsets[trial_id] = new_offset

        if meta:
            TrialRecord.objects \
                .filter(trial_id=trial_id) \
                .update(trial_status=meta["status"],
                        end_time=timestamp2date(meta.get("end_time", None)))
        elif len(results) > 0:
            metrics = {
                "episode_reward": results[-1].get("episode_reward_mean", None),
                "accuracy": results[-1].get("mean_accuracy", None),
                "loss": results[-1].get("loss", None)
            }
            if results[-1].get("done"):
                TrialRecord.objects \
                    .filter(trial_id=trial_id) \
                    .update(trial_status="TERMINATED",
                            end_time=results[-1].get("date", None),
                            metrics=str(metrics))
            else:
                TrialRecord.objects \
                    .filter(trial_id=trial_id) \
                    .update(metrics=str(metrics))
Ejemplo n.º 2
0
    def _update_trial_info(self, expr_dir):
        """Update information for given trial.

        Meta file will be loaded if exists, and the trial information
        in db backend will be updated.

        Args:
            expr_dir(str)
        """
        trial_id = expr_dir[-8:]

        meta_file = os.path.join(expr_dir, EXPR_META_FILE)
        meta = parse_json(meta_file)

        result_file = os.path.join(expr_dir, EXPR_RESULT_FILE)
        offset = self._result_offsets.get(trial_id, 0)
        results, new_offset = parse_multiple_json(result_file, offset)
        self._add_results(results, trial_id)
        self._result_offsets[trial_id] = new_offset

        if meta:
            TrialRecord.objects \
                .filter(trial_id=trial_id) \
                .update(trial_status=meta["status"],
                        end_time=timestamp2date(meta.get("end_time", None)))
        elif len(results) > 0:
            metrics = {
                "episode_reward": results[-1].get("episode_reward_mean", None),
                "accuracy": results[-1].get("mean_accuracy", None),
                "loss": results[-1].get("loss", None)
            }
            if results[-1].get("done"):
                TrialRecord.objects \
                    .filter(trial_id=trial_id) \
                    .update(trial_status="TERMINATED",
                            end_time=results[-1].get("date", None),
                            metrics=str(metrics))
            else:
                TrialRecord.objects \
                    .filter(trial_id=trial_id) \
                    .update(metrics=str(metrics))