Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:58:22

0001 #!/usr/bin/env python
0002 #
0003 # Licensed under the Apache License, Version 2.0 (the "License");
0004 # You may not use this file except in compliance with the License.
0005 # You may obtain a copy of the License at
0006 # http://www.apache.org/licenses/LICENSE-2.0OA
0007 #
0008 # Authors:
0009 # - Wen Guan, <wen.guan@cern.ch>, 2019 - 2020
0010 
0011 
0012 """
0013 Test client.
0014 """
0015 
0016 
0017 from idds.client.clientmanager import ClientManager
0018 from idds.common.utils import get_rest_host
0019 
0020 
0021 def get_workflow():
0022     from idds.workflowv2.workflow import Workflow
0023     from idds.atlas.workflowv2.atlashpowork import ATLASHPOWork
0024 
0025     # request_metadata for predefined method 'nevergrad'
0026     request_metadata = {'workload_id': '20525135', 'sandbox': None, 'method': 'nevergrad', 'opt_space': {"A": {"type": "Choice", "params": {"choices": [1, 4]}}, "B": {"type": "Scalar", "bounds": [0, 5]}}, 'initial_points': [({'A': 1, 'B': 2}, 0.3), ({'A': 1, 'B': 3}, None)], 'max_points': 20, 'num_points_per_generation': 10}   # noqa E501
0027 
0028     # request_metadata for docker method
0029     request_metadata = {'workload_id': '20525134', 'sandbox': 'wguanicedew/idds_hpo_nevergrad', 'workdir': '/data', 'executable': 'docker', 'arguments': 'python /opt/hyperparameteropt_nevergrad.py --max_points=%MAX_POINTS --num_points=%NUM_POINTS --input=/data/%IN --output=/data/%OUT', 'output_json': 'output.json', 'opt_space': {"A": {"type": "Choice", "params": {"choices": [1, 4]}}, "B": {"type": "Scalar", "bounds": [0, 5]}}, 'initial_points': [({'A': 1, 'B': 2}, 0.3), ({'A': 1, 'B': 3}, None)], 'max_points': 20, 'num_points_per_generation': 10}  # noqa E501
0030 
0031     # request_metadata for docker toymc method
0032     request_metadata = {'workload_id': '20525147', 'sandbox': 'wguanicedew/idds_hpo_toymc', 'workdir': '/data', 'executable': 'docker', 'arguments': 'python /opt/hyperparameteropt_toymc.py --max_points=%MAX_POINTS --num_points=%NUM_POINTS --input=/data/%IN --output=/data/%OUT', 'output_json': 'output.json', 'opt_space': {"A": {}}, 'initial_points': [], 'max_points': 20, 'num_points_per_generation': 10}  # noqa E501
0033 
0034     work = ATLASHPOWork(executable=request_metadata.get('executable', None),
0035                         arguments=request_metadata.get('arguments', None),
0036                         parameters=request_metadata.get('parameters', None),
0037                         setup=None, exec_type='local',
0038                         sandbox=request_metadata.get('sandbox', None),
0039                         method=request_metadata.get('method', None),
0040                         container_workdir=request_metadata.get('workdir', None),
0041                         output_json=request_metadata.get('output_json', None),
0042                         opt_space=request_metadata.get('opt_space', None),
0043                         initial_points=request_metadata.get('initial_points', None),
0044                         max_points=request_metadata.get('max_points', None),
0045                         num_points_per_iteration=request_metadata.get('num_points_per_iteration', 10))
0046     wf = Workflow()
0047     wf.set_workload_id(request_metadata.get('workload_id', None))
0048     wf.add_work(work)
0049     return wf
0050 
0051 
0052 if __name__ == '__main__':
0053     host = get_rest_host()
0054     # props = get_req_properties()
0055     # props = get_example_real_tape_stagein_request()
0056     # props = get_example_prodsys2_tape_stagein_request()
0057     # props = get_example_active_learning_request()
0058     workflow = get_workflow()
0059 
0060     # props = pre_check(props)
0061     # print(props)
0062 
0063     wm = ClientManager(host=host)
0064     request_id = wm.submit(workflow)
0065     print(request_id)