-
Notifications
You must be signed in to change notification settings - Fork 18
Attempt to make optimas generators compatible with generator standard
#249
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
Changes from 68 commits
fbd8b0a
2fc7992
db6e2bc
522dd9c
2445546
0487226
55400dd
a879df1
cee853e
b29c7b5
cb7a90e
d361865
2a8053e
db32626
687fe52
c233aa9
38438bf
d33ccb0
cd01075
e1022a3
2d72c63
6a3d111
e7e1d5b
7cfa798
f66c716
3668aaf
4dc2a95
3494360
ac7c618
318d7f0
4fc1f49
695cb5a
d1f11ff
682f7d1
f5045cd
8df32a6
fb4bfbc
31fa71b
72fce60
f58ab4e
298772c
a735cdd
7660387
d6ff991
6037af8
df59180
907003f
0ce0ec2
56ea9ec
4bf8c28
427bcdd
c105ef2
fbeaec3
e747542
01f712b
e516585
939aea0
48c83e8
c66e09f
8d9bc44
af2b0d4
4a3f0c7
f14f3c5
cd694e0
e858bae
b7ae657
bfc4fad
082bded
5b9d514
3dc27c6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,7 @@ def persistent_generator(H, persis_info, gen_specs, libE_info): | |
| """Generate and launch evaluations with the optimas generators. | ||
|
|
||
| This function gets the generator object and uses it to generate new | ||
| evaluations via the `ask` method. Once finished, the result of the | ||
| evaluations via the `ask_trials` method. Once finished, the result of the | ||
| evaluations is communicated back to the generator via the `tell` method. | ||
|
|
||
| This is a persistent generator function, i.e., it is called by a dedicated | ||
|
|
@@ -68,7 +68,7 @@ def persistent_generator(H, persis_info, gen_specs, libE_info): | |
| # Ask the optimizer to generate `batch_size` new points | ||
| # Store this information in the format expected by libE | ||
| H_o = np.zeros(number_of_gen_points, dtype=gen_specs["out"]) | ||
| generated_trials = generator.ask(number_of_gen_points) | ||
| generated_trials = generator.ask_trials(number_of_gen_points) | ||
| for i, trial in enumerate(generated_trials): | ||
| for var, val in zip( | ||
| trial.varying_parameters, trial.parameter_values | ||
|
|
@@ -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] | ||
|
|
@@ -107,8 +108,12 @@ 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([trial]) | ||
| generator.tell_trials([trial]) | ||
| trials.append(trial) | ||
|
|
||
| # Register trials with unknown SEM | ||
| # generator.tell_trials(trials) # Give as batch | ||
|
||
|
|
||
| # 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 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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", | ||
|
|
@@ -32,4 +32,5 @@ | |
| "GridSamplingGenerator", | ||
| "LineSamplingGenerator", | ||
| "RandomSamplingGenerator", | ||
| "ExternalGenerator", | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it make sense to add a test for this object in the CI?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes |
||
| ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -196,10 +196,18 @@ def __init__( | |
| model_save_period: Optional[int] = 5, | ||
| model_history_dir: Optional[str] = "model_history", | ||
| ) -> None: | ||
| # SH note for standardization | ||
RemiLehe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # As trial parameters these get written to history array | ||
| # Ax trial_index and arm toegther locate a point | ||
| # Multiple points (Optimas trials) can share the same Ax trial_index | ||
| # Standard (VOCS) does not have equiv. of trial parameters -> would be variables. | ||
| # If want to use _id can have a mapping inside the generator, but those | ||
| # points that are part of same ax trial_index will not be seen in history. | ||
RemiLehe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| custom_trial_parameters = [ | ||
| TrialParameter("arm_name", "ax_arm_name", dtype="U32"), | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a follow-up PR, let us consider how to fit this in the VOCS format and/or whether to convert |
||
| TrialParameter("trial_type", "ax_trial_type", dtype="U32"), | ||
| TrialParameter("trial_index", "ax_trial_index", dtype=int), | ||
| # SH changed from trial_index to ax_trial_id - trial_index is usually Optimas index? | ||
RemiLehe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| TrialParameter("ax_trial_id", "ax_trial_index", dtype=int), | ||
| ] | ||
| self._check_inputs(varying_parameters, objectives, lofi_task, hifi_task) | ||
| super().__init__( | ||
|
|
@@ -260,23 +268,38 @@ def _check_inputs( | |
| "to the number of high-fidelity trials" | ||
| ) | ||
|
|
||
| def _ask(self, trials: List[Trial]) -> List[Trial]: | ||
| """Fill in the parameter values of the requested trials.""" | ||
| for trial in trials: | ||
| def suggest(self, num_points: Optional[int]) -> List[dict]: | ||
| """Request the next set of points to evaluate.""" | ||
| points = [] | ||
| for _ in range(num_points): | ||
| next_trial = self._get_next_trial_arm() | ||
| if next_trial is not None: | ||
| arm, trial_type, trial_index = next_trial | ||
| trial.parameter_values = [ | ||
| arm.parameters.get(var.name) | ||
| point = { | ||
| var.name: arm.parameters.get(var.name) | ||
| for var in self._varying_parameters | ||
| ] | ||
| trial.trial_type = trial_type | ||
| trial.arm_name = arm.name | ||
| trial.trial_index = trial_index | ||
| return trials | ||
|
|
||
| def _tell(self, trials: List[Trial]) -> None: | ||
| } | ||
| # SH for VOCS standard these will need to be 'variables' | ||
| # For now much match the trial parameter names. | ||
| point["ax_trial_id"] = trial_index | ||
| point["arm_name"] = arm.name | ||
| point["trial_type"] = trial_type | ||
| points.append(point) | ||
| return points | ||
|
|
||
| def ingest(self, results: List[dict]) -> None: | ||
| """Incorporate evaluated trials into experiment.""" | ||
| # reconstruct Optimastrials | ||
RemiLehe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| trials = [] | ||
| for result in results: | ||
| trial = Trial.from_dict( | ||
| trial_dict=result, | ||
| varying_parameters=self._varying_parameters, | ||
| objectives=self._objectives, | ||
| analyzed_parameters=self._analyzed_parameters, | ||
| custom_parameters=self._custom_trial_parameters, | ||
| ) | ||
| trials.append(trial) | ||
| if self.gen_state == NOT_STARTED: | ||
| self._incorporate_external_data(trials) | ||
| else: | ||
|
|
@@ -285,17 +308,18 @@ def _tell(self, trials: List[Trial]) -> None: | |
| def _incorporate_external_data(self, trials: List[Trial]) -> None: | ||
| """Incorporate external data (e.g., from history) into experiment.""" | ||
| # Get trial indices. | ||
| # SH should have handling if ax_trial_ids are None... | ||
| trial_indices = [] | ||
| for trial in trials: | ||
| trial_indices.append(trial.trial_index) | ||
| trial_indices.append(trial.ax_trial_id) | ||
| trial_indices = np.unique(np.array(trial_indices)) | ||
|
|
||
| # Group trials by index. | ||
| grouped_trials = {} | ||
| for index in trial_indices: | ||
| grouped_trials[index] = [] | ||
| for trial in trials: | ||
| grouped_trials[trial.trial_index].append(trial) | ||
| grouped_trials[trial.ax_trial_id].append(trial) | ||
|
|
||
| # Add trials to experiment. | ||
| for index in trial_indices: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.