-
Notifications
You must be signed in to change notification settings - Fork 27
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
Open
jlnav
wants to merge
463
commits into
develop
Choose a base branch
from
experimental/jlnav_plus_shuds_asktell
base: develop
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
ASK/TELL DEVELOP #1307
Changes from 210 commits
Commits
Show all changes
463 commits
Select commit
Hold shift + click to select a range
c9c4671
presumably fix surmise asktell test?
jlnav 601af44
actually fix surmise test. make sure that when passing around single …
jlnav d454b5c
similarly exclude gpcam_class test from tests, for now
jlnav 92e22e4
experimenting with batch_size and initial_batch_size gen_specs options
jlnav d14f4d2
subsequent batch_sizes are either back_size or len(H_in)
jlnav e27487d
now test in test_sampling_asktell_gen
jlnav a6feb77
cover asking aposmm for num points
jlnav 12a133b
various coverage adjustments and fixes
jlnav de1916a
Merge branch 'develop' into experimental/jlnav_plus_shuds_asktell
jlnav ee2508e
initial commit, creating ask/tell gen unit test, base LibensembleGene…
jlnav 070fc6f
add test, arrays become flattened dicts in np_to_list_dicts
jlnav a969f50
remove debug statement
jlnav 6eb5fe8
additional attempts to unflatten the input dict...
jlnav 1261274
fix index ordering, cleanup/complete tentatively unit test
jlnav d960b96
passthrough kwargs to superclasses, try to handle empty lists for sin…
jlnav 3ce0ca2
better handling of multi-dim and single-dim output-array item assignm…
jlnav 09cb4a6
comments
jlnav 601f02c
adjust persistent_gen_wrapper, fix UniformSampleDicts
jlnav 6733fe5
fix ordering of parameters in implemented ask/tell classes and parent…
jlnav 7466100
better detecting of combinable names, by stripping out the numeric su…
jlnav 751de5e
deal with keys that end with integers, but aren't similar to any othe…
jlnav 18e7079
keyword assignment of gen_specs to Surmise
jlnav a34d589
forgot another keyword surmise assignment
jlnav 5f33724
add unit test for awkward H and checking routine from shuds, add case…
jlnav 41c16b7
add optional dtype argument for list_dicts_to_np to preempt "dtype di…
jlnav 4860428
replace _to_array with list_dicts_to_np with dtype parameter. list_di…
jlnav ced8992
fix
jlnav cbfdf0b
Merge branch 'develop' into feature/flatten_asktell_dict_values
jlnav 4261ca8
LibensembleGenerator can provide matching dtype for list_dicts_to_np,…
jlnav 460bbe3
fix
jlnav 7fdd8a6
ahhhh, just gen_specs['out']'s dtype isn't sufficient. persis_in, des…
jlnav 69b0584
removing hardcoded gen_specs.out, removing hardcoded persis_info.nwor…
jlnav 8c01ca9
clarify a comment
jlnav 4541d8a
as discussed, currently gen_specs['out'] must be provided to a gen in…
jlnav 345aea3
Merge pull request #1409 from Libensemble/feature/flatten_asktell_dic…
jlnav fe7629e
Merge branch 'develop' into experimental/jlnav_plus_shuds_asktell
jlnav 0d7e1a3
specify gen_specs.out dtype to conversion in independent borehole-call
jlnav c7d1cb1
dont assert cancelled sims in asktell surmise test (at this time)
jlnav 94de46f
slotting in variables/objectives into Generator abc. changes to subcl…
jlnav 80df25f
try an indexing fix
jlnav b5d8bcf
dont require an explicit "None" to shut down a threaded generator
jlnav f52bf92
various internal logics and routines for buffering results passed bac…
jlnav 5434dfa
fixes
jlnav 0ab048d
given that persis_info available to the aposmm thread needs nworkers.…
jlnav 7a9a2d8
fix
jlnav a68ffb8
tiny fix
jlnav 5228711
tiny fix
jlnav 1ef5898
undo some unneeded changes
jlnav 8371d97
enormously ugly iterating over the buffering, tell_numpy process. got…
jlnav 092be69
Merge branch 'develop' into feature/adjusts_for_optimas
jlnav 3ebc467
making some attributes private
jlnav 1159e74
Merge branch 'develop' into feature/adjusts_for_optimas
jlnav 138c89e
Merge branch 'develop' into experimental/jlnav_plus_shuds_asktell
jlnav 2922259
Merge branch 'experimental/jlnav_plus_shuds_asktell' into feature/adj…
jlnav c2a2802
comments, reorganizing tell_numpy as usual
jlnav 5a2eb09
using gen_specs.batch_size and gen_specs.initial_batch_size to try co…
jlnav 10accde
Merge branch 'develop' into feature/adjusts_for_optimas
jlnav aa8ad57
use base MPIRunner if detection fails, so KeyError doesnt occur?
jlnav 6712f1e
Merge branch 'bugfix/detect_mpiexec_mpis' into feature/adjusts_for_op…
jlnav 1eec392
various fixes as usual, plus experimenting with running gen-on-proces…
jlnav c4418fb
Merge branch 'develop' into experimental/jlnav_plus_shuds_asktell
jlnav 2b8e537
initial commit - adding variables/objectives to initializer signature…
jlnav 70dde7b
recreate the buffer after the results' final opportunity to send onto…
jlnav 484304b
dont need sim_id sorting
jlnav b0897d0
the initial sample being done is determined by the total number of re…
jlnav cdcb2d8
Merge branch 'develop' into experimental/jlnav_plus_shuds_asktell
jlnav 57bbfb1
it was long-past time to give up on the super-complicated slot-in-dat…
jlnav dbd19fd
Merge pull request #1433 from Libensemble/feature/adjusts_for_optimas
jlnav 994b652
enormously critical bugfix; optimas workflow now finds minima
jlnav 64c2cd1
Merge branch 'experimental/jlnav_plus_shuds_asktell' into asktell/var…
jlnav 3104240
experiment with UniformSampleDicts using variables/objectiveso
jlnav 3d262fb
i wonder if we can determine lb, ub, and n based on the contents of s…
jlnav 847a617
APOSMM can now accept variables and objectives instead of needing ub,…
jlnav f45ddbe
cleanup the removed validator; since gen_specs['out'] can be absent
jlnav 26f1d73
cleanup/fixes
jlnav 10e96d8
stop kwargs from replacing entire gen_specs.user; try out vars/objs w…
jlnav 0290deb
Merge branch 'develop' into experimental/jlnav_plus_shuds_asktell
jlnav e01e87b
removing ask/tell generator wrapper user function; removing from samp…
jlnav a1eb450
adjust ask/tell gpcam test
jlnav 23b1549
Merge branch 'experimental/jlnav_plus_shuds_asktell' into asktell/var…
jlnav 1b4c2c6
we dont need to run multiple tests for asktell surmise
jlnav 5f777c2
additional experiments with vars/objs, including seeing if we can app…
jlnav a165cdd
tiny changes for slotting in data back from the waket/optimas workflow
jlnav ac5467b
moving logic for determining lb and ub from variables into parent cla…
jlnav 85507a4
init pair of functions for mapping, slot in where they'll be called
jlnav fc30284
remove a debugging print
jlnav 98267e3
small fixes, including slotting-in x-on-cube, removing hardcoded -10 …
jlnav 74579d5
simplifications from code-review; need to determine reason for hang i…
jlnav 63ef323
i determined that besides having asked for at least as many points as…
jlnav 1b1cd59
better check: all generated sim_ids have returned to the buffer
jlnav dcb3486
fix LibensembleGenThreadInterfacer._set_sim_ended to use results' dty…
jlnav 6828fe0
whoops, fix dtype definition in set_sim_ended
jlnav e443af9
cleanup unused attributes
jlnav a1937a9
better buffer updating suggestion from shuds
jlnav dedef4c
fix ask-the-genf condition to accomodate after initial sample has com…
jlnav 4b812d6
fix set_sim_ended new array dtype specification
jlnav f9e3cba
small fixes, and first tentative implementation of converter for xs t…
jlnav 14c36fa
perhaps the input conversion will be easier on a numpy array?
jlnav 25299e7
tentatively complete converter for vars/objs -> x/f. but those xs and…
jlnav f0736fb
some cleanup
jlnav 7fa4d1e
fix continue-condition to occur earlier if we're looking at keys we d…
jlnav 14daf3c
test fixes, plus if our gen naturally returns the requested variables…
jlnav 114c7a4
fix asktell_gen functionality test - including removing wrapper tests…
jlnav 507bc0a
just use UniformSample class
jlnav 18a52c9
remove ask/tell surmise and ask/tell surmise test - they were proof-o…
jlnav 231e6f0
fix import
jlnav eaebbff
remove the other ask/tell surmise test
jlnav 043feeb
renable persistent_aposmm unit test
jlnav c66f10b
gpCAM class uses returned x
shuds13 3d7981b
Convert numpy scalar types
shuds13 c380595
preparing to add variables_mapping to LibensembleGenerator parent cla…
jlnav fdcfd66
Merge pull request #1453 from Libensemble/experimental/optimas_waket_…
jlnav 1e0abd3
Merge branch 'experimental/jlnav_plus_shuds_asktell' into asktell/var…
jlnav c7ea54b
intermediate work on passing mapping into np_to_list_dicts. need to p…
jlnav c111afd
Call setup on first ask
shuds13 0ee448c
use mapping to construct list_dicts_to_np dtype when provided
jlnav bb37f4b
additional work on replacing dict keys with xs and fs
jlnav 38b3967
some cleanup of generators.py in anticipation of the changes to the d…
jlnav 4b49233
Merge branch 'experimental/jlnav_plus_shuds_asktell' into asktell/var…
jlnav 1d213ef
dont try to determine dtype for fields that aren't actually in the in…
jlnav f8c5eaf
finalize mapping support within list_dicts_to_np, now need to refacto…
jlnav dff6bad
refactoring
jlnav c1ec7f6
tiny fixes; need to figure out why aposmm_nlopt reg test is hanging
jlnav a5133b9
runners.py no longer calls setup() on gen
jlnav 682daa8
rename a handful of asktell tests to have a test_asktell prefix
jlnav 09ebdbc
remove redundant .setup calls that also cause hangs
jlnav 9f200f0
Merge branch 'experimental/jlnav_plus_shuds_asktell' into asktell/var…
jlnav cf5ac63
Merge branch 'develop' into experimental/jlnav_plus_shuds_asktell
jlnav f2ef248
Merge branch 'experimental/jlnav_plus_shuds_asktell' into asktell/var…
jlnav 2c6a9c4
lock nlopt to 2.8.0?
jlnav 7224de3
Merge branch 'develop' into experimental/jlnav_plus_shuds_asktell
jlnav 99a7a2c
Merge branch 'experimental/jlnav_plus_shuds_asktell' into asktell/var…
jlnav e8b7052
Feature/spawn with interfacer (#1464)
shuds13 23e5164
use macOS-supported condition to check if gen_f has enqueued any outb…
jlnav 06c14d7
Merge pull request #1467 from Libensemble/asktell/macos_queue_fixes
jlnav bc1587e
Merge branch 'experimental/jlnav_plus_shuds_asktell' into asktell/var…
jlnav 5c2308d
avoid redundant install of nlopt?
jlnav 0d146fc
Merge branch 'develop' into experimental/jlnav_plus_shuds_asktell
jlnav ef906d5
Merge branch 'experimental/jlnav_plus_shuds_asktell' into asktell/var…
jlnav 9d07e6c
Merge branch 'develop' into experimental/jlnav_plus_shuds_asktell
jlnav 902b7f0
Merge branch 'experimental/jlnav_plus_shuds_asktell' into asktell/var…
jlnav 64b6401
swap sim_id with _id when data goes out from gen. swap _id with sim_i…
jlnav ab09b9f
Merge pull request #1480 from Libensemble/asktell/under_id
jlnav d66dafb
Merge branch 'experimental/jlnav_plus_shuds_asktell' into asktell/var…
jlnav f4a9691
Merge pull request #1448 from Libensemble/asktell/variables_objectives
jlnav 6fb608e
Merge branch 'experimental/jlnav_plus_shuds_asktell' into asktell/try…
jlnav f926bfa
Merge pull request #1451 from Libensemble/asktell/try_removing_wrapper
jlnav 25bca85
rename LibensembleGenThreadInterfacer to PersistentGenInterfacer
jlnav 2973b41
remove ask_updates from abc
jlnav 5a7160f
always build "lb" and "ub" from variables
jlnav b5d66e0
refactoring of list_dicts_to_np, more comments, docstrings, etc.
jlnav bf4577d
refactor np_to_list_dicts
jlnav c24730b
only call ask_updates on gen if its implemented
jlnav 8695692
rename self.thread to self.running_gen_f, some TODO and clarification…
jlnav fcb434e
lets go with the first approach for updating libE_info's comm
jlnav 581c9a5
fix
jlnav 877ecef
Merge pull request #1481 from Libensemble/asktell/various_fixes
jlnav 54d7b3f
Merge branch 'develop' into experimental/jlnav_plus_shuds_asktell
jlnav 1cd8b45
Merge branch 'develop' into experimental/jlnav_plus_shuds_asktell
jlnav 05fca90
Merge branch 'develop' into experimental/jlnav_plus_shuds_asktell
jlnav 7a96995
Merge branch 'develop' into experimental/jlnav_plus_shuds_asktell
jlnav c86c571
Merge branch 'develop' into experimental/jlnav_plus_shuds_asktell
jlnav 8379e0f
first find-and-replace for ask/tell/final_tell to suggest/ingest/fina…
jlnav 0ad9dcf
missed one
jlnav e2263a3
oMerge branch 'develop' into experimental/jlnav_plus_shuds_asktell
jlnav 57e8c4b
Merge branch 'develop' into experimental/jlnav_plus_shuds_asktell
jlnav a952fc1
Merge branch 'develop' into experimental/jlnav_plus_shuds_asktell
jlnav 6ec7528
Merge branch 'develop' into experimental/jlnav_plus_shuds_asktell
jlnav 3ac630a
initial commit, adding upstream current VOCS implementation as depend…
jlnav 08ad9df
initial commit for replacing variables/objectives with VOCS
jlnav aca1d50
Merge branch 'develop' into experimental/jlnav_plus_shuds_asktell
jlnav 6ac1faa
Merge branch 'asktell/init_vocs' into asktell/VOCS
jlnav 56c644e
make generator_standard a required dependency
jlnav fec7aa4
cleanup
jlnav 0db9f0b
some more cleanup, carrying on with making UniformSampler VOCS compat…
jlnav 49fda1e
adjust test_asktell to use VOCS for testing UniformSample
jlnav 1d6f83b
cleanup sampling.py
jlnav 81267a5
first attempt to try simply having new Standard_GP_CAM be a thin wrap…
jlnav b633f94
fix gen standard repo install
jlnav a3e8346
work to convert previous variables/objectives for LibensembleGenerato…
jlnav 4da4298
further work using vocs for self.n, self.lb, self.ub
jlnav c0e452c
make GPCAM_Standard test a separate file
jlnav f9385c2
adjustments for variables_mapping needing to be an attribute of the g…
jlnav 02b349c
trying to figure out why our autogenerated variables_mapping isn't wo…
jlnav f162e75
chasing down a bug involving a single-dim f-shape being not (1,), lik…
jlnav c041a6b
update asktell aposmm unit test
jlnav 23ed512
various fixes involving the dict/array converters, when aposmm has be…
jlnav 34f582e
fix ask/tell sampling test, also don't assume a given gen has a mappi…
jlnav 390597f
include standard-finalize-usage in StandardGenRunner. Then for gens l…
jlnav f80aa9f
Merge branch 'develop' into asktell/VOCS
jlnav 80c09d7
dunno how this validator change made it through
jlnav 7ca34b1
fix isinstance check for gen_f when gen_specs["generator"] is provide…
jlnav f6341a4
this spec-checker was lost to time somehow
jlnav fef5833
Merge branch 'develop' into experimental/jlnav_plus_shuds_asktell
jlnav 673c3eb
Merge branch 'experimental/jlnav_plus_shuds_asktell' into asktell/VOCS
jlnav 65ca79b
revert sampling.py and the associated functionality test to their pre…
jlnav 1ed05e5
various experiments with updating samplers and the test to accept onl…
jlnav 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 9b3429b
Fix finalize and export functions
shuds13 a2c58fc
Option to export with user fields
shuds13 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 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 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): | ||
|
||
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
Show resolved
Hide resolved
|
||
|
||
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_specs
first. 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.