|
181 | 181 | " task = exctr.submit(app_name=\"forces\", app_args=args, num_procs=1)\n", |
182 | 182 | "\n", |
183 | 183 | " # Block until the task finishes\n", |
184 | | - " task.wait(timeout=60)\n", |
| 184 | + " task.wait()\n", |
185 | 185 | "\n", |
186 | 186 | " output, calc_status = read_output(sim_specs)\n", |
187 | 187 | "\n", |
|
232 | 232 | "import numpy as np\n", |
233 | 233 | "from pprint import pprint\n", |
234 | 234 | "\n", |
235 | | - "# from forces_simf import run_forces # Sim func from current dir\n", |
| 235 | + "# from forces_simf import run_forces # Use is sim function is in a file\n", |
236 | 236 | "\n", |
237 | 237 | "from libensemble import Ensemble\n", |
| 238 | + "from libensemble.specs import ExitCriteria, GenSpecs, LibeSpecs, SimSpecs\n", |
238 | 239 | "from libensemble.gen_funcs.sampling import uniform_random_sample\n", |
239 | | - "from libensemble.tools import add_unique_random_streams\n", |
240 | 240 | "from libensemble.executors import MPIExecutor\n", |
241 | 241 | "\n", |
242 | 242 | "# Initialize MPI Executor\n", |
|
266 | 266 | "metadata": {}, |
267 | 267 | "outputs": [], |
268 | 268 | "source": [ |
269 | | - "nworkers = 2\n", |
270 | | - "\n", |
271 | 269 | "# Global settings - including creating directories for each simulation\n", |
272 | | - "libE_specs = {\n", |
273 | | - " \"nworkers\": nworkers,\n", |
274 | | - " \"comms\": \"local\",\n", |
275 | | - " \"sim_dirs_make\": True,\n", |
276 | | - "}\n", |
277 | | - "\n", |
278 | | - "# State the sim_f, inputs, outputs\n", |
279 | | - "sim_specs = {\n", |
280 | | - " \"sim_f\": run_forces,\n", |
281 | | - " \"in\": [\"x\"], # Name of input for sim_f (defined in gen_specs[\"out\"])\n", |
282 | | - " \"out\": [(\"energy\", float)],\n", |
283 | | - "}\n", |
284 | | - "\n", |
285 | | - "# State the gen_f, inputs, outputs, additional parameters\n", |
286 | | - "gen_specs = {\n", |
287 | | - " \"gen_f\": uniform_random_sample,\n", |
288 | | - " \"out\": [(\"x\", float, (1,))],\n", |
289 | | - " \"user\": {\n", |
| 270 | + "libE_specs = LibeSpecs(\n", |
| 271 | + " nworkers=2,\n", |
| 272 | + " sim_dirs_make=True,\n", |
| 273 | + ")\n", |
| 274 | + "\n", |
| 275 | + "gen_specs = GenSpecs(\n", |
| 276 | + " gen_f=uniform_random_sample,\n", |
| 277 | + " outputs=[(\"x\", float, (1,))],\n", |
| 278 | + " user={\n", |
290 | 279 | " \"lb\": np.array([1000]), # min particles\n", |
291 | 280 | " \"ub\": np.array([3000]), # max particles\n", |
292 | 281 | " \"gen_batch_size\": 8,\n", |
293 | 282 | " },\n", |
294 | | - "}" |
| 283 | + ")\n", |
| 284 | + "\n", |
| 285 | + "sim_specs = SimSpecs(\n", |
| 286 | + " sim_f=run_forces,\n", |
| 287 | + " inputs=[\"x\"], # Name of input for sim_f (defined in gen_specs.outputs)\n", |
| 288 | + " outputs=[(\"energy\", float)],\n", |
| 289 | + ")" |
295 | 290 | ] |
296 | 291 | }, |
297 | 292 | { |
|
308 | 303 | "outputs": [], |
309 | 304 | "source": [ |
310 | 305 | "# Instruct libEnsemble to exit after this many simulations\n", |
311 | | - "exit_criteria = {\"sim_max\": 8}\n", |
312 | | - "\n", |
313 | | - "# Seed random streams for each worker, particularly for gen_f\n", |
314 | | - "persis_info = add_unique_random_streams({}, nworkers + 1)\n", |
| 306 | + "exit_criteria = ExitCriteria(sim_max=8)\n", |
315 | 307 | "\n", |
316 | 308 | "# Initialize ensemble object, passing executor.\n", |
317 | 309 | "ensemble = Ensemble(\n", |
|
320 | 312 | " gen_specs=gen_specs,\n", |
321 | 313 | " sim_specs=sim_specs,\n", |
322 | 314 | " exit_criteria=exit_criteria,\n", |
323 | | - " persis_info=persis_info,\n", |
324 | | - ")" |
| 315 | + ")\n", |
| 316 | + "\n", |
| 317 | + "# Seed random streams for each worker, particularly for gen_f\n", |
| 318 | + "ensemble.add_random_streams()" |
325 | 319 | ] |
326 | 320 | }, |
327 | 321 | { |
|
559 | 553 | "input_file = \"forces_input\"\n", |
560 | 554 | "\n", |
561 | 555 | "# Add a field to libE_specs\n", |
562 | | - "libE_specs[\"sim_dir_copy_files\"] = [input_file]\n", |
563 | | - "ensemble.libE_specs = libE_specs\n", |
564 | | - "\n", |
565 | | - "ensemble.sim_specs = {\n", |
566 | | - " \"sim_f\": run_forces_using_file,\n", |
567 | | - " \"in\": [\"x\"], # Name of input for sim_f (defined in gen_specs[\"out\"])\n", |
568 | | - " \"out\": [(\"energy\", float)],\n", |
569 | | - " \"user\": {\"input_filename\": input_file, \"input_names\": [\"particles\"]},\n", |
570 | | - "}\n", |
| 556 | + "ensemble.libE_specs.sim_dir_copy_files = [input_file]\n", |
571 | 557 | "\n", |
| 558 | + "ensemble.sim_specs = SimSpecs(\n", |
| 559 | + " sim_f=run_forces_using_file,\n", |
| 560 | + " inputs=[\"x\"], # Name of input for sim_f (defined in gen_specs.outputs)\n", |
| 561 | + " outputs=[(\"energy\", float)],\n", |
| 562 | + " user={\"input_filename\": input_file, \"input_names\": [\"particles\"]},\n", |
| 563 | + ")\n", |
572 | 564 | "\n", |
573 | 565 | "# To reset random number seed in the generator\n", |
574 | | - "ensemble.persis_info = add_unique_random_streams({}, nworkers + 1)\n", |
| 566 | + "ensemble.add_random_streams()\n", |
575 | 567 | "\n", |
576 | 568 | "# Clean up any previous outputs and launch libEnsemble\n", |
577 | 569 | "cleanup()\n", |
|
595 | 587 | { |
596 | 588 | "cell_type": "code", |
597 | 589 | "execution_count": null, |
598 | | - "metadata": {}, |
| 590 | + "metadata": { |
| 591 | + "scrolled": false |
| 592 | + }, |
599 | 593 | "outputs": [], |
600 | 594 | "source": [ |
601 | 595 | "! ls -l ensemble/sim*" |
|
0 commit comments