def validate_optParams()

in source/src/molecule-unfolding/lambda/TaskParametersLambda/app.py [0:0]


def validate_optParams(input_dict: dict, errors: list):
    k = 'optParams'
    if not isinstance(input_dict[k], dict):
        errors.append(f"optParams must be a dict")
    for p in input_dict[k].keys():
        if p not in ['sa', 'qa']:
            errors.append(
                f"invalid key {p} of optParams, values: sa|qa")
        elif not isinstance(input_dict[k][p], dict):
            errors.append(f"optParams[{p}] must be a dict")
        elif 'shots' in input_dict[k][p]:
            shots = input_dict[k][p]['shots']
            if not isinstance(shots, int):
                errors.append(
                    f"optParams[{p}][shots] must be int, invalid value: {shots}")
            elif shots > max_shots or shots < min_shots:
                errors.append(
                    f"optParams[{p}][shots], invalid shots value: {shots}, value range [{min_shots}, {max_shots}]")
        if p == 'qa':
            for kk in input_dict[k][p].keys():
                if kk not in ['shots', 'embed_method']:
                    errors.append(
                        f'invalid param for {k}.{p}: {kk}, support params: shots|embed_method')
                if kk == 'embed_method' and input_dict[k][p][kk] != 'default':
                    errors.append(
                        f'invalid value for {k}.{p}.{kk}: {input_dict[k][p][kk]}, support value: default')

        if p == 'sa':
            for kk in input_dict[k][p].keys():
                if kk not in ['shots', 'notes']:
                    errors.append(
                        f'invalid param for {k}.{p}: {kk}, support params: shots|notes')
                if kk == 'notes' and len(input_dict[k][p][kk]) > 20:
                    errors.append(
                        f'invalid value for {k}.{p}.{kk}, string len cannot more than 20')