def _check_trial_id(self, trial_id):
     if not isinstance(trial_id, int):
         msg = 'Trial id must be integer, given: {}{}'
         msg.format(trial_id, type(trial_id))
         raise TrialIDNotFoundError(msg.format(trial_id, type(trial_id)))
     if trial_id <= 0 or self.trial_id < trial_id:
         raise TrialIDNotFoundError(trial_id)
Exemple #2
0
 def current_trial_id(self):
     # read-only
     if self._running:
         return self._current_trial_id
     else:
         msg = "Current Trial ID only exists during a trial execution"
         raise TrialIDNotFoundError(msg)
Exemple #3
0
 def current_trial_id(self):
     if self.is_locked():
         # TODO: is locked by myself?
         return self._current_trial_id
     else:
         msg = "Current Trial ID only exists during a trial execution"
         raise TrialIDNotFoundError(msg)
Exemple #4
0
 def _load_single(self, trial_id):
     """
     Loading single metric from single trial id
     """
     try:
         return self.values[trial_id]
     except KeyError:
         # TODO: read from file
         raise TrialIDNotFoundError(trial_id)
Exemple #5
0
 def load_text(self, key):
     """
     Load text from key (pathlib.Path)
     """
     assert isinstance(key, pathlib.Path)
     try:
         return key.read_text()
     except FileNotFoundError:
         raise TrialIDNotFoundError(key)
Exemple #6
0
 def load_object(self, key):
     """
     Load object from key (pathlib.Path)
     """
     assert isinstance(key, pathlib.Path)
     try:
         return pickle.load(key)
     except FileNotFoundError:
         raise TrialIDNotFoundError(key)
Exemple #7
0
    def load_object(self, key):
        """
        Load object from key
        """
        assert isinstance(key, (str, bytes)), key
        res = self.get(key)

        if res is None:
            raise TrialIDNotFoundError(key)
        else:
            return pickle.loads(res)
Exemple #8
0
    def load_object(self, key):
        """
        Load object from key
        """
        self._validate_key(key)
        res = self.get(key)

        if res is None:
            raise TrialIDNotFoundError(key)
        else:
            return self.loads_object(res)
Exemple #9
0
    def load_text(self, key):
        """
        Load code context from file
        """
        assert isinstance(key, (str, bytes)), key
        res = self.client.get(key)

        if res is None:
            # TODO: define better exception
            # key may not contain trial id
            raise TrialIDNotFoundError(key)
        else:
            return res.decode('utf-8')
Exemple #10
0
    def load_text(self, key):
        """
        Load code context from file
        """
        self._validate_key(key)
        res = self.get(key)

        if res is None:
            # TODO: define better exception
            # key may not contain trial id
            raise TrialIDNotFoundError(key)
        else:
            return self._finalize_text(res)
Exemple #11
0
    def _load_single(self, metric_key, trial_id):
        key = self.backend.get_metric_key(metric_key, trial_id)
        values = self.backend.get_list(key)

        if values is None or len(values) == 0:
            if metric_key not in self.keys():
                msg = 'Unable to find saved metric with specified key: {}'
                raise ValueError(msg.format(metric_key))
            else:
                raise TrialIDNotFoundError(trial_id)

        values = [pickle.loads(value) for value in values]

        return self._wrap_single_result(values, trial_id)
    def _load_single_environment(self, env, trial_id):
        """
        Load single environment instance
        """
        if trial_id is None:
            return env

        key = self.backend.get_environment_key(env.key, trial_id, env.ext)
        try:
            text = self.backend.load_text(key)
        except TrialIDNotFoundError:
            # overwrite message using trial_id
            raise TrialIDNotFoundError(trial_id)
        return env.loads(text)