Skip to content

Commit 833a9b0

Browse files
authored
Add Proxystore example (#1326)
* Add test that inserts proxystore proxies into H.
1 parent 36fb0e3 commit 833a9b0

4 files changed

Lines changed: 101 additions & 0 deletions

File tree

.github/workflows/extra.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,12 @@ jobs:
229229
rm ./libensemble/tests/unit_tests/test_ufunc_runners.py
230230
rm ./libensemble/tests/unit_tests/test_executor_balsam.py
231231
232+
- name: Start Redis
233+
if: matrix.os == 'ubuntu-latest'
234+
uses: supercharge/redis-github-action@1.7.0
235+
with:
236+
redis-version: 7
237+
232238
- name: Run extensive tests, Ubuntu
233239
if: matrix.os == 'ubuntu-latest'
234240
run: |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
globus-compute-sdk==2.25.0
2+
proxystore==0.7.0
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../docs/images/libE_logo.png
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
"""
2+
Test libEnsemble's capability to use no gen_f and instead coordinates the
3+
evaluation of an existing set of points.
4+
5+
Execute via one of the following commands (e.g. 3 workers):
6+
mpiexec -np 4 python test_evaluate_existing_sample.py
7+
python test_evaluate_existing_sample.py --nworkers 3 --comms local
8+
python test_evaluate_existing_sample.py --nworkers 3 --comms tcp
9+
10+
The number of concurrent evaluations of the objective function will be 4-1=3.
11+
"""
12+
13+
# Do not change these lines - they are parsed by run-tests.sh
14+
# TESTSUITE_COMMS: local
15+
# TESTSUITE_NPROCS: 4
16+
# TESTSUITE_OS_SKIP: OSX WIN
17+
# TESTSUITE_EXTRA: true
18+
19+
from pathlib import Path
20+
21+
import numpy as np
22+
23+
# Import libEnsemble items for this test
24+
from libensemble import Ensemble
25+
from libensemble.alloc_funcs.give_pregenerated_work import give_pregenerated_sim_work as alloc_f
26+
from libensemble.sim_funcs.borehole import gen_borehole_input
27+
from libensemble.specs import AllocSpecs, ExitCriteria, SimSpecs, input_fields, output_data
28+
29+
30+
def insert_proxy(H0):
31+
from proxystore.connectors.redis import RedisConnector
32+
from proxystore.store import Store, get_store
33+
34+
store = Store(
35+
"my-store",
36+
RedisConnector(hostname="localhost", port=6379),
37+
register=True,
38+
)
39+
40+
store = get_store("my-store")
41+
picture = Path("libE_logo.png").read_bytes()
42+
proxy = store.proxy(picture)
43+
for i in range(len(H0)):
44+
H0[i]["proxy"] = proxy
45+
46+
47+
def check_H(H):
48+
from proxystore.proxy import Proxy
49+
50+
assert all([isinstance(H[i]["proxy"], Proxy) for i in range(len(H))])
51+
52+
53+
@input_fields(["x", "proxy"])
54+
@output_data([("f", float)])
55+
def one_d_example(x, persis_info, sim_specs, info):
56+
57+
H_o = np.zeros(1, dtype=sim_specs["out"])
58+
H_o["f"] = np.linalg.norm(x["x"])
59+
picture = bytes(x["proxy"][0])
60+
61+
sim_id = info["H_rows"][0]
62+
worker_id = info["workerID"]
63+
64+
Path(f"logo_id{sim_id}_worker{worker_id}.png").write_bytes(picture)
65+
66+
return H_o, persis_info
67+
68+
69+
# Main block is necessary only when using local comms with spawn start method (default on macOS and Windows).
70+
if __name__ == "__main__":
71+
72+
n_samp = 4
73+
H0 = np.zeros(n_samp, dtype=[("x", float, 8), ("sim_id", int), ("sim_started", bool), ("proxy", object)])
74+
np.random.seed(0)
75+
H0["x"] = gen_borehole_input(n_samp)
76+
H0["sim_id"] = range(n_samp)
77+
H0["sim_started"] = False
78+
insert_proxy(H0)
79+
80+
sampling = Ensemble(parse_args=True)
81+
sampling.H0 = H0
82+
sampling.sim_specs = SimSpecs(sim_f=one_d_example)
83+
sampling.alloc_specs = AllocSpecs(alloc_f=alloc_f)
84+
sampling.exit_criteria = ExitCriteria(sim_max=len(H0))
85+
sampling.run()
86+
87+
if sampling.is_manager:
88+
assert len(sampling.H) == len(H0)
89+
assert np.array_equal(H0["x"], sampling.H["x"])
90+
assert np.all(sampling.H["sim_ended"])
91+
check_H(sampling.H)
92+
print("\nlibEnsemble correctly didn't add anything to initial sample")
93+
sampling.save_output(__file__)

0 commit comments

Comments
 (0)