示例#1
0
    def get_trial(self):
        """
        Returns the next trial from a Sherpa Study.

        Returns:
            sherpa.core.Trial: The trial to run.
        """
        if self.test_mode:
            return sherpa.Trial(id=1, parameters={})

        assert os.environ.get(
            'SHERPA_TRIAL_ID'
        ), "Environment-variable SHERPA_TRIAL_ID not found. Scheduler needs to set this variable in the environment when submitting a job"
        trial_id = int(os.environ.get('SHERPA_TRIAL_ID'))
        for _ in range(5):
            g = (entry
                 for entry in self.db.trials.find({'trial_id': trial_id}))
            t = next(g)
            if t:
                break
            time.sleep(10)
        if not t:
            raise RuntimeError("No Trial Found!")
        return sherpa.Trial(id=t.get('trial_id'),
                            parameters=t.get('parameters'))
示例#2
0
    def get_trial(self):
        """
        Returns the next trial from a Sherpa Study.

        Returns:
            sherpa.core.Trial: The trial to run.
        """
        if self.test_mode:
            return sherpa.Trial(id=1, parameters={})

        assert os.environ.get(
            'SHERPA_TRIAL_ID'
        ), "Environment-variable SHERPA_TRIAL_ID not found. Scheduler needs to set this variable in the environment when submitting a job"
        trial_id = int(os.environ.get('SHERPA_TRIAL_ID'))

        logging.disable(logging.CRITICAL)

        with FileLock(self.trials_file_name + '.lock'):
            with open(self.trials_file_name, 'r') as f:
                trials = json.load(f)
                return sherpa.Trial(id=trial_id,
                                    parameters=trials[str(trial_id)])

        logging.disable(logging.NOTSET)
示例#3
0
def get_test_trial(id=1):
    p = {'a': 1, 'b': 2}
    t = sherpa.Trial(id, p)
    return t
示例#4
0
def test_trial():
    p = {'a': 1, 'b': 2}
    t = sherpa.Trial(1, p)
    assert t.id == 1
    assert t.parameters == p
示例#5
0
def test_study_add_observation_invalid_trial():
    s = get_mock_study()
    with pytest.raises(ValueError):
        s.add_observation(trial=sherpa.Trial(id=1, parameters={'abcd': 1}), objective=0.1, context={'other_metrics': 0.2}, iteration=1)