Esempio n. 1
0
    def _update_operator_input_schema(self):
        # find operator
        default_name = self.get_property_default_value(InputParser.OPERATOR, JSONSchema.NAME)
        operator_name = self.get_section_property(InputParser.OPERATOR, JSONSchema.NAME, default_name)
        if operator_name is None:
            # find the first valid input for the problem
            problem_name = self.get_section_property(JSONSchema.PROBLEM, JSONSchema.NAME)
            if problem_name is None:
                problem_name = self.get_property_default_value(JSONSchema.PROBLEM, JSONSchema.NAME)

            if problem_name is None:
                raise QiskitChemistryError("No algorithm 'problem' section found on input.")

            for name in local_chemistry_operators():
                if problem_name in self.get_operator_problems(name):
                    # set to the first input to solve the problem
                    operator_name = name
                    break

        if operator_name is None:
            # just remove fromm schema if none solves the problem
            if InputParser.OPERATOR in self.json_schema.schema['properties']:
                del self.json_schema.schema['properties'][InputParser.OPERATOR]

            return

        if default_name is None:
            default_name = operator_name

        config = {}
        try:
            config = get_chemistry_operator_configuration(operator_name)
        except:
            pass

        input_schema = config['input_schema'] if 'input_schema' in config else {}
        properties = input_schema['properties'] if 'properties' in input_schema else {}
        properties[JSONSchema.NAME] = {'type': 'string'}
        required = input_schema['required'] if 'required' in input_schema else []
        additionalProperties = input_schema['additionalProperties'] if 'additionalProperties' in input_schema else True
        if default_name is not None:
            properties[JSONSchema.NAME]['default'] = default_name
            required.append(JSONSchema.NAME)

        if InputParser.OPERATOR not in self.json_schema.schema['properties']:
            self.json_schema.schema['properties'][InputParser.OPERATOR] = {'type': 'object'}

        self.json_schema.schema['properties'][InputParser.OPERATOR]['properties'] = properties
        self.json_schema.schema['properties'][InputParser.OPERATOR]['required'] = required
        self.json_schema.schema['properties'][InputParser.OPERATOR]['additionalProperties'] = additionalProperties
Esempio n. 2
0
    def get_operator_problems(input_name):
        config = get_chemistry_operator_configuration(input_name)
        if 'problems' in config:
            return config['problems']

        return []