in source/src/molecule-unfolding/lambda/TaskParametersLambda/app.py [0:0]
def validate_modelParams(input_dict: dict, errors: list):
k = 'modelParams'
if not isinstance(input_dict[k], dict):
errors.append(f"devicesArns must be a dict")
molFile = input_dict.get('molFile', None)
if molFile is not None:
log.info(f"use your own model file {molFile}, skip check for modelParams")
return
devices_arns = input_dict.get('devicesArns', default_devices_arns)
D_val = input_dict[k].get('D', default_model_params.get('D', [4]))[0]
global MAX_M
log.info(f"MAX_M={MAX_M}")
log.info(f"max_M_for_devices: {max_M_for_devices}")
for d in devices_arns:
max_val_for_device = max_M_for_devices.get(D_val, {}).get(d, MAX_M)
log.info(f"max_val_for_device={max_val_for_device}, {D_val}, {d}")
MAX_M = min(MAX_M, max_val_for_device)
if d not in known_devices_arns:
log.info(f"has_unknown_device {d}, skip modelParams check")
return
log.info(f"D_val={D_val}, MAX_M={MAX_M}")
param_names = dict(input_dict[k]).keys()
for p in param_names:
if p not in ["M", "D", "A", "HQ"]:
errors.append(f"unknown modelParam: {p}")
if not isinstance(input_dict[k][p], list):
errors.append(
f"values of modelParam: {p} must be an array")
list_vals = input_dict[k][p]
for e in list_vals:
if not isinstance(e, int):
errors.append(
f"invalid value {e}, value for {p} must be int")
if p == 'D' and not (list_vals == [8] or list_vals == [4]):
errors.append(
f"invalid value for {p}, current only support '[ 8 ]' or '[ 4 ]'")
if p == 'A' and list_vals != [300]:
errors.append(
f"invalid value for {p}, current only support '[ 300 ]'")
if p == 'HQ' and list_vals != [200]:
errors.append(
f"invalid value for {p}, current only support '[ 200 ]'")
if p == 'M' and (max(list_vals) > MAX_M or min(list_vals) < 1):
errors.append(
f"invalid value for {p}: {list_vals}, support range: [1, {MAX_M}] for the device ")