def test_dimension_prior_change_backward_incompatible_dimensions( self, disjoint_prior, small_prior, trials): """Test :meth:`orion.core.evc.adapters.DimensionPriorChange.backward` with incompatible priors, such that all trials are filtered out """ dimension_prior_change_adapter = DimensionPriorChange( "small_prior", disjoint_prior, small_prior) adapted_trials = dimension_prior_change_adapter.backward(trials) assert len(adapted_trials) == 0
def test_dimension_prior_change_backward(self, large_prior, small_prior, trials): """Test :meth:`orion.core.evc.adapters.DimensionPriorChange.backward` with compatible priors """ dimension_prior_change_adapter = DimensionPriorChange( "large_prior", large_prior, small_prior) adapted_trials = dimension_prior_change_adapter.backward(trials) assert len(adapted_trials) == len(trials)
def test_dimension_prior_change_backward_different_shapes( self, small_prior, prior_with_shape, trials): """Test :meth:`orion.core.evc.adapters.DimensionPriorChange.backward` with priors of different shapes """ dimension_prior_change_adapter = DimensionPriorChange( "small_prior", small_prior, prior_with_shape) trials = generate_trials({"small_prior": prior_with_shape}, 10) adapted_trials = dimension_prior_change_adapter.backward(trials) assert len(adapted_trials) == 0
def test_dimension_prior_change_forward_different_shapes( self, small_prior, prior_with_shape, trials, caplog): """Test :meth:`orion.core.evc.adapters.DimensionPriorChange.forward` with priors of different shapes """ with caplog.at_level(logging.WARNING): dimension_prior_change_adapter = DimensionPriorChange( "small_prior", small_prior, prior_with_shape) assert ("Oríon does not support yet adaptations on prior shape changes" in caplog.records[0].msg) trials = generate_trials({"small_prior": small_prior}, 10) adapted_trials = dimension_prior_change_adapter.forward(trials) assert len(adapted_trials) == 0
def test_dimension_prior_change_init_with_bad_dimensions(self): """Test initialization of :class:`orion.core.evc.adapters.DimensionPriorChange` with non valid string definitions of dimension prior """ with pytest.raises(TypeError) as exc_info: DimensionPriorChange("dummy", "bad", "priors") assert "Parameter 'old': Please provide a valid form for prior" in str( exc_info.value)
def test_dimension_prior_change_configuration(small_prior, large_prior): """Test :meth:`orion.core.evc.adapters.DimensionPriorChange.configuration`""" dimension_name = "small_prior" dimension_prior_change_adapter = DimensionPriorChange( dimension_name, small_prior, large_prior) configuration = dimension_prior_change_adapter.configuration[0] assert configuration["of_type"] == "dimensionpriorchange" assert configuration["name"] == dimension_name assert configuration["old_prior"] == small_prior assert configuration["new_prior"] == large_prior assert (BaseAdapter.build( [configuration]).adapters[0].configuration[0] == configuration)
def test_dimension_prior_change_init_with_dimensions( self, large_prior, small_prior): """Test initialization of :class:`orion.core.evc.adapters.DimensionPriorChange` with valid string definitions of dimension prior """ dimension_prior_change = DimensionPriorChange("dummy", large_prior, small_prior) assert dimension_prior_change.old_prior == large_prior assert dimension_prior_change.new_prior == small_prior assert isinstance(dimension_prior_change.old_dimension, Real) assert isinstance(dimension_prior_change.new_dimension, Real) assert dimension_prior_change.old_dimension.interval() == (0, 1000) assert dimension_prior_change.new_dimension.interval() == (0, 10)