def _update_driver_input_schemas(self): # find driver name default_name = self.get_property_default_value(InputParser.DRIVER, JSONSchema.NAME) driver_name = self.get_section_property(InputParser.DRIVER, JSONSchema.NAME, default_name) if driver_name is not None: driver_name = driver_name.strip().lower() for name in local_drivers(): name_orig = name name = name.lower() if driver_name is not None and driver_name == name: config = get_driver_configuration(name_orig) input_schema = copy.deepcopy( config['input_schema']) if 'input_schema' in config else { 'type': 'object' } if '$schema' in input_schema: del input_schema['$schema'] if 'id' in input_schema: del input_schema['id'] self.json_schema.schema['properties'][ driver_name] = input_schema else: if name in self.json_schema.schema['properties']: del self.json_schema.schema['properties'][name]
def parse(self): """Parse the data.""" if self._inputdict is None: if self._filename is None: raise QiskitChemistryError("Missing input file") section = None self._sections = OrderedDict() contents = '' with open(self._filename, 'rt', encoding="utf8", errors='ignore') as f: for line in f: contents += line section = self._process_line(section, line) if self._sections: # convert to aqua compatible json dictionary based on schema driver_configs = OrderedDict() for driver_name in local_drivers(): driver_configs[driver_name.lower( )] = get_driver_configuration(driver_name) json_dict = OrderedDict() for section_name, section in self._sections.items(): types = [] if section_name.lower() in driver_configs: config = driver_configs[section_name.lower()] input_schema = copy.deepcopy( config['input_schema'] ) if 'input_schema' in config else { 'type': 'string' } if 'type' not in input_schema: input_schema['type'] = 'string' types = [input_schema['type']] else: types = self.get_section_types(section_name.lower()) if 'string' in types: json_dict[section_name] = section[ 'data'] if 'data' in section else '' else: json_dict[section_name] = section[ 'properties'] if 'properties' in section else OrderedDict( ) self._sections = json_dict else: contents = contents.strip().replace('\n', '').replace('\r', '') if len(contents) > 0: # check if input file was dictionary try: v = ast.literal_eval(contents) if isinstance(v, dict): self._inputdict = json.loads(json.dumps(v)) self._load_parser_from_dict() except: pass else: self._load_parser_from_dict() # check for old enable_substitutions name old_enable_substitutions = self.get_section_property( JSONSchema.PROBLEM, InputParser._OLD_ENABLE_SUBSTITUTIONS) if old_enable_substitutions is not None: self.delete_section_property(JSONSchema.PROBLEM, InputParser._OLD_ENABLE_SUBSTITUTIONS) self.set_section_property(JSONSchema.PROBLEM, InputParser.AUTO_SUBSTITUTIONS, old_enable_substitutions) self.json_schema.update_backend_schema() self.json_schema.update_pluggable_schemas(self) self._update_driver_input_schemas() self._update_operator_input_schema() self._sections = self._order_sections(self._sections) self._original_sections = copy.deepcopy(self._sections)