optimas-org / optimas

Optimization at scale, powered by libEnsemble
https://optimas.readthedocs.io
Other
22 stars 13 forks source link

Support changing the range and fixing the value of `VaryingParameter`s #150

Closed AngelFP closed 9 months ago

AngelFP commented 9 months ago

This PR adds support for interactive explorations where the range of varying parameters can be updated, or their values fixed. For example:

var1 = VaryingParameter("x0", -50.0, 5.0)
var2 = VaryingParameter("x1", -5.0, 15.0)
obj = Objective("f", minimize=False)

generator = AxSingleFidelityGenerator(
    varying_parameters=[var1, var2],
    objectives=[obj],
    fit_out_of_design=True,
)
evaluator = FunctionEvaluator(function=eval_func_sf)
exploration = Exploration(
    generator=generator,
    evaluator=evaluator,
    sim_workers=2,
)

# Run 5 evals with default parameters
exploration.run(n_evals=5)

# Change range of x0 and run 10 evals
var1.update_range(-20., 0.)
generator.update_parameter(var1)
exploration.run(n_evals=10)

# Fix value of x0 and run 5 evals
var1.fix_value(-9)
generator.update_parameter(var1)
exploration.run(n_evals=5)

# Free value of x0 and run 5 evals
var1.free_value()
generator.update_parameter(var1)
exploration.run(n_evals=5)

Currently, only the generators based on the Ax service API support updating the parameters. Support for other generators will be added in future PRs.

In order to support VaryingParameters with a fixed value, a set of fixed_features needs to be passed to Ax. This, however, is not currently possible with the Service API (unless https://github.com/facebook/Ax/pull/2015 or something similar is merged). Therefore, this PR defines a CustomAxClient derived class that modifies get_next_trial to support fixed_features.

Other changes