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

Feature/interface updates #250

Open
wants to merge 4 commits into
base: standardization
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions optimas/gen_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def persistent_generator(H, persis_info, gen_specs, libE_info):
# Check how many simulations have returned
n = len(calc_in["sim_id"])
# Feed the latest simulation results to the generator
trials = []
for i in range(n):
trial_index = int(calc_in["trial_index"][i])
trial_status = calc_in["trial_status"][i]
Expand All @@ -107,8 +108,11 @@ def persistent_generator(H, persis_info, gen_specs, libE_info):
y = calc_in[par.name][i]
ev = Evaluation(parameter=par, value=y)
trial.complete_evaluation(ev)
# Register trial with unknown SEM
generator.tell_trials([trial])
trials.append(trial)

# Register trials with unknown SEM
generator.tell_trials(trials)

# Set the number of points to generate to that number:
number_of_gen_points = min(n + n_failed_gens, max_evals - n_gens)
n_failed_gens = 0
Expand Down
3 changes: 2 additions & 1 deletion optimas/generators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from .grid_sampling import GridSamplingGenerator
from .line_sampling import LineSamplingGenerator
from .random_sampling import RandomSamplingGenerator

from .external import ExternalGenerator

__all__ = [
"AxSingleFidelityGenerator",
Expand All @@ -32,4 +32,5 @@
"GridSamplingGenerator",
"LineSamplingGenerator",
"RandomSamplingGenerator",
"ExternalGenerator",
]
25 changes: 25 additions & 0 deletions optimas/generators/external.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""Contains the definition of an external generator."""

from .base import Generator


class ExternalGenerator(Generator):
Copy link
Collaborator Author

@shuds13 shuds13 Nov 13, 2024

Choose a reason for hiding this comment

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

The reason this wrapper is necessary is that Optimas generators contain a number of variables that are not present in our generators such as varying_parameters etc... (basically everything in the Optimas generator constructors). By wrapping the generator like this, we can allow Optimas functions to make the necessary updates to those data structures (e.g., in ask_trials/tell_trials), while the actual ask/tell() functions only deal with the standard.

As libEnsemble generators do not inherit from Optimas generators, we don't have those, so there has to be some way to give Optimas VaryingParameters etc...

Copy link
Collaborator Author

@shuds13 shuds13 Nov 13, 2024

Choose a reason for hiding this comment

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

The only other thing I can think would be to pass VaryingParameters etc.. into Optimas as a separate config, alongside the standard (or libE) generator. And Optimas could create the wrapper internally, maybe. I'm not sure thats preferable though.

I guess for Optimas to be fully supportive of the generator standard, the constructors still need updating. So Variables is converted to VaryingParameters, but there is still a lot of extra options for Optimas gens (e.g custom_trial_parameters or allow_fixed_parameters)

"""Supports a generator in the CAMPA generator standard."""

def __init__(
self,
ext_gen,
**kwargs,
):
super().__init__(
**kwargs,
)
self.gen = ext_gen

def ask(self, n_trials):
"""Request the next set of points to evaluate."""
return self.gen.ask(n_trials)

def tell(self, trials):
"""Send the results of evaluations to the generator."""
self.gen.tell(trials)
Loading