-
Notifications
You must be signed in to change notification settings - Fork 27
Better parameterization of APOSMM class, plus docstring #1583
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
Open
jlnav
wants to merge
6
commits into
experimental/jlnav_plus_shuds_asktell
Choose a base branch
from
asktell/aposmm_fixes
base: experimental/jlnav_plus_shuds_asktell
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c8d6a82
starting to populate the APOSMM class with common kwargs, for better …
jlnav 1dce059
small fixes
jlnav 77845a0
docstring for APOSMM class
jlnav 2635236
evaluate an APOSMM with only VOCS passed in
jlnav 4e73c93
replace completely-typed out gen_specs['user'] update from parameters…
jlnav 4357173
coverage adjusts
jlnav File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import copy | ||
from math import gamma, pi, sqrt | ||
from typing import List | ||
|
||
import numpy as np | ||
|
@@ -11,38 +12,115 @@ | |
|
||
class APOSMM(PersistentGenInterfacer): | ||
""" | ||
Standalone object-oriented APOSMM generator | ||
APOSMM coordinates multiple local optimization runs, dramatically reducing time for | ||
discovering multiple minima on parallel systems. | ||
This *generator* adheres to the `Generator Standard <https://github.com/campa-consortium/generator_standard>`_. | ||
.. seealso:: | ||
`https://doi.org/10.1007/s12532-017-0131-4 <https://doi.org/10.1007/s12532-017-0131-4>`_ | ||
Parameters | ||
---------- | ||
vocs: VOCS | ||
The VOCS object, adhering to the VOCS interface from the Generator Standard. | ||
History: npt.NDArray = [] | ||
An optional history of previously evaluated points. | ||
initial_sample_size: int = 100 | ||
Number of uniformly sampled points | ||
to be evaluated before starting the localopt runs. Can be | ||
zero if no additional sampling is desired, but if zero there must be past values | ||
provided in the History. | ||
sample_points: npt.NDArray = None | ||
Points to be sampled (original domain). | ||
If more sample points are needed by APOSMM during the course of the | ||
optimization, points will be drawn uniformly over the domain. | ||
localopt_method: str = "LN_BOBYQA" | ||
The local optimization method to use. | ||
rk_const: float = None | ||
Multiplier in front of the ``r_k`` value. | ||
If not provided, it will be set to ``0.5 * ((gamma(1 + (n / 2)) * 5) ** (1 / n)) / sqrt(pi)`` | ||
xtol_abs: float = 1e-6 | ||
Localopt method's convergence tolerance. | ||
ftol_abs: float = 1e-6 | ||
Localopt method's convergence tolerance. | ||
dist_to_bound_multiple: float = 0.5 | ||
What fraction of the distance to the nearest boundary should the initial | ||
step size be in localopt runs. | ||
max_active_runs: int = 6 | ||
Bound on number of runs APOSMM is advancing. | ||
random_seed: int = 1 | ||
Seed for the random number generator. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
vocs: VOCS, | ||
History: npt.NDArray = [], | ||
persis_info: dict = {}, | ||
gen_specs: dict = {}, | ||
libE_info: dict = {}, | ||
initial_sample_size: int = 100, | ||
sample_points: npt.NDArray = None, | ||
localopt_method: str = "LN_BOBYQA", | ||
rk_const: float = None, | ||
xtol_abs: float = 1e-6, | ||
ftol_abs: float = 1e-6, | ||
dist_to_bound_multiple: float = 0.5, | ||
max_active_runs: int = 6, | ||
random_seed: int = 1, | ||
**kwargs, | ||
) -> None: | ||
|
||
from libensemble.gen_funcs.persistent_aposmm import aposmm | ||
|
||
self.VOCS = vocs | ||
|
||
gen_specs = {} | ||
persis_info = {"1": np.random.default_rng(random_seed)} | ||
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. why is this with key "1", I dont think we want that. |
||
libE_info = {} | ||
gen_specs["gen_f"] = aposmm | ||
self.n = len(list(self.VOCS.variables.keys())) | ||
|
||
if not rk_const: | ||
rk_const = 0.5 * ((gamma(1 + (self.n / 2)) * 5) ** (1 / self.n)) / sqrt(pi) | ||
|
||
gen_specs["user"] = {} | ||
gen_specs["user"]["lb"] = np.array([vocs.variables[i].domain[0] for i in vocs.variables]) | ||
gen_specs["user"]["ub"] = np.array([vocs.variables[i].domain[1] for i in vocs.variables]) | ||
|
||
if not gen_specs.get("out"): # gen_specs never especially changes for aposmm even as the problem varies | ||
gen_specs["out"] = [ | ||
("x", float, self.n), | ||
("x_on_cube", float, self.n), | ||
("sim_id", int), | ||
("local_min", bool), | ||
("local_pt", bool), | ||
] | ||
gen_specs["persis_in"] = ["x", "f", "local_pt", "sim_id", "sim_ended", "x_on_cube", "local_min"] | ||
FIELDS = [ | ||
"initial_sample_size", | ||
"sample_points", | ||
"localopt_method", | ||
"rk_const", | ||
"xtol_abs", | ||
"ftol_abs", | ||
"dist_to_bound_multiple", | ||
"max_active_runs", | ||
] | ||
|
||
for k in FIELDS: | ||
val = locals().get(k) | ||
if val is not None: | ||
gen_specs["user"][k] = val | ||
|
||
gen_specs["out"] = [ | ||
("x", float, self.n), | ||
("x_on_cube", float, self.n), | ||
("sim_id", int), | ||
("local_min", bool), | ||
("local_pt", bool), | ||
] | ||
gen_specs["persis_in"] = ["x", "f", "local_pt", "sim_id", "sim_ended", "x_on_cube", "local_min"] | ||
super().__init__(vocs, History, persis_info, gen_specs, libE_info, **kwargs) | ||
|
||
if not self.persis_info.get("nworkers"): | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should default be 0 or 1.