Exemple #1
0
    def _load_data(self):
        if self._data_loaded:
            return

        from qiskit_aqua import (local_pluggables_types, local_pluggables,
                                 get_pluggable_configuration)
        from qiskit_aqua.input import (local_inputs, get_input_configuration)

        self._property_titles = OrderedDict()
        self._sections = OrderedDict()
        self._sections[Model._INPUT_NAME] = OrderedDict()
        self._property_titles[Model._INPUT_NAME] = OrderedDict()
        for input_name in local_inputs():
            config = copy.deepcopy(get_input_configuration(input_name))
            self._populate_section(Model._INPUT_NAME, input_name, config)

        for pluggable_type in local_pluggables_types():
            self._sections[pluggable_type] = OrderedDict()
            self._property_titles[pluggable_type] = OrderedDict()
            for pluggable_name in local_pluggables(pluggable_type):
                config = copy.deepcopy(
                    get_pluggable_configuration(pluggable_type,
                                                pluggable_name))
                self._populate_section(pluggable_type, pluggable_name, config)

        self._data_loaded = True
Exemple #2
0
    def _update_algorithm_input_schema(self):
        # find alogorithm input
        default_name = self.get_property_default_value(
            InputParser.INPUT, JSONSchema.NAME)
        input_name = self.get_section_property(
            InputParser.INPUT, JSONSchema.NAME, default_name)
        if input_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 AlgorithmError(
                    "No algorithm 'problem' section found on input.")

            for name in local_inputs():
                if problem_name in self.get_input_problems(name):
                    # set to the first input to solve the problem
                    input_name = name
                    break

        if input_name is None:
            # just remove fromm schema if none solves the problem
            if InputParser.INPUT in self._json_schema.schema['properties']:
                del self._json_schema.schema['properties'][InputParser.INPUT]
            return

        if default_name is None:
            default_name = input_name

        config = {}
        try:
            config = get_input_configuration(input_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.INPUT not in self._json_schema.schema['properties']:
            self._json_schema.schema['properties'][InputParser.INPUT] = {
                'type': 'object'}

        self._json_schema.schema['properties'][InputParser.INPUT]['properties'] = properties
        self._json_schema.schema['properties'][InputParser.INPUT]['required'] = required
        self._json_schema.schema['properties'][InputParser.INPUT]['additionalProperties'] = additionalProperties
Exemple #3
0
    def __init__(self):
        """Create Model object."""

        self._property_titles = OrderedDict()
        self._sections = OrderedDict()
        self._sections[Model._INPUT_NAME] = OrderedDict()
        self._property_titles[Model._INPUT_NAME] = OrderedDict()
        for input_name in local_inputs():
            config = copy.deepcopy(get_input_configuration(input_name))
            self._populate_section(Model._INPUT_NAME, input_name, config)

        for pluggable_type in local_pluggables_types():
            self._sections[pluggable_type] = OrderedDict()
            self._property_titles[pluggable_type] = OrderedDict()
            for pluggable_name in local_pluggables(pluggable_type):
                config = copy.deepcopy(
                    get_pluggable_configuration(pluggable_type,
                                                pluggable_name))
                self._populate_section(pluggable_type, pluggable_name, config)
Exemple #4
0
 def get_input_problems(input_name):
     config = get_input_configuration(input_name)
     if 'problems' in config:
         return config['problems']
     
     return []