Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions docs/platforms/frontier.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@ Now grab an interactive session on one node::

Then in the session run::

python run_libe_forces.py --nworkers 9
python run_libe_forces.py --nworkers 8

This places the generator on the first worker and runs simulations on the
others (each simulation using one GPU).
The workers will each run simulations with one GPU each.

To see GPU usage, ssh into the node you are on in another window and run::

Expand Down
5 changes: 2 additions & 3 deletions docs/platforms/perlmutter.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,9 @@ Now grab an interactive session on one node::
Then in the session run::

export LIBE_PLATFORM="perlmutter_g"
python run_libe_forces.py -n 5
python run_libe_forces.py -n 4

This places the generator on the first worker and runs simulations on the
others (each simulation using one GPU).
The workers will each run simualations with one GPU each.

To see GPU usage, ssh into the node you are on in another window and run::

Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/xopt_bayesian_gen.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Define the VOCS specification and set up the generator.

.. code-block:: python

libE_specs = LibeSpecs(gen_on_manager=True, nworkers=4)
libE_specs = LibeSpecs(nworkers=4)

vocs = VOCS(
variables={"x1": [0, 1.0], "x2": [0, 10.0]},
Expand Down
6 changes: 3 additions & 3 deletions examples/tutorials/gpcam_surrogate_model/gpcam.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,9 @@
"\n",
"nworkers = 4\n",
"\n",
"# When using gen_on_manager, nworkers is number of concurrent sims.\n",
"# nworkers is number of concurrent sims.\n",
"# final_gen_send means the last evaluated points are returned to the generator to update the model.\n",
"libE_specs = LibeSpecs(nworkers=nworkers, gen_on_manager=True, final_gen_send=True)\n",
"libE_specs = LibeSpecs(nworkers=nworkers, final_gen_send=True)\n",
"\n",
"n = 2 # Input dimensions\n",
"batch_size = 4\n",
Expand Down Expand Up @@ -400,7 +400,7 @@
"import matplotlib\n",
"import matplotlib.pyplot as plt\n",
"\n",
"# Get \"mean_squared_error\" from generators return (worker 0 as we ran gen_on_manager)\n",
"# Get \"mean_squared_error\" from generators return\n",
"mse = persis_info[0][\"mean_squared_error\"]\n",
"niter = len(mse)\n",
"num_sims = list(range(batch_size, (niter * batch_size) + 1, batch_size))\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/tutorials/xopt_bayesian_gen/xopt_EI_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"metadata": {},
"outputs": [],
"source": [
"libE_specs = LibeSpecs(gen_on_manager=True, nworkers=4)\n",
"libE_specs = LibeSpecs(nworkers=4)\n",
"\n",
"vocs = VOCS(\n",
" variables={\"x1\": [0, 1.0], \"x2\": [0, 10.0]},\n",
Expand Down
19 changes: 19 additions & 0 deletions libensemble/specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import warnings
from pathlib import Path

import numpy as np
import pydantic
from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator

Expand Down Expand Up @@ -354,6 +355,24 @@ def set_fields_from_vocs(self):
if "_id" not in self.persis_in:
self.persis_in.append("_id")

# Set user["lb"]/["ub"] from VOCS continuous variables (for legacy generators
# that read bounds from gen_specs["user"]). Skip variables without a ``.domain``
# attribute (e.g., DiscreteVariable). Do not overwrite user-provided values.
if self.user is None:
self.user = {}
if "lb" not in self.user or "ub" not in self.user:
lbs, ubs = [], []
for _name, var in (getattr(self.vocs, "variables", None) or {}).items():
domain = getattr(var, "domain", None)
if domain is not None and len(domain) == 2:
lbs.append(domain[0])
ubs.append(domain[1])
if lbs:
if "lb" not in self.user:
self.user["lb"] = np.array(lbs, dtype=float)
if "ub" not in self.user:
self.user["ub"] = np.array(ubs, dtype=float)

return self

@model_validator(mode="after")
Expand Down
8 changes: 4 additions & 4 deletions libensemble/tests/functionality_tests/test_1d_super_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# TESTSUITE_NPROCS: 2 4

import numpy as np
from gest_api.vocs import VOCS

from libensemble.alloc_funcs.give_sim_work_first import give_sim_work_first
from libensemble.gen_funcs.sampling import latin_hypercube_sample as gen_f
Expand All @@ -38,14 +39,13 @@ def sim_f(In):
"out": [("f", float)],
}

vocs = VOCS(variables={"x0": [-3, 3]}, objectives={"f": "MINIMIZE"})

gen_specs = {
"gen_f": gen_f,
"out": [("x", float, (1,))],
"batch_size": 500,
"user": {
"lb": np.array([-3]),
"ub": np.array([3]),
},
"vocs": vocs,
}

exit_criteria = {"gen_max": 501}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ def sim_f(In):
"out": [("x", float, (2,))],
"initial_batch_size": 20,
"batch_size": 10,
"user": {
"lb": np.array([-3, -2]),
"ub": np.array([3, 2]),
},
}

variables = {"x0": [-3, 3], "x1": [-2, 2]}
Expand Down
9 changes: 4 additions & 5 deletions libensemble/tests/functionality_tests/test_calc_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# TESTSUITE_COMMS: mpi local tcp
# TESTSUITE_NPROCS: 2 4

import numpy as np
from gest_api.vocs import VOCS

from libensemble.alloc_funcs.give_sim_work_first import give_sim_work_first
from libensemble.gen_funcs.sampling import uniform_random_sample as gen_f
Expand All @@ -35,15 +35,14 @@ def six_hump_camel_err(H, persis_info, sim_specs, _):
"out": [("f", float)],
}

vocs = VOCS(variables={"x0": [-3, 3], "x1": [-2, 2]}, objectives={"f": "MINIMIZE"})

gen_specs = {
"gen_f": gen_f,
"in": ["sim_id"],
"out": [("x", float, 2)],
"batch_size": 10,
"user": {
"lb": np.array([-3, -2]),
"ub": np.array([3, 2]),
},
"vocs": vocs,
}

alloc_specs = {
Expand Down
16 changes: 11 additions & 5 deletions libensemble/tests/functionality_tests/test_cancel_in_alloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# TESTSUITE_NPROCS: 4

import numpy as np
from gest_api.vocs import VOCS

from libensemble.alloc_funcs.give_sim_work_first import give_sim_work_first
from libensemble.gen_funcs.sampling import uniform_random_sample as gen_f
Expand All @@ -39,16 +40,15 @@
"user": {"uniform_random_pause_ub": 10},
}

vocs = VOCS(variables={"x0": [-3, 3], "x1": [-2, 2]}, objectives={"f": "MINIMIZE"})

gen_specs = {
"gen_f": gen_f,
"in": ["sim_id"],
"out": [("x", float, (2,))],
"batch_size": 5,
"num_active_gens": 1,
"user": {
"lb": np.array([-3, -2]),
"ub": np.array([3, 2]),
},
"vocs": vocs,
}

alloc_specs = {
Expand All @@ -62,7 +62,13 @@
exit_criteria = {"sim_max": 10, "wallclock_max": 300}

# Perform the run
H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, libE_specs=libE_specs, alloc_specs=alloc_specs)
H, persis_info, flag = libE(
sim_specs,
gen_specs,
exit_criteria,
libE_specs=libE_specs,
alloc_specs=alloc_specs,
)

if is_manager:
test = np.any(H["cancel_requested"]) and np.any(H["kill_sent"])
Expand Down
8 changes: 4 additions & 4 deletions libensemble/tests/functionality_tests/test_comms.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# TESTSUITE_NPROCS: 2 4

import numpy as np
from gest_api.vocs import VOCS

from libensemble.alloc_funcs.give_sim_work_first import give_sim_work_first
from libensemble.executors.mpi_executor import MPIExecutor # Only used to get workerID in float_x1000
Expand All @@ -41,15 +42,14 @@
"out": [("arr_vals", float, array_size), ("scal_val", float)],
}

vocs = VOCS(variables={"x0": [-3, 3], "x1": [-2, 2]}, objectives={"f": "MINIMIZE"})

gen_specs = {
"gen_f": gen_f,
"in": ["sim_id"],
"out": [("x", float, (2,))],
"batch_size": sim_max,
"user": {
"lb": np.array([-3, -2]),
"ub": np.array([3, 2]),
},
"vocs": vocs,
}

exit_criteria = {"sim_max": sim_max, "wallclock_max": 300}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# TESTSUITE_COMMS: mpi local tcp
# TESTSUITE_NPROCS: 2 4

import numpy as np
from gest_api.vocs import VOCS

from libensemble.alloc_funcs.give_sim_work_first import give_sim_work_first
from libensemble.gen_funcs.sampling import uniform_random_sample as gen_f
Expand All @@ -34,16 +34,15 @@
"user": {"pause_time": 2},
}

vocs = VOCS(variables={"x0": [-3, 3], "x1": [-2, 2]}, objectives={"f": "MINIMIZE"})

gen_specs = {
"gen_f": gen_f,
"in": ["sim_id"],
"out": [("x", float, (2,))],
"batch_size": 5,
"num_active_gens": 2,
"user": {
"lb": np.array([-3, -2]),
"ub": np.array([3, 2]),
},
"vocs": vocs,
}

alloc_specs = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# TESTSUITE_NPROCS: 2 4

import numpy as np
from gest_api.vocs import VOCS

# Import libEnsemble items for this test
from libensemble import Ensemble
Expand All @@ -24,11 +25,8 @@
from libensemble.specs import AllocSpecs, ExitCriteria, GenSpecs, SimSpecs


def create_H0(gen_specs, H0_size):
def create_H0(lb, ub, H0_size):
"""Create an H0 for give_pregenerated_sim_work"""
# Manually creating H0
ub = gen_specs["user"]["ub"]
lb = gen_specs["user"]["lb"]
n = len(lb)
b = H0_size

Expand All @@ -45,18 +43,19 @@ def create_H0(gen_specs, H0_size):
sampling = Ensemble(parse_args=True)
sampling.sim_specs = SimSpecs(sim_f=sim_f, inputs=["x"], out=[("f", float)])

gen_specs = {
"gen_f": gen_f,
"outputs": [("x", float, (2,))],
"batch_size": 50,
"user": {
"lb": np.array([-3, -3]),
"ub": np.array([3, 3]),
},
}
sampling.gen_specs = GenSpecs(**gen_specs)
vocs = VOCS(variables={"x0": [-3, 3], "x1": [-3, 3]}, objectives={"f": "MINIMIZE"})
lb = np.array([-3, -3])
ub = np.array([3, 3])

sampling.gen_specs = GenSpecs(
gen_f=gen_f,
persis_in=["f"],
outputs=[("x", float, (2,))],
batch_size=50,
vocs=vocs,
)
sampling.exit_criteria = ExitCriteria(sim_max=100)
sampling.H0 = create_H0(gen_specs, 50)
sampling.H0 = create_H0(lb, ub, 50)
sampling.alloc_specs = AllocSpecs(alloc_f=give_sim_work_first)
sampling.run()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import os
import sys

import numpy as np
from forces_simf import run_forces # Sim func from current dir
from gest_api.vocs import VOCS

from libensemble import Ensemble
from libensemble.executors import MPIExecutor
Expand Down Expand Up @@ -37,17 +37,16 @@
outputs=[("energy", float)],
)

vocs = VOCS(variables={"nparticles": [1000, 3000]}, objectives={"energy": "MINIMIZE"})

ensemble.gen_specs = GenSpecs(
gen_f=gen_f,
inputs=[], # No input when starting persistent generator
persis_in=["sim_id"], # Return sim_ids of evaluated points to generator
outputs=[("x", float, (1,))],
initial_batch_size=nsim_workers,
async_return=False,
user={
"lb": np.array([1000]), # min particles
"ub": np.array([3000]), # max particles
},
vocs=vocs,
) # gen_specs_end_tag

# Starts one persistent generator. Simulated values are returned in batch.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import os
import sys

import numpy as np
from forces_simf import run_forces # Sim func from current dir
from gest_api.vocs import VOCS

from libensemble import Ensemble, logger
from libensemble.executors import MPIExecutor
Expand Down Expand Up @@ -39,17 +39,16 @@
outputs=[("energy", float)],
)

vocs = VOCS(variables={"nparticles": [1000, 3000]}, objectives={"energy": "MINIMIZE"})

ensemble.gen_specs = GenSpecs(
gen_f=gen_f,
inputs=[], # No input when starting persistent generator
persis_in=["sim_id"], # Return sim_ids of evaluated points to generator
outputs=[("x", float, (1,))],
initial_batch_size=nsim_workers,
async_return=True,
user={
"lb": np.array([1000]), # min particles
"ub": np.array([3000]), # max particles
},
vocs=vocs,
) # gen_specs_end_tag

# Starts one persistent generator. Simulated values are returned in batch.
Expand Down
Loading
Loading