def parameters(self): """Return the online backend parameters. Returns: dict: The parameters of the backend. Raises: LookupError: If parameters for the backend can't be found. """ try: backend_name = self.configuration['name'] parameters = self._api.backend_parameters(backend_name) # FIXME a hack to remove parameters data that is none. # Needs to be fixed in api if backend_name == 'ibmq_qasm_simulator': parameters = {} except Exception as ex: raise LookupError( "Couldn't get backend parameters: {0}".format(ex)) parameters_edit = {} for key, vals in parameters.items(): new_key = _camel_case_to_snake_case(key) parameters_edit[new_key] = vals return parameters_edit
def __init__(self, configuration, provider, credentials, api): """Initialize remote backend for IBM Quantum Experience. Args: configuration (dict): configuration of backend. provider (IBMQProvider): provider. credentials (Credentials): credentials. api (IBMQConnector): api for communicating with the Quantum Experience. """ super().__init__(provider=provider, configuration=configuration) self._api = api if self._configuration: configuration_edit = {} for key, vals in self._configuration.items(): new_key = _camel_case_to_snake_case(key) configuration_edit[new_key] = vals self._configuration = configuration_edit # FIXME: This is a hack to make sure that the # local : False is added to the online device self._configuration['local'] = False self._credentials = credentials self.hub = credentials.hub self.group = credentials.group self.project = credentials.project
def calibration(self): """Return the online backend calibrations. The return is via QX API call. Returns: dict: The calibration of the backend. Raises: LookupError: If a configuration for the backend can't be found. """ try: backend_name = self.configuration['name'] calibrations = self._api.backend_calibration(backend_name) # FIXME a hack to remove calibration data that is none. # Needs to be fixed in api if backend_name == 'ibmq_qasm_simulator': calibrations = {} except Exception as ex: raise LookupError( "Couldn't get backend calibration: {0}".format(ex)) calibrations_edit = {} for key, vals in calibrations.items(): new_key = _camel_case_to_snake_case(key) calibrations_edit[new_key] = vals return calibrations_edit
def calibration(self): """Return the online backend calibrations. The return is via QX API call. Returns: dict: The calibration of the backend. Raises: LookupError: If a calibration for the backend can't be found. :deprecated: will be removed after 0.7 """ warnings.warn("Backends will no longer return a calibration dictionary, " "use backend.properties() instead.", DeprecationWarning) try: backend_name = self.name() calibrations = self._api.backend_calibration(backend_name) # FIXME a hack to remove calibration data that is none. # Needs to be fixed in api if backend_name == 'ibmq_qasm_simulator': calibrations = {} except Exception as ex: raise LookupError( "Couldn't get backend calibration: {0}".format(ex)) calibrations_edit = {} for key, vals in calibrations.items(): new_key = _camel_case_to_snake_case(key) calibrations_edit[new_key] = vals return calibrations_edit
def _parse_backend_configuration(cls, config): """Parse a backend configuration returned by IBMQ. Args: config (dict): raw configuration as returned by IBMQ. Returns: dict: parsed configuration. """ edited_config = {'local': False} for key in config.keys(): new_key = _camel_case_to_snake_case(key) if new_key not in ['id', 'serial_number', 'topology_id', 'status']: edited_config[new_key] = config[key] return edited_config
def __init__(self, configuration, api=None): """Initialize remote backend for IBM Quantum Experience. Args: configuration (dict): configuration of backend. api (IBMQuantumExperience.IBMQuantumExperience.IBMQuantumExperience): api for communicating with the Quantum Experience. """ super().__init__(configuration=configuration) self._api = api if self._configuration: configuration_edit = {} for key, vals in self._configuration.items(): new_key = _camel_case_to_snake_case(key) configuration_edit[new_key] = vals self._configuration = configuration_edit # FIXME: This is a hack to make sure that the # local : False is added to the online device self._configuration['local'] = False
def properties(self): """Return the online backend properties. The return is via QX API call. Returns: dict: The properties of the backend. Raises: LookupError: If properties for the backend can't be found. """ properties = self._api.backend_properties(self.name()) # Convert the properties to snake_case. # TODO: ideally should be handled at the API level. properties_edit = {} for key, val in properties.items(): new_key = _camel_case_to_snake_case(key) properties_edit[new_key] = val return properties_edit
def _parse_backend_configuration(cls, config): """ Parse a backend configuration returned by IBMQuantumConfiguration. Args: config (dict): raw configuration as returned by IBMQuantumExperience. Returns: dict: parsed configuration. """ edited_config = { 'local': False } for key in config.keys(): new_key = _camel_case_to_snake_case(key) if new_key not in ['id', 'serial_number', 'topology_id', 'status']: edited_config[new_key] = config[key] return edited_config
def available_backends(self, hub=None, group=None, project=None, access_token=None, user_id=None): """ Get the backends available to use in the QX Platform """ if access_token: self.req.credential.set_token(access_token) if user_id: self.req.credential.set_user_id(user_id) if not self.check_credentials(): raise CredentialsError('credentials invalid') url = get_backend_url(self.config, hub, group, project) response = self.req.get(url) if (response is not None) and (isinstance(response, dict)): return [] # Pre-process configurations in order to make them schema-conformant. # TODO: this should be removed once devices return the proper format. ret = [] for original_config in response: if original_config.get('status', 'off') != 'on': continue config = {} # Convert camelCase to snake_case. for key in original_config.keys(): new_key = _camel_case_to_snake_case(key) if new_key not in [ 'id', 'serial_number', 'topology_id', 'status' ]: config[new_key] = original_config[key] # Empty and non-schema conformat versions. if not re.match(r'[0-9]+.[0-9]+.[0-9]+', config.get('version', '')): config['version'] = '0.0.0' # Coupling map for simulators. if config.get('coupling_map', None) == 'all-to-all': config.pop('coupling_map') # Other fields. config['basis_gates'] = config['basis_gates'].split(',') config['local'] = config.get('local', False) config['open_pulse'] = config.get('open_pulse', False) config['conditional'] = config.get('conditional', True) config['backend_name'] = config.pop('name') config['backend_version'] = config.pop('version') config['gates'] = [{ 'name': 'TODO', 'parameters': [], 'qasm_def': 'TODO' }] # Append to returned list. ret.append(config) return ret