コード例 #1
0
ファイル: _inputparser.py プロジェクト: taalexander/aqua
    def _update_input_problem(self):
        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.")

        input_name = self.get_section_property(InputParser.INPUT,
                                               JSONSchema.NAME)
        if input_name is not None and problem_name in InputParser.get_input_problems(
                input_name):
            return

        for input_name in local_inputs():
            if problem_name in self.get_input_problems(input_name):
                # set to the first input to solve the problem
                self.set_section_property(InputParser.INPUT, JSONSchema.NAME,
                                          input_name)
                return

        # no input solve this problem, remove section
        self.delete_section(InputParser.INPUT)
コード例 #2
0
ファイル: _model.py プロジェクト: simhan/aqua
    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
コード例 #3
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
コード例 #4
0
ファイル: _model.py プロジェクト: takehuge/aqua
    def get_input_section_names(self):
        problem_name = None
        if self._parser is not None:
            problem_name = self.get_section_property(InputParser.PROBLEM,
                                                     InputParser.NAME)
        if problem_name is None:
            problem_name = self.get_property_default_value(
                InputParser.PROBLEM, InputParser.NAME)

        if problem_name is None:
            return local_inputs()

        input_names = []
        for input_name in local_inputs():
            problems = InputParser.get_input_problems(input_name)
            if problem_name in problems:
                input_names.append(input_name)

        return input_names
コード例 #5
0
ファイル: _model.py プロジェクト: simhan/aqua
    def get_input_section_names(self):
        from qiskit_aqua.parser import InputParser
        from qiskit_aqua.input import local_inputs
        from qiskit_aqua.parser import JSONSchema
        problem_name = None
        if self._parser is not None:
            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:
            return local_inputs()

        input_names = []
        for input_name in local_inputs():
            problems = InputParser.get_input_problems(input_name)
            if problem_name in problems:
                input_names.append(input_name)

        return input_names
コード例 #6
0
ファイル: _model.py プロジェクト: xiaoyaolanyun/aqua
    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)