Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-20 07:58:59

0001 import os
0002 
0003 import requests
0004 
0005 
0006 # get HP point
0007 def get_hp_point(idds_url, task_id, point_id, tmp_log, verbose):
0008     url = os.path.join(idds_url, "idds", "hpo", str(task_id), "null", str(point_id), "null", "null")
0009     try:
0010         if verbose:
0011             tmp_log.debug(f"getting HP point from {url}")
0012         r = requests.get(url, verify=False)
0013         if verbose:
0014             tmp_log.debug(f"status: {r.status_code}, body: {r.text}")
0015         if r.status_code != requests.codes.ok:
0016             return False, f"bad http status {r.status_code} when getting point (ID={point_id}) : {r.text}"
0017         tmp_dict = r.json()
0018         for i in tmp_dict:
0019             if i["id"] == point_id:
0020                 return True, i
0021     except Exception as e:
0022         return False, f"failed to get point (ID={point_id}) : {str(e)}"
0023 
0024     return False, f"cannot get point (ID={point_id}) since it is unavailable"
0025 
0026 
0027 # update HP point
0028 def update_hp_point(idds_url, task_id, point_id, loss, tmp_log, verbose):
0029     url = os.path.join(idds_url, "idds", "hpo", str(task_id), "null", str(point_id), str(loss))
0030     try:
0031         if verbose:
0032             tmp_log.debug(f"updating HP point at {url}")
0033         r = requests.put(url, verify=False)
0034         if verbose:
0035             tmp_log.debug(f"status: {r.status_code}, body: {r.text}")
0036         if r.status_code != requests.codes.ok:
0037             return False, f"bad http status {r.status_code} when updating point (ID={point_id}) : {r.text}"
0038         tmp_dict = r.json()
0039         if tmp_dict["status"] == 0:
0040             return True, None
0041     except Exception as e:
0042         return False, f"failed to update point (ID={point_id}) : {str(e)}"
0043 
0044     return False, f"cannot update point (ID={point_id}) since status is missing"