-
Notifications
You must be signed in to change notification settings - Fork 32
Examples/optimas ax generators #1635
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
shuds13
wants to merge
24
commits into
experimental/jlnav_plus_shuds_asktell
Choose a base branch
from
examples/optimas_ax_generators
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
24 commits
Select commit
Hold shift + click to select a range
97287d4
Ensure gens with _id return with sim_id
shuds13 d78856b
Add Optimas Ax test
shuds13 c60ad27
Add working multi-task test
shuds13 1e341b9
Target Optimas branch for testing
shuds13 a79eb56
Add tests with single/multi fidelity and multitask gens
shuds13 b4dbc7d
Remove old optimas test
shuds13 eeabf3f
Make _id to sim_id more robust
shuds13 5de0573
Handle empty dictionary
shuds13 04a0565
Formatting tests
shuds13 7697ef7
Ingest initial H0 for gest-api generators
shuds13 cd15f07
Multitask test uses H0
shuds13 e7fef19
Fix test naming
shuds13 781780a
Add _id field when id producing gen
shuds13 98861c0
Handle _id as own field
shuds13 c4110ab
Make test_optimas_ax_multitask.py local only
shuds13 f6dc389
Merge from upstream
shuds13 7a7789d
Formatting update
shuds13 90b3e9c
Formatting
shuds13 c4c58f0
Update xopt branch
shuds13 08a195c
Put back _id to sim_id fixup
shuds13 d338a98
Merge from upstream
shuds13 9b1a78f
Merge branch 'experimental/jlnav_plus_shuds_asktell' into examples/op…
shuds13 0766e41
Exclude multitask
shuds13 a9b76ef
Merge branch 'experimental/jlnav_plus_shuds_asktell' into examples/op…
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
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
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
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 |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| """ | ||
| Tests libEnsemble with Optimas Multi-Fidelity Ax Generator | ||
|
|
||
| *****currently fixing nworkers to batch_size***** | ||
|
|
||
| Execute via one of the following commands (e.g. 4 workers): | ||
| mpiexec -np 5 python test_optimas_ax_mf.py | ||
| python test_optimas_ax_mf.py -n 4 | ||
|
|
||
| When running with the above commands, the number of concurrent evaluations of | ||
| the objective function will be 4 as the generator is on the manager. | ||
|
|
||
| """ | ||
|
|
||
| # Do not change these lines - they are parsed by run-tests.sh | ||
| # TESTSUITE_COMMS: mpi local | ||
| # TESTSUITE_NPROCS: 4 | ||
| # TESTSUITE_EXTRA: true | ||
|
|
||
| import numpy as np | ||
|
|
||
| from gest_api.vocs import VOCS | ||
| from optimas.generators import AxMultiFidelityGenerator | ||
|
|
||
| from libensemble import Ensemble | ||
| from libensemble.alloc_funcs.start_only_persistent import only_persistent_gens as alloc_f | ||
| from libensemble.specs import AllocSpecs, ExitCriteria, GenSpecs, LibeSpecs, SimSpecs | ||
|
|
||
|
|
||
| def eval_func_mf(input_params): | ||
| """Evaluation function for multifidelity test.""" | ||
| x0 = input_params["x0"] | ||
| x1 = input_params["x1"] | ||
| resolution = input_params["res"] | ||
| result = -( | ||
| (x0 + 10 * np.cos(x0 + 0.1 * resolution)) | ||
| * (x1 + 5 * np.cos(x1 - 0.2 * resolution)) | ||
| ) | ||
| return {"f": result} | ||
|
|
||
|
|
||
| # Main block is necessary only when using local comms with spawn start method (default on macOS and Windows). | ||
| if __name__ == "__main__": | ||
|
|
||
| n = 2 | ||
| batch_size = 2 | ||
|
|
||
| libE_specs = LibeSpecs(gen_on_manager=True, nworkers=batch_size) | ||
|
|
||
| vocs = VOCS( | ||
| variables={"x0": [-50.0, 5.0], "x1": [-5.0, 15.0], "res": [1.0, 8.0]}, | ||
| objectives={"f": "MAXIMIZE"}, | ||
| ) | ||
|
|
||
| gen = AxMultiFidelityGenerator(vocs=vocs) | ||
|
|
||
| gen_specs = GenSpecs( | ||
| generator=gen, | ||
| batch_size=batch_size, | ||
| vocs=vocs, | ||
| ) | ||
|
|
||
| sim_specs = SimSpecs( | ||
| simulator=eval_func_mf, | ||
| vocs=vocs, | ||
| ) | ||
|
|
||
| alloc_specs = AllocSpecs(alloc_f=alloc_f) | ||
| exit_criteria = ExitCriteria(sim_max=6) | ||
|
|
||
| workflow = Ensemble( | ||
| libE_specs=libE_specs, | ||
| sim_specs=sim_specs, | ||
| alloc_specs=alloc_specs, | ||
| gen_specs=gen_specs, | ||
| exit_criteria=exit_criteria, | ||
| ) | ||
|
|
||
| H, _, _ = workflow.run() | ||
|
|
||
| # Perform the run | ||
| if workflow.is_manager: | ||
| workflow.save_output(__file__) | ||
| print(f"Completed {len(H)} simulations") |
110 changes: 110 additions & 0 deletions
110
libensemble/tests/regression_tests/test_optimas_ax_multitask.py
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 |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| """ | ||
| Tests libEnsemble with Optimas Multitask Ax Generator | ||
|
|
||
| Runs an initial ensemble, followed by another using the first as an H0. | ||
|
|
||
| *****currently fixing nworkers to batch_size***** | ||
|
|
||
| Execute via one of the following commands (e.g. 4 workers): | ||
| mpiexec -np 5 python test_optimas_ax_multitask.py | ||
| python test_optimas_ax_multitask.py -n 4 | ||
|
|
||
| When running with the above commands, the number of concurrent evaluations of | ||
| the objective function will be 4 as the generator is on the manager. | ||
|
|
||
| Issues: In some cases, the generator fails to produce points. This is | ||
| intermittent and can be seen by the message "alloc_f did not return any work". | ||
| This needs to be resolved in the generator by generating extra points | ||
| as needed (exluding from until then). | ||
| """ | ||
|
|
||
| # Do not change these lines - they are parsed by run-tests.sh | ||
| # TESTSUITE_COMMS: local | ||
| # TESTSUITE_NPROCS: 4 | ||
| # TESTSUITE_EXTRA: true | ||
| # TESTSUITE_EXCLUDE: true | ||
|
|
||
| import numpy as np | ||
| from gest_api.vocs import VOCS | ||
|
|
||
| from optimas.core import Task | ||
| from optimas.generators import AxMultitaskGenerator | ||
|
|
||
| from libensemble import Ensemble | ||
| from libensemble.alloc_funcs.start_only_persistent import only_persistent_gens as alloc_f | ||
| from libensemble.specs import AllocSpecs, ExitCriteria, GenSpecs, LibeSpecs, SimSpecs | ||
|
|
||
|
|
||
| def eval_func_multitask(input_params): | ||
| """Evaluation function for task1 or task2 in multitask test""" | ||
| print(f'input_params: {input_params}') | ||
| x0 = input_params["x0"] | ||
| x1 = input_params["x1"] | ||
| trial_type = input_params["trial_type"] | ||
|
|
||
| if trial_type == "task_1": | ||
| result = -(x0 + 10 * np.cos(x0)) * (x1 + 5 * np.cos(x1)) | ||
| else: | ||
| result = -0.5 * (x0 + 10 * np.cos(x0)) * (x1 + 5 * np.cos(x1)) | ||
|
|
||
| output_params = {"f": result} | ||
| return output_params | ||
|
|
||
|
|
||
| # Main block is necessary only when using local comms with spawn start method (default on macOS and Windows). | ||
| if __name__ == "__main__": | ||
|
|
||
| n = 2 | ||
| batch_size = 2 | ||
|
|
||
| libE_specs = LibeSpecs(gen_on_manager=True, nworkers=batch_size) | ||
|
|
||
| vocs = VOCS( | ||
| variables={ | ||
| "x0": [-50.0, 5.0], | ||
| "x1": [-5.0, 15.0], | ||
| "trial_type": {"task_1", "task_2"}, | ||
| }, | ||
| objectives={"f": "MAXIMIZE"}, | ||
| ) | ||
|
|
||
| sim_specs = SimSpecs( | ||
| simulator=eval_func_multitask, | ||
| vocs=vocs, | ||
| ) | ||
|
|
||
| alloc_specs = AllocSpecs(alloc_f=alloc_f) | ||
| exit_criteria = ExitCriteria(sim_max=15) | ||
|
|
||
| H0 = None # or np.load("multitask_first_pass.npy") | ||
| for run_num in range(2): | ||
| print(f"\nRun number: {run_num}") | ||
| task1 = Task("task_1", n_init=2, n_opt=1) | ||
| task2 = Task("task_2", n_init=5, n_opt=3) | ||
| gen = AxMultitaskGenerator(vocs=vocs, hifi_task=task1, lofi_task=task2) | ||
|
|
||
| gen_specs = GenSpecs( | ||
| generator=gen, | ||
| batch_size=batch_size, | ||
| vocs=vocs, | ||
| ) | ||
|
|
||
| workflow = Ensemble( | ||
| libE_specs=libE_specs, | ||
| sim_specs=sim_specs, | ||
| alloc_specs=alloc_specs, | ||
| gen_specs=gen_specs, | ||
| exit_criteria=exit_criteria, | ||
| H0=H0, | ||
| ) | ||
|
|
||
| H, _, _ = workflow.run() | ||
|
|
||
| if run_num == 0: | ||
| H0 = H | ||
| workflow.save_output("multitask_first_pass", append_attrs=False) # Allows restart only run | ||
|
|
||
| if workflow.is_manager: | ||
| if run_num == 1: | ||
| workflow.save_output("multitask_with_H0") | ||
| print(f"Second run completed: {len(H)} simulations") |
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 |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| """ | ||
| Tests libEnsemble with Optimas Single-Fidelity Ax Generator | ||
|
|
||
| *****currently fixing nworkers to batch_size***** | ||
|
|
||
| Execute via one of the following commands (e.g. 4 workers): | ||
| mpiexec -np 5 python test_optimas_ax_sf.py | ||
| python test_optimas_ax_sf.py -n 4 | ||
|
|
||
| When running with the above commands, the number of concurrent evaluations of | ||
| the objective function will be 4 as the generator is on the manager. | ||
|
|
||
| """ | ||
|
|
||
| # Do not change these lines - they are parsed by run-tests.sh | ||
| # TESTSUITE_COMMS: mpi local | ||
| # TESTSUITE_NPROCS: 4 | ||
| # TESTSUITE_EXTRA: true | ||
|
|
||
| import numpy as np | ||
|
|
||
| from gest_api.vocs import VOCS | ||
| from optimas.generators import AxSingleFidelityGenerator | ||
|
|
||
| from libensemble import Ensemble | ||
| from libensemble.alloc_funcs.start_only_persistent import only_persistent_gens as alloc_f | ||
| from libensemble.specs import AllocSpecs, ExitCriteria, GenSpecs, LibeSpecs, SimSpecs | ||
|
|
||
|
|
||
| def eval_func_sf(input_params): | ||
| """Evaluation function for single-fidelity test. """ | ||
| x0 = input_params["x0"] | ||
| x1 = input_params["x1"] | ||
| result = -(x0 + 10 * np.cos(x0)) * (x1 + 5 * np.cos(x1)) | ||
| return {"f": result} | ||
|
|
||
|
|
||
| # Main block is necessary only when using local comms with spawn start method (default on macOS and Windows). | ||
| if __name__ == "__main__": | ||
|
|
||
| n = 2 | ||
| batch_size = 2 | ||
|
|
||
| libE_specs = LibeSpecs(gen_on_manager=True, nworkers=batch_size) | ||
|
|
||
| vocs = VOCS( | ||
| variables={ | ||
| "x0": [-50.0, 5.0], | ||
| "x1": [-5.0, 15.0], | ||
| }, | ||
| objectives={"f": "MAXIMIZE"}, | ||
| ) | ||
|
|
||
| gen = AxSingleFidelityGenerator(vocs=vocs) | ||
|
|
||
| gen_specs = GenSpecs( | ||
| generator=gen, | ||
| batch_size=batch_size, | ||
| vocs=vocs, | ||
| ) | ||
|
|
||
| sim_specs = SimSpecs( | ||
| simulator=eval_func_sf, | ||
| vocs=vocs, | ||
| ) | ||
|
|
||
| alloc_specs = AllocSpecs(alloc_f=alloc_f) | ||
| exit_criteria = ExitCriteria(sim_max=10) | ||
|
|
||
| workflow = Ensemble( | ||
| libE_specs=libE_specs, | ||
| sim_specs=sim_specs, | ||
| alloc_specs=alloc_specs, | ||
| gen_specs=gen_specs, | ||
| exit_criteria=exit_criteria, | ||
| ) | ||
|
|
||
| H, _, _ = workflow.run() | ||
|
|
||
| # Perform the run | ||
| if workflow.is_manager: | ||
| workflow.save_output(__file__) | ||
| print(f"Completed {len(H)} simulations") |
Oops, something went wrong.
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.
And such gens will only return sim_id if we're already explicitly mapping _id to it... right?