예제 #1
0
    def test_dimension_addition_backward_not_existing(self, trials):
        """Test :meth:`orion.core.evc.adapters.DimensionAddition.backward`
        with valid param and invalid trials because param does not exist
        """
        new_param = Trial.Param(name="second_normal_prior",
                                type="integer",
                                value=1)
        dimension_addition_adapter = DimensionAddition(new_param)

        with pytest.raises(RuntimeError) as exc_info:
            dimension_addition_adapter.backward(trials)
        assert "Provided trial does not have a compatible configuration" in str(
            exc_info.value)
예제 #2
0
    def test_dimension_addition_backward(self, dummy_param, trials):
        """Test :meth:`orion.core.evc.adapters.DimensionAddition.backward`
        with valid param and valid trials
        """
        new_param = Trial.Param(name="second_normal_prior",
                                type="integer",
                                value=1)
        dimension_addition_adapter = DimensionAddition(new_param)

        sampler = DimensionBuilder().build("random",
                                           "uniform(10, 100, discrete=True)")
        for trial in trials:
            random_param = new_param.to_dict()
            random_param["value"] = sampler.sample()
            trial._params.append(Trial.Param(**random_param))

        adapted_trials = dimension_addition_adapter.backward(trials)
        assert len(adapted_trials) == 0

        trials[0]._params[-1].value = 1
        assert trials[0]._params[-1] == new_param

        adapted_trials = dimension_addition_adapter.backward(trials)
        assert len(adapted_trials) == 1

        trials[4]._params[-1].value = 1
        assert trials[4]._params[-1] == new_param

        adapted_trials = dimension_addition_adapter.backward(trials)
        assert len(adapted_trials) == 2

        trials[-1]._params[-1].value = 1
        assert trials[-1]._params[-1] == new_param

        adapted_trials = dimension_addition_adapter.backward(trials)
        assert len(adapted_trials) == 3

        assert new_param not in (adapted_trials[0]._params)
        assert new_param not in (adapted_trials[1]._params)
        assert new_param not in (adapted_trials[2]._params)