|
| 1 | +import glob |
| 2 | +import os |
| 3 | +import re |
| 4 | +import numpy as np |
| 5 | + |
| 6 | +from libensemble.alloc_funcs.start_only_persistent import only_persistent_gens as alloc_f |
| 7 | +from libensemble.executors.mpi_executor import MPIExecutor |
| 8 | +from libensemble.gen_funcs.persistent_sampling_var_resources import uniform_sample as gen_f |
| 9 | + |
| 10 | +# Import libEnsemble items for this test |
| 11 | +from libensemble import Ensemble |
| 12 | +from libensemble.resources.platforms import PerlmutterGPU |
| 13 | +from libensemble.sim_funcs import six_hump_camel |
| 14 | +from libensemble.sim_funcs.var_resources import gpu_variable_resources as sim_f |
| 15 | +from libensemble.specs import LibeSpecs |
| 16 | + |
| 17 | + |
| 18 | +# from libensemble import logger |
| 19 | +# logger.set_level("DEBUG") # For testing the test |
| 20 | + |
| 21 | +# Main block is necessary only when using local comms with spawn start method (default on macOS and Windows). |
| 22 | +if __name__ == "__main__": |
| 23 | + # Get paths for applications to run |
| 24 | + six_hump_camel_app = six_hump_camel.__file__ |
| 25 | + n = 2 |
| 26 | + |
| 27 | + alloc_specs = { |
| 28 | + "alloc_f": alloc_f, |
| 29 | + "user": { |
| 30 | + "give_all_with_same_priority": False, |
| 31 | + "async_return": False, # False batch returns |
| 32 | + }, |
| 33 | + } |
| 34 | + |
| 35 | + exit_criteria = {"sim_max": 20} |
| 36 | + |
| 37 | + # Ensure LIBE_PLATFORM environment variable is not set. |
| 38 | + if "LIBE_PLATFORM" in os.environ: |
| 39 | + del os.environ["LIBE_PLATFORM"] |
| 40 | + |
| 41 | + exctr = MPIExecutor() |
| 42 | + exctr.register_app(full_path=six_hump_camel_app, app_name="six_hump_camel") |
| 43 | + |
| 44 | + ensemble = Ensemble(parse_args=True, |
| 45 | + executor=exctr, |
| 46 | + alloc_specs=alloc_specs, |
| 47 | + exit_criteria=exit_criteria, |
| 48 | + # libE_specs = LibeSpecs(use_workflow_dir=True, platform_specs=platform_specs), # works |
| 49 | + ) |
| 50 | + |
| 51 | + platform_specs = PerlmutterGPU() |
| 52 | + ensemble.libE_specs = LibeSpecs( |
| 53 | + num_resource_sets=ensemble.nworkers - 1, |
| 54 | + resource_info={"gpus_on_node": 4}, |
| 55 | + use_workflow_dir=True, |
| 56 | + platform_specs=platform_specs, |
| 57 | + ) |
| 58 | + |
| 59 | + ensemble.gen_specs = { |
| 60 | + "gen_f": gen_f, |
| 61 | + "persis_in": ["f", "x", "sim_id"], |
| 62 | + "out": [("priority", float), ("resource_sets", int), ("x", float, n)], |
| 63 | + "user": { |
| 64 | + "initial_batch_size": ensemble.nworkers - 1, |
| 65 | + "max_resource_sets": ensemble.nworkers - 1, # Any sim created can req. 1 worker up to all. |
| 66 | + "lb": np.array([-3, -2]), |
| 67 | + "ub": np.array([3, 2]), |
| 68 | + }, |
| 69 | + } |
| 70 | + |
| 71 | + ensemble.sim_specs = { |
| 72 | + "sim_f": sim_f, |
| 73 | + "in": ["x"], |
| 74 | + "out": [("f", float)], |
| 75 | + "user": {"dry_run": True}, |
| 76 | + } |
| 77 | + |
| 78 | + ensemble.add_random_streams() |
| 79 | + ensemble.run() |
| 80 | + |
| 81 | + if ensemble.is_manager: |
| 82 | + matching_dirs = glob.glob("workflow_*") |
| 83 | + assert matching_dirs, "No workflow dir found" |
| 84 | + most_recent_dir = max(matching_dirs, key=os.path.getctime) |
| 85 | + print(f"Checking ensemble.log in {most_recent_dir}") |
| 86 | + file_path = file_path = os.path.join(most_recent_dir, 'ensemble.log') |
| 87 | + if os.path.exists(file_path): # an assert |
| 88 | + with open(file_path, 'r') as file: |
| 89 | + content = file.read() |
| 90 | + pattern = r"Runline:\s+srun" |
| 91 | + assert re.findall(pattern, content), "Incorrect MPI runner" |
0 commit comments