-
Notifications
You must be signed in to change notification settings - Fork 31
ASK/TELL DEVELOP #1307
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
Merged
Merged
ASK/TELL DEVELOP #1307
Changes from 210 commits
Commits
Show all changes
660 commits
Select commit
Hold shift + click to select a range
9b1195b
add parameter for UniformSample, instructing the generator to squash …
jlnav 24df60f
making variables_mapping an explicit kwarg for a libensemble generator
jlnav 715773b
bump pydantic - this should've been done in a previous PR
jlnav 08ead4a
fix UniformSample LibensembleGenerator to use variables_mapping
jlnav 22b69b4
just commenting out, but maybe we don't need this unit test now that …
jlnav f664e37
removing unnecessary GPCAM_Standard class; refactoring the other gpca…
jlnav 99bc450
update regression test to (presumably) use classes that now use VOCS
jlnav 423f0d6
... why was this test excluded?
jlnav 56e59aa
lists instead of tuples...
jlnav 145e09d
fix default value of test_points_file kwarg to be None
jlnav 9a6f299
somehow this tell_numpy got missed
jlnav 9c0e258
various fixes to building variables_mapping and extra.ci, still debug…
jlnav 4a52e0b
temporary debugging print?
jlnav 73bbf69
fix objective name
jlnav bf0d79e
batch_size fix to runners.py, add batch_size to gen_specs so the runn…
jlnav b3ce513
we still want to map {"f": ["energy"]), obviously
jlnav 2428152
move StandardSample to test_asktell_sampling.py, to test as-though we…
jlnav 0bcd7c9
various fixes from PR suggestions
jlnav bf9ed05
move gpcam superclass init to top of init, make UniformSample accept …
jlnav acc4811
gpcam asserts objectives, then a better description of variables_mapping
jlnav 2a67724
move _validate_vocs call to superclass
jlnav 8c9e313
Merge pull request #1572 from Libensemble/asktell/VOCS
jlnav 6b54991
Merge branch 'develop' into experimental/jlnav_plus_shuds_asktell
jlnav a4ead36
Split finalize and export
shuds13 3622219
aposmm uses x mapping to set bounds and size
shuds13 c8d6a82
starting to populate the APOSMM class with common kwargs, for better …
jlnav 1dce059
small fixes
jlnav 77845a0
docstring for APOSMM class
jlnav 9b3429b
Fix finalize and export functions
shuds13 a2c58fc
Option to export with user fields
shuds13 2635236
evaluate an APOSMM with only VOCS passed in
jlnav 012227a
Add unit tests of unmap_numpy_array
shuds13 03420b3
Remove unneeded branch
shuds13 682425a
Add expected variables mapping for APOSMM
shuds13 b209901
Better example bounds
shuds13 fd630eb
Allow pass through of unmapped arrays
shuds13 57a8de9
Allow export as list of dictionaries
shuds13 050c22d
Add pass-through array to unmap test
shuds13 5d31b63
Add export unit tests and fix up unmap
shuds13 d1d4b76
Re-enable APOSMM unit tests
shuds13 b05762a
Add checks for x and x_on_cube
shuds13 0b8cdec
Add export tests and fixup
shuds13 4e73c93
replace completely-typed out gen_specs['user'] update from parameters…
jlnav 4357173
coverage adjusts
jlnav 1e52d99
Do not send local_min/pt to ingest
shuds13 3c21202
Autofill x and f variables_mapping separately
shuds13 1cb542f
Update asktell APOSMM regression test
shuds13 9798b3e
Merge branch 'develop' into experimental/jlnav_plus_shuds_asktell
jlnav 585c521
Add fvec when components is present
shuds13 cf36e85
Send APOSMM errors as a string
shuds13 77efa2a
Formatting
shuds13 ed6604d
Blacken
shuds13 9cbca1e
Clarify comment
shuds13 ec773d4
Update generator_standard to gest_api
shuds13 5ea9b2b
Fix gest-api in pyproject
shuds13 b14b85d
Fix gest project name
shuds13 f8d1833
Fix _validate_vocs for gpCAM
shuds13 ad54abd
Remove misleading n
shuds13 a383dc0
Merge pull request #1582 from Libensemble/feature/update_finalize
shuds13 1353363
Merge branch 'experimental/jlnav_plus_shuds_asktell' into asktell/apo…
jlnav bb26e05
Merge branch 'develop' into asktell/aposmm_fixes
jlnav 948c88b
this specific gen_specs['out'] assignment no longer needed, as confli…
jlnav 047673d
adjust for finalize and export; plus now variables_mapping is required
jlnav b681398
don't need persis_info declared like this
jlnav b828cb4
fixes and refactors as suggested by shuds - *works on multistage lpa*
jlnav c040721
make initial_sample_size and max_active_runs required arguments for a…
jlnav cd776a1
Merge pull request #1583 from Libensemble/asktell/aposmm_fixes
jlnav 7b22ab1
Merge branch 'develop' into experimental/jlnav_plus_shuds_asktell
jlnav 4e37554
typo
jlnav 41a4cbc
fix generator-standard package name in pyproject.toml
jlnav 3e41b4b
also start running thread upon initial ingest
jlnav 2303512
better docstrings. new "do_not_produce_sample_points" arg from shuds.…
jlnav 802de9c
add kwarg where necessary, plus more test glue
jlnav fa254a0
unpack "x"s passed in into dtype-less array. so _on_cube conversion c…
jlnav 1606ef3
TODOs, plus more
jlnav 473487d
mostly just trying the current aposmm.py with Xopt in this commit...
jlnav b42e1ba
fix initial sample (within aposmm *class*) requiring sim_ids. we'll j…
jlnav a354339
aposmm gen_f : new loop undserneath do_not_produce_sample_points cond…
jlnav 5dc5155
add unit test where APOSMM class ingests first
jlnav ed03ac1
make an internal method internal. implement _validate_vocs for aposmm…
jlnav b7a79c3
trying to account for, then test a large variety of conditions where …
jlnav 1d335c8
adjusts send-conditions upon full sample being ingested. adjusts warn…
jlnav b23d13c
additional docs
jlnav c07611d
Add Xopt EI test
shuds13 f39b937
Restructure imports
shuds13 fb9b01d
Set batch size and fix nworkers
shuds13 e88088f
Make temp note on fixing nworkers
shuds13 57b466e
Restructure gen_specs
shuds13 da20d5a
Change sim to xopt test sim
shuds13 e5ff70d
Add vocs field to GenSpecs
shuds13 d060f2e
Add vocs field to SimSpecs
shuds13 d5e3c53
Get vocs field type
shuds13 42f772a
tentative refactor of do_not_produce_sample_points keyword to be the …
jlnav bc3a976
Add unit tests for set_fields_from_vocs
shuds13 12c0fe3
Test array type
shuds13 95bc6a0
doing "generate_sample_points". ensuring sim_id gets cast as int (for…
jlnav f399750
add onto n_s with the len of received presumptive_user_sample
jlnav cf9b1c1
Prevent gen from converting to dictionary
shuds13 fbf1288
Cleanup test_xopt_EI.py
shuds13 4ca2153
fix conditions for something_sent after initial_sample is ingested. a…
jlnav d28681d
Provide pre-evaluated initial sample
shuds13 635439d
internally, generate_sample_points is now set based on whether sugges…
jlnav c91a824
Remove automapping
shuds13 854a336
various fixes; sim_id warning no longer needed in gen_f. raise RunTim…
jlnav 4dbfc42
always map _id to sim_id. add simple executor + UniformSample test. c…
jlnav f4f6b96
put the executor.comm adjustment back - and add a asktell aposmm + ex…
jlnav 2c28939
other MPI processes attempting to finalize their gen is problematic
jlnav 00bbebe
Add array dtype support
shuds13 379868d
Update vocs sampling tests
shuds13 1c1e996
Remove redundant line
shuds13 f6b2ce2
Remove another redundant line
shuds13 4ed9efd
Formatting
shuds13 a02e8d4
Add gest_api simulator wrapper
shuds13 104424e
Add version of xopt test that uses xopt simulator
shuds13 52d32a6
Fix naming
shuds13 561ba54
Fix test for array fields
shuds13 7f4a4ee
Disable awkward array test
shuds13 3de1de5
Give output assert to xopt tests
shuds13 3b21fe0
Fix formatting
shuds13 a11e04d
Merge pull request #1622 from Libensemble/examples/xopt_generators_re…
shuds13 5800c93
Add Optimas grid sample test
shuds13 253efea
Infer type of discrete vars
shuds13 4fda921
tweaks based on PR feedback
jlnav abdf4a6
Re-enamble model tests
shuds13 6ac2880
Add xopt sequential test
shuds13 6d649a3
Do not ingest None
shuds13 56db443
Simplify xopt nelder mead test and assert
shuds13 4a47d2f
Correct procs count for when use parse_args
shuds13 aabcf15
Add xopt and optimas to extra CI
shuds13 d345dce
Formatting
shuds13 fcb1af2
Fix install
shuds13 31f0778
Test xopt/optimas gens on basic tests
shuds13 548f580
doc/docstring additional tweaks and clarifications
jlnav aaac936
bump polling_loop interval for (perhaps) slower containers/VMs/system…
jlnav e9fa694
set the sim_ids of the ingest_buf right when we're about to send it t…
jlnav 0b41dab
Fixing CI for xopt/optimas generator tests (#1626)
shuds13 9903266
Clean up
shuds13 1634579
Add xopt notebook
shuds13 7a76385
Add xopt example to docs
shuds13 55c346c
Add new tutorial to main toctree
shuds13 58f0d82
Rename example
shuds13 f4af3a6
Rename and add colab link
shuds13 cccd3bb
Improve layout
shuds13 63b2fdd
Add xopt/forces example
shuds13 3917e43
Enable gest-api simulator to use executor
shuds13 c8e6d62
Fix user_specs naming
shuds13 589d8fb
Formatting
shuds13 7288d08
Merge pull request #1620 from Libensemble/examples/xopt_generators
shuds13 d5fbe14
Merge branch 'develop' into asktell/nov_aposmm_refactor
jlnav 68f1d4e
Merge branch 'experimental/jlnav_plus_shuds_asktell' into asktell/nov…
jlnav 90fe2dc
Merge branch 'develop' into experimental/jlnav_plus_shuds_asktell
jlnav ba1e2f3
Merge branch 'experimental/jlnav_plus_shuds_asktell' into asktell/nov…
jlnav 3daf0c1
Merge pull request #1616 from Libensemble/asktell/nov_aposmm_refactor
shuds13 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 d847490
Merge branch 'develop' into experimental/jlnav_plus_shuds_asktell
jlnav 1fd96dc
typo
jlnav 7697ef7
Ingest initial H0 for gest-api generators
shuds13 cd15f07
Multitask test uses H0
shuds13 ea9c35c
Merge branch 'develop' into experimental/jlnav_plus_shuds_asktell
jlnav e7fef19
Fix test naming
shuds13 d12f53d
initial small changes to add returns_id attribute to APOSMM class
jlnav 57ad733
adjust README intro sample to use standard gen, VOCS
jlnav c2bf534
de-emphasize the "user-functions" in favor of generators and simulato…
jlnav e3f2375
Merge pull request #1646 from Libensemble/asktell/aposmm_id_attr
jlnav 10d0810
mention uv as an install approach. in README example vocs->variables_…
jlnav 1ff10e1
remove sim_specs / gen_specs docs components that describe defining t…
jlnav cb05162
bump specifically-mentioned required pydantic version in advanced_ins…
jlnav 67fa8e4
initial files and fixes for autodocing the gest-api adhering generators
jlnav 1d1c1b6
Merge branch 'develop' into experimental/jlnav_plus_shuds_asktell
jlnav 8e05686
Merge branch 'experimental/jlnav_plus_shuds_asktell' of https://githu…
jlnav ba9a9ef
Merge branch 'develop' into experimental/jlnav_plus_shuds_asktell
jlnav 618c7cf
Merge branch 'experimental/jlnav_plus_shuds_asktell' into asktell/emp…
jlnav 4039b6e
small fixes, plus display some ask/tell aposmm examples in the docs
jlnav fa9c9f6
list gpcam example
jlnav c6e56a9
monocasing, plus a clarification
jlnav c6c79bb
linenos
jlnav c1b5731
starting to rewrite the first tutorial for standardized gens
jlnav b34266b
remove some redundancy
jlnav b52eff8
link to xopt/optimas generators in docs - also try only doc'ing sugge…
jlnav 5cbc999
note the third party gens are examples - adjust xopt file paths to ma…
jlnav d7d1e52
add gest-api pypi release as required dependency
jlnav 4641d1c
Merge branch 'develop' into asktell/gest-api-release
jlnav 54ddb6d
Merge branch 'develop' into experimental/jlnav_plus_shuds_asktell
jlnav 04c6383
lock scipy version until pixi changes implemented into extra.yml
jlnav 5fdf4b3
lock to version from a bit ago
jlnav b34c8b7
remove lock...?
jlnav 3079721
Merge branch 'experimental/jlnav_plus_shuds_asktell' into asktell/emp…
jlnav 5f51e56
Merge branch 'develop' into experimental/jlnav_plus_shuds_asktell
jlnav 5436672
Merge branch 'experimental/jlnav_plus_shuds_asktell' into asktell/ges…
jlnav be014c7
fix psutil version on macos in lockfile
jlnav 1b3165b
Merge pull request #1666 from Libensemble/asktell/gest-api-release
jlnav 9b5cb8d
unbump ax
jlnav d714127
Merge branch 'develop' into asktell/emphasize_asktell_gens
jlnav 14f2909
Merge branch 'experimental/jlnav_plus_shuds_asktell' into asktell/emp…
jlnav 915d5af
Merge branch 'develop' into experimental/jlnav_plus_shuds_asktell
jlnav 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 46db6bf
Merge branch 'develop' into experimental/jlnav_plus_shuds_asktell
jlnav 08a195c
Put back _id to sim_id fixup
shuds13 d338a98
Merge from upstream
shuds13 6cd49de
fix generator.vocs attribute to be lowercase throughout. fix bugged l…
jlnav 9b1a78f
Merge branch 'experimental/jlnav_plus_shuds_asktell' into examples/op…
shuds13 2d97222
add optimas to all extra envs. add xopt to py3.11+ envs
jlnav 87f14e5
since xopt and optimas now included in envs, remove xopt tests on pyt…
jlnav 1508d7e
use main branch of optimas instead of release
jlnav 86d7397
forgot an e
jlnav 9f6e31e
grab develop's run-tests.py
jlnav 9b93625
why are these tests complaining about reusing an ensemble dir
jlnav e264d0a
pass the instance, not the parent class that was included for typing …
jlnav 0766e41
Exclude multitask
shuds13 b20961c
enabled / disabled tests adjustments
jlnav 328ce64
move nlopt dep
jlnav 38aa584
upstream optimas branch for asktell
jlnav a9b76ef
Merge branch 'experimental/jlnav_plus_shuds_asktell' into examples/op…
jlnav 95b019e
some fixes (?), experimenting with calling only suggest on Libensembl…
jlnav 7bf84a0
Merge remote-tracking branch 'remotes/origin/examples/optimas_ax_gene…
jlnav 35fa55e
various fixes, adjustments, new functions. unmap aposmm's output nump…
jlnav dcf2ed9
history.py:
jlnav f47c685
exclude optimas ax tests on macos
jlnav 0e7924a
remove optimas-ax tests from newer python extended tests
jlnav e89e62d
Merge pull request #1635 from Libensemble/examples/optimas_ax_generators
jlnav 4f8c912
Merge branch 'experimental/jlnav_plus_shuds_asktell' into asktell/apo…
jlnav c5e5183
Merge branch 'develop' into experimental/jlnav_plus_shuds_asktell
jlnav 37bc5d8
coverage fixes, plus adjustments for warning/handling when both the w…
jlnav ebce988
adjusts for MPI case
jlnav b17ffd6
Merge branch 'experimental/jlnav_plus_shuds_asktell' into asktell/apo…
jlnav 2ecaba0
dependency and expected-error-condition tweaks
jlnav 7bfabce
lock to previous petsc version
jlnav 9ab4f93
Merge pull request #1679 from Libensemble/asktell/aposmm_reg_test_vocs
shuds13 eeddffa
Merge branch 'experimental/jlnav_plus_shuds_asktell' into asktell/emp…
jlnav 718df76
Merge pull request #1656 from Libensemble/asktell/emphasize_asktell_gens
jlnav 09a1b7f
open up ax-platform across extra-envs for compatiblity with xopt requ…
jlnav 2070a93
fix tutorial code
jlnav 2a2c20b
typo
jlnav c79bf4d
lock ax again, point to optimas branch
jlnav f1bb7ed
disable xopt install/tests for now
jlnav 005647f
Merge pull request #1684 from Libensemble/asktell/ax
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 |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
|
|
||
| Ask/Tell Generators | ||
| =================== | ||
|
|
||
| **BETA - SUBJECT TO CHANGE** | ||
|
|
||
| These generators, implementations, methods, and subclasses are in BETA, and | ||
| may change in future releases. | ||
|
|
||
| The Generator interface is expected to roughly correspond with CAMPA's standard: | ||
| https://github.com/campa-consortium/generator_standard | ||
|
|
||
| libEnsemble is in the process of supporting generator objects that implement the following interface: | ||
|
|
||
| .. automodule:: generators | ||
| :members: Generator LibensembleGenerator | ||
| :undoc-members: | ||
|
|
||
| .. autoclass:: Generator | ||
| :member-order: bysource | ||
| :members: |
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 |
|---|---|---|
|
|
@@ -12,3 +12,4 @@ | |
| from libensemble import logger | ||
|
|
||
| from .ensemble import Ensemble | ||
| from .generators import Generator | ||
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,154 @@ | ||
| """Generator class exposing gpCAM functionality""" | ||
|
|
||
| import time | ||
| from typing import List | ||
|
|
||
| import numpy as np | ||
| from gpcam import GPOptimizer as GP | ||
| from numpy import typing as npt | ||
|
|
||
| # While there are class / func duplicates - re-use functions. | ||
| from libensemble.gen_funcs.persistent_gpCAM import ( | ||
| _calculate_grid_distances, | ||
| _eval_var, | ||
| _find_eligible_points, | ||
| _generate_mesh, | ||
| _read_testpoints, | ||
| ) | ||
| from libensemble.generators import LibensembleGenerator | ||
|
|
||
| __all__ = [ | ||
| "GP_CAM", | ||
| "GP_CAM_Covar", | ||
| ] | ||
|
|
||
|
|
||
| # Note - batch size is set in wrapper currently - and passed to ask as n_trials. | ||
| # To support empty ask(), add batch_size back in here. | ||
|
|
||
|
|
||
| # Equivalent to function persistent_gpCAM_ask_tell | ||
| class GP_CAM(LibensembleGenerator): | ||
| """ | ||
| This generation function constructs a global surrogate of `f` values. | ||
|
|
||
| It is a batched method that produces a first batch uniformly random from | ||
| (lb, ub). On subequent iterations, it calls an optimization method to | ||
| produce the next batch of points. This optimization might be too slow | ||
| (relative to the simulation evaluation time) for some use cases. | ||
| """ | ||
|
|
||
| def _initialize_gpCAM(self, user_specs): | ||
| """Extract user params""" | ||
| # self.b = user_specs["batch_size"] | ||
| self.lb = np.array(user_specs["lb"]) | ||
| self.ub = np.array(user_specs["ub"]) | ||
| self.n = len(self.lb) # dimension | ||
| assert isinstance(self.n, int), "Dimension must be an integer" | ||
| assert isinstance(self.lb, np.ndarray), "lb must be a numpy array" | ||
| assert isinstance(self.ub, np.ndarray), "ub must be a numpy array" | ||
| self.all_x = np.empty((0, self.n)) | ||
| self.all_y = np.empty((0, 1)) | ||
| np.random.seed(0) | ||
|
|
||
| def __init__(self, H, persis_info, gen_specs, libE_info=None): | ||
|
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. I will put above _initialize_gpcAM
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. and make _initialize_gpcAM _initialize_gpCAM |
||
| self.H = H # Currently not used - could be used for an H0 | ||
| self.persis_info = persis_info | ||
| self.gen_specs = gen_specs | ||
| self.libE_info = libE_info | ||
|
|
||
| self.U = self.gen_specs["user"] | ||
| self._initialize_gpCAM(self.U) | ||
|
|
||
| self.my_gp = None | ||
| self.noise = 1e-8 # 1e-12 | ||
| self.ask_max_iter = self.gen_specs["user"].get("ask_max_iter") or 10 | ||
|
|
||
| def ask_numpy(self, n_trials: int) -> npt.NDArray: | ||
| if self.all_x.shape[0] == 0: | ||
| self.x_new = self.persis_info["rand_stream"].uniform(self.lb, self.ub, (n_trials, self.n)) | ||
| else: | ||
| start = time.time() | ||
| self.x_new = self.my_gp.ask( | ||
| input_set=np.column_stack((self.lb, self.ub)), | ||
| n=n_trials, | ||
| pop_size=n_trials, | ||
| acquisition_function="total correlation", | ||
| max_iter=self.ask_max_iter, # Larger takes longer. gpCAM default is 20. | ||
| )["x"] | ||
| print(f"Ask time:{time.time() - start}") | ||
| H_o = np.zeros(n_trials, dtype=self.gen_specs["out"]) | ||
| H_o["x"] = self.x_new | ||
| return H_o | ||
|
|
||
| def tell_numpy(self, calc_in: npt.NDArray) -> None: | ||
| if calc_in is not None: | ||
| self.y_new = np.atleast_2d(calc_in["f"]).T | ||
| nan_indices = [i for i, fval in enumerate(self.y_new) if np.isnan(fval)] | ||
| self.x_new = np.delete(self.x_new, nan_indices, axis=0) | ||
| self.y_new = np.delete(self.y_new, nan_indices, axis=0) | ||
|
|
||
| self.all_x = np.vstack((self.all_x, self.x_new)) | ||
| self.all_y = np.vstack((self.all_y, self.y_new)) | ||
|
|
||
| noise_var = self.noise * np.ones(len(self.all_y)) | ||
| if self.my_gp is None: | ||
| self.my_gp = GP(self.all_x, self.all_y.flatten(), noise_variances=noise_var) | ||
| else: | ||
| self.my_gp.tell(self.all_x, self.all_y.flatten(), noise_variances=noise_var) | ||
| self.my_gp.train() | ||
|
|
||
|
|
||
| class GP_CAM_Covar(GP_CAM): | ||
| """ | ||
| This generation function constructs a global surrogate of `f` values. | ||
|
|
||
| It is a batched method that produces a first batch uniformly random from | ||
| (lb, ub) and on following iterations samples the GP posterior covariance | ||
| function to find sample points. | ||
| """ | ||
|
|
||
| def __init__(self, H, persis_info, gen_specs, libE_info=None): | ||
| super().__init__(H, persis_info, gen_specs, libE_info) | ||
| self.test_points = _read_testpoints(self.U) | ||
| self.x_for_var = None | ||
| self.var_vals = None | ||
| if self.U.get("use_grid"): | ||
| self.num_points = 10 | ||
| self.x_for_var = _generate_mesh(self.lb, self.ub, self.num_points) | ||
| self.r_low_init, self.r_high_init = _calculate_grid_distances(self.lb, self.ub, self.num_points) | ||
|
|
||
| def ask_numpy(self, n_trials: int) -> List[dict]: | ||
| if self.all_x.shape[0] == 0: | ||
| x_new = self.persis_info["rand_stream"].uniform(self.lb, self.ub, (n_trials, self.n)) | ||
| else: | ||
| if not self.U.get("use_grid"): | ||
| x_new = self.x_for_var[np.argsort(self.var_vals)[-n_trials:]] | ||
| else: | ||
| r_high = self.r_high_init | ||
| r_low = self.r_low_init | ||
| x_new = [] | ||
| r_cand = r_high # Let's start with a large radius and stop when we have batchsize points | ||
|
|
||
| sorted_indices = np.argsort(-self.var_vals) | ||
| while len(x_new) < n_trials: | ||
| x_new = _find_eligible_points(self.x_for_var, sorted_indices, r_cand, n_trials) | ||
| if len(x_new) < n_trials: | ||
| r_high = r_cand | ||
| r_cand = (r_high + r_low) / 2.0 | ||
|
|
||
| self.x_new = x_new | ||
| H_o = np.zeros(n_trials, dtype=self.gen_specs["out"]) | ||
| H_o["x"] = self.x_new | ||
| return H_o | ||
|
|
||
| def tell_numpy(self, calc_in: npt.NDArray): | ||
| if calc_in is not None: | ||
| super().tell_numpy(calc_in) | ||
| if not self.U.get("use_grid"): | ||
| n_trials = len(self.y_new) | ||
| self.x_for_var = self.persis_info["rand_stream"].uniform(self.lb, self.ub, (10 * n_trials, self.n)) | ||
|
|
||
| self.var_vals = _eval_var( | ||
| self.my_gp, self.all_x, self.all_y, self.x_for_var, self.test_points, self.persis_info | ||
| ) | ||
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,47 @@ | ||
| """Generator classes providing points using sampling""" | ||
|
|
||
| import numpy as np | ||
|
|
||
| from libensemble.generators import LibensembleGenerator | ||
|
|
||
| __all__ = [ | ||
| "UniformSample", | ||
| ] | ||
|
|
||
|
|
||
| class UniformSample(LibensembleGenerator): | ||
| """ | ||
| This generator returns ``gen_specs["initial_batch_size"]`` uniformly | ||
| sampled points the first time it is called. Afterwards, it returns the | ||
| number of points given. This can be used in either a batch or asynchronous | ||
| mode by adjusting the allocation function. | ||
| """ | ||
|
|
||
| def __init__(self, _, persis_info, gen_specs, libE_info=None) -> list: | ||
| self.persis_info = persis_info | ||
| self.gen_specs = gen_specs | ||
| self.libE_info = libE_info | ||
| self._get_user_params(self.gen_specs["user"]) | ||
|
|
||
| def ask_numpy(self, n_trials): | ||
| H_o = np.zeros(n_trials, dtype=self.gen_specs["out"]) | ||
| H_o["x"] = self.persis_info["rand_stream"].uniform(self.lb, self.ub, (n_trials, self.n)) | ||
|
|
||
| if "obj_component" in H_o.dtype.fields: # needs H_o - needs to be created in here. | ||
| H_o["obj_component"] = self.persis_info["rand_stream"].integers( | ||
| low=0, high=self.gen_specs["user"]["num_components"], size=n_trials | ||
| ) | ||
| return H_o | ||
|
|
||
| def tell_numpy(self, calc_in): | ||
| pass # random sample so nothing to tell | ||
|
|
||
| def _get_user_params(self, user_specs): | ||
| """Extract user params""" | ||
| # b = user_specs["initial_batch_size"] | ||
| self.ub = user_specs["ub"] | ||
| self.lb = user_specs["lb"] | ||
| self.n = len(self.lb) # dimension | ||
| assert isinstance(self.n, int), "Dimension must be an integer" | ||
| assert isinstance(self.lb, np.ndarray), "lb must be a numpy array" | ||
| assert isinstance(self.ub, np.ndarray), "ub must be a numpy array" |
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,38 @@ | ||
| import inspect | ||
|
|
||
| import numpy as np | ||
|
|
||
| from libensemble.message_numbers import EVAL_GEN_TAG, FINISHED_PERSISTENT_GEN_TAG, PERSIS_STOP, STOP_TAG | ||
| from libensemble.tools.persistent_support import PersistentSupport | ||
| from libensemble.utils.misc import np_to_list_dicts | ||
|
|
||
|
|
||
| def persistent_gen_f(H, persis_info, gen_specs, libE_info): | ||
|
|
||
| ps = PersistentSupport(libE_info, EVAL_GEN_TAG) | ||
| U = gen_specs["user"] | ||
| b = U.get("initial_batch_size") or U.get("batch_size") | ||
|
|
||
| generator = U["generator"] | ||
| if inspect.isclass(generator): | ||
| gen = generator(H, persis_info, gen_specs, libE_info) | ||
| else: | ||
| gen = generator | ||
|
|
||
| tag = None | ||
| calc_in = None | ||
| while tag not in [STOP_TAG, PERSIS_STOP]: | ||
| H_o = gen.ask(b) | ||
| if isinstance(H_o, list): | ||
| H_o_arr = np.zeros(len(H_o), dtype=gen_specs["out"]) | ||
| for i in range(len(H_o)): | ||
| for key in H_o[0].keys(): | ||
| H_o_arr[i][key] = H_o[i][key] | ||
| H_o = H_o_arr | ||
| tag, Work, calc_in = ps.send_recv(H_o) | ||
| gen.tell(np_to_list_dicts(calc_in)) | ||
|
jlnav marked this conversation as resolved.
Outdated
|
||
|
|
||
| if hasattr(calc_in, "__len__"): | ||
| b = len(calc_in) | ||
|
|
||
| return H_o, persis_info, FINISHED_PERSISTENT_GEN_TAG | ||
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
We need to decide
__init__interface.We questioned before whether we keep the same interface - which mirrors the current gen_f, or to rearrange, as H is often not given (basically an H0). So it could be
gen_specsfirst. I'm leaning towards keeping the original ordering as it mirrors our user functions, but this should be discussed.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.
Fair enough. My opinion/intuition is a user is more likely to prefer either "classical" gens (e.g. Jeff) or ask/tell gens (e.g. other CAMPA folks). With these gens' interfaces and users being so different, I don't think an arguably simpler rearrangement of the input parameters is too confusing.
Similarly to how some people prefer numpy or pandas; they do similar things, but their interfaces being different isn't a point of contention.
I'd also lean towards if someone were to initialize some object, like a gen, themselves, they'd prefer their specifications be provided as early and clearly as possible:
vs.