Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Desirability functions as objectives #497

Merged
merged 31 commits into from
Jan 21, 2025

Conversation

LukasHebing
Copy link
Contributor

  • added a file with data-models 3 different Desirability functions: Increasing, Decreasing, and Peak Desirability
  • Some options for the function design (bounds, clipping, concave/convex form
  • Added torch executables into torch_tools.py
  • Tests for data-models and objectives added
  • A demonstration notebook, on how the functions look is added as example

@LukasHebing
Copy link
Contributor Author

LukasHebing commented Jan 10, 2025

There are some Linting errors. I dont know why pyright doesnt find anything for all the objective classes? Even the old ones:

Error: Cannot access member "peak_position" for type "MinimizeSigmoidObjective"
Member "peak_position" is unknown (reportGeneralTypeIssues)
/home/runner/work/bofire/bofire/bofire/utils/torch_tools.py:494:70 - error: Cannot access member "peak_position" for type "TargetObjective"
Member "peak_position" is unknown (reportGeneralTypeIssues)

@LukasHebing
Copy link
Contributor Author

entmoot on python 3.9 is still responsible for the failing tests (see #493)

@LukasHebing
Copy link
Contributor Author

@jduerholt: I really don`t know, how to fix the linting errors of the data-models. Field definitions of the other objectives are unchanged, still pyright wants to validate fields from other objectives, e.g.:

Error: Cannot access member "lower_bound" for type "CloseToTargetObjective"
Member "lower_bound" is unknown (reportGeneralTypeIssues)
/home/runner/work/bofire/bofire/bofire/utils/torch_tools.py:503:58 - error: Cannot access member "lower_bound" for type "ConstrainedCategoricalObjective"
Member "lower_bound" is unknown (reportGeneralTypeIssues)

@jduerholt
Copy link
Contributor

Hi @LukasHebing, I had a day off yesterday, I will have a look today. Best, Johannes

@jduerholt
Copy link
Contributor

Hi @LukasHebing, I had a day off yesterday, I will have a look today. Best, Johannes PS: We merged the PR that drops the python 3.9 support. So the errors due to entmoot should be gone, if you merge main in.

Copy link
Contributor

@jduerholt jduerholt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LukasHebing: Thanks!

I did a first pass with some general remarks. Regarding the linting: Maybe it stems from the not provided type argument for the new objectives?

bofire/data_models/objectives/desirabilities.py Outdated Show resolved Hide resolved
bofire/data_models/objectives/desirabilities.py Outdated Show resolved Hide resolved
bofire/data_models/objectives/desirabilities.py Outdated Show resolved Hide resolved
bofire/utils/torch_tools.py Outdated Show resolved Hide resolved
@LukasHebing
Copy link
Contributor Author

LukasHebing commented Jan 16, 2025

The failing test is due to changes in the main branch:
features_to_idx_mapper in map_HammingDistanceKernel seems to cause a problem

[Edit]
That failed test disappeared. Very strange

@LukasHebing
Copy link
Contributor Author

@jduerholt:
Do you have any idea, why tests in test_ask.py are failing, which have nothing to do with this PR? It seems to originate in the acquisition function qNegInt. But specifications of these tests is very difficult. I think, this is not due to any of this changes.

_________ test_ask_single_objective[SoboStrategy-spec3-False-False-2] __________

cls = <class 'bofire.data_models.strategies.predictives.sobo.SoboStrategy'>
spec = {'acquisition_function': qNegIntPosVar(type='qNegIntPosVar', n_mc_samples=128, weights={'y_1': 0.5, 'y_2': 0.5}), 'cat...ctive(type='MaximizeObjective', w=1.0, bounds=[0, 1]))]), constraints=Constraints(type='Constraints', constraints=[]))}
categorical = False, descriptor = False, candidate_count = 2

@pytest.mark.parametrize(
    "cls, spec, categorical, descriptor, candidate_count",
    [
        (cls, specs, categorical, descriptor, random.randint(1, 2))
        for cls, specs in STRATEGY_SPECS_SINGLE_OBJECTIVE.items()
        for categorical in [True, False]
        for descriptor in [True, False]
    ],
)
# @pytest.mark.slow
def test_ask_single_objective(cls, spec, categorical, descriptor, candidate_count):
    # generate data
    benchmark = Ackley(categorical=categorical, descriptor=descriptor)
    random_strategy = RandomStrategy(
        data_model=RandomStrategyDataModel(domain=benchmark.domain),
    )
    experiments = benchmark.f(random_strategy.ask(10), return_complete=True)

    # set up of the strategy
  data_model = cls(**{**spec, "domain": benchmark.domain})

E pydantic_core._pydantic_core.ValidationError: 7 validation errors for SoboStrategy
E acquisition_function.qNEI
E Input should be a valid dictionary or instance of qNEI [type=model_type, input_value=qNegIntPosVar(type='qNegI...'y_1': 0.5, 'y_2': 0.5}), input_type=qNegIntPosVar]
E For further information visit https://errors.pydantic.dev/2.10/v/model_type
E acquisition_function.qEI
E Input should be a valid dictionary or instance of qEI [type=model_type, input_value=qNegIntPosVar(type='qNegI...'y_1': 0.5, 'y_2': 0.5}), input_type=qNegIntPosVar]
E For further information visit https://errors.pydantic.dev/2.10/v/model_type
E acquisition_function.qSR
E Input should be a valid dictionary or instance of qSR [type=model_type, input_value=qNegIntPosVar(type='qNegI...'y_1': 0.5, 'y_2': 0.5}), input_type=qNegIntPosVar]
E For further information visit https://errors.pydantic.dev/2.10/v/model_type
E acquisition_function.qUCB
E Input should be a valid dictionary or instance of qUCB [type=model_type, input_value=qNegIntPosVar(type='qNegI...'y_1': 0.5, 'y_2': 0.5}), input_type=qNegIntPosVar]
E For further information visit https://errors.pydantic.dev/2.10/v/model_type
E acquisition_function.qPI
E Input should be a valid dictionary or instance of qPI [type=model_type, input_value=qNegIntPosVar(type='qNegI...'y_1': 0.5, 'y_2': 0.5}), input_type=qNegIntPosVar]
E For further information visit https://errors.pydantic.dev/2.10/v/model_type
E acquisition_function.qLogEI
E Input should be a valid dictionary or instance of qLogEI [type=model_type, input_value=qNegIntPosVar(type='qNegI...'y_1': 0.5, 'y_2': 0.5}), input_type=qNegIntPosVar]
E For further information visit https://errors.pydantic.dev/2.10/v/model_type
E acquisition_function.qLogNEI
E Input should be a valid dictionary or instance of qLogNEI [type=model_type, input_value=qNegIntPosVar(type='qNegI...'y_1': 0.5, 'y_2': 0.5}), input_type=qNegIntPosVar]
E For further information visit https://errors.pydantic.dev/2.10/v/model_type

@jduerholt
Copy link
Contributor

This is kind of a Heisenbug, I have to take some time and tidy up these tests, it some kind of legacy back from everest and is very messy. Just ignore them for now.

@jduerholt
Copy link
Contributor

That failed test disappeared. Very strange

It has been fixed on main, I assume it is vanished due to this ;)

@LukasHebing
Copy link
Contributor Author

Works now, only the linting error remains.
@jduerholt: Can this be skipped?

Copy link
Contributor

@jduerholt jduerholt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Lukas,

looks good to me. Only some smaller comments regarding inheritance and testing.

Best,

Johannes

bofire/data_models/objectives/desirabilities.py Outdated Show resolved Hide resolved
pyright_output.txt Outdated Show resolved Hide resolved
tests/bofire/data_models/objectives/test_desirabilities.py Outdated Show resolved Hide resolved
@LukasHebing
Copy link
Contributor Author

@jduerholt : If we ignore the linting (don`t know how to fix that), I fixed everything. Let me know, if we can merge

Copy link
Contributor

@jduerholt jduerholt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thanks!

@jduerholt jduerholt merged commit 4d6d6c6 into main Jan 21, 2025
9 of 10 checks passed
@jduerholt jduerholt deleted the feature/desirability_functions branch January 21, 2025 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants