def _merge_dependencies(self): algo_name = self.get_section_property(InputParser.ALGORITHM, InputParser.NAME) if algo_name is None: return config = get_algorithm_configuration(algo_name) pluggable_dependencies = [] if 'depends' not in config else config[ 'depends'] pluggable_defaults = {} if 'defaults' not in config else config[ 'defaults'] for pluggable_type in local_pluggables_types(): if pluggable_type != InputParser.ALGORITHM and pluggable_type not in pluggable_dependencies: # remove pluggables from input that are not in the dependencies if pluggable_type in self._sections: del self._sections[pluggable_type] section_names = self.get_section_names() for pluggable_type in pluggable_dependencies: pluggable_name = None new_properties = {} if pluggable_type in pluggable_defaults: for key, value in pluggable_defaults[pluggable_type].items(): if key == InputParser.NAME: pluggable_name = pluggable_defaults[pluggable_type][ key] else: new_properties[key] = value if pluggable_name is None: continue if pluggable_type not in section_names: self.set_section(pluggable_type) if self.get_section_property(pluggable_type, InputParser.NAME) is None: self.set_section_property(pluggable_type, InputParser.NAME, pluggable_name) if pluggable_name == self.get_section_property( pluggable_type, InputParser.NAME): properties = self.get_section_properties(pluggable_type) if new_properties: new_properties.update(properties) else: new_properties = properties self.set_section_properties(pluggable_type, new_properties)
def _update_dependency_sections(self): algo_name = self.get_section_property(InputParser.ALGORITHM, InputParser.NAME) config = {} if algo_name is None else get_algorithm_configuration( algo_name) classical = config['classical'] if 'classical' in config else False pluggable_dependencies = [] if 'depends' not in config else config[ 'depends'] pluggable_defaults = {} if 'defaults' not in config else config[ 'defaults'] pluggable_types = local_pluggables_types() for pluggable_type in pluggable_types: if pluggable_type != InputParser.ALGORITHM and pluggable_type not in pluggable_dependencies: # remove pluggables from input that are not in the dependencies if pluggable_type in self._sections: del self._sections[pluggable_type] for pluggable_type in pluggable_dependencies: pluggable_name = None if pluggable_type in pluggable_defaults: if InputParser.NAME in pluggable_defaults[pluggable_type]: pluggable_name = pluggable_defaults[pluggable_type][ InputParser.NAME] if pluggable_name is not None and pluggable_type not in self._sections: self.set_section_property(pluggable_type, InputParser.NAME, pluggable_name) # update backend based on classical if classical: if InputParser.BACKEND in self._sections: del self._sections[InputParser.BACKEND] else: if InputParser.BACKEND not in self._sections: self._sections[ InputParser.BACKEND] = self.get_section_default_properties( InputParser.BACKEND)
def _update_pluggable_input_schemas(self): # find alogorithm default_algo_name = self.get_property_default_value( InputParser.ALGORITHM, InputParser.NAME) algo_name = self.get_section_property(InputParser.ALGORITHM, InputParser.NAME, default_algo_name) # update alogorithm scheme if algo_name is not None: self._update_pluggable_input_schema(InputParser.ALGORITHM, algo_name, default_algo_name) # update alogorithm depoendencies scheme config = {} if algo_name is None else get_algorithm_configuration( algo_name) classical = config['classical'] if 'classical' in config else False pluggable_dependencies = [] if 'depends' not in config else config[ 'depends'] pluggable_defaults = {} if 'defaults' not in config else config[ 'defaults'] pluggable_types = local_pluggables_types() for pluggable_type in pluggable_types: if pluggable_type != InputParser.ALGORITHM and pluggable_type not in pluggable_dependencies: # remove pluggables from schema that ate not in the dependencies if pluggable_type in self._schema['definitions']: del self._schema['definitions'][pluggable_type] if pluggable_type in self._schema['properties']: del self._schema['properties'][pluggable_type] # update algorithm backend from schema if it is classical or not if classical: if InputParser.BACKEND in self._schema['definitions']: del self._schema['definitions'][InputParser.BACKEND] if InputParser.BACKEND in self._schema['properties']: del self._schema['properties'][InputParser.BACKEND] else: if InputParser.BACKEND not in self._schema['definitions']: self._schema['definitions'][ InputParser.BACKEND] = self._original_schema[ 'definitions'][InputParser.BACKEND] if InputParser.BACKEND not in self._schema['properties']: self._schema['properties'][ InputParser.BACKEND] = self._original_schema['properties'][ InputParser.BACKEND] # update schema with dependencies for pluggable_type in pluggable_dependencies: pluggable_name = None default_properties = {} if pluggable_type in pluggable_defaults: for key, value in pluggable_defaults[pluggable_type].items(): if key == InputParser.NAME: pluggable_name = pluggable_defaults[pluggable_type][ key] else: default_properties[key] = value default_name = pluggable_name pluggable_name = self.get_section_property(pluggable_type, InputParser.NAME, pluggable_name) if pluggable_name is None: continue # update dependency schema self._update_pluggable_input_schema(pluggable_type, pluggable_name, default_name) for property_name in self._schema['definitions'][pluggable_type][ 'properties'].keys(): if property_name in default_properties: self._schema['definitions'][pluggable_type]['properties'][ property_name]['default'] = default_properties[ property_name]
def get_algorithm_problems(algo_name): config = get_algorithm_configuration(algo_name) if 'problems' in config: return config['problems'] return []