def variables(self): """List of active variables in response/answer.""" result = self.result() if 'active_variables' in result: return result['active_variables'] if 'sampleset' in result: return result['sampleset'].variables raise InvalidAPIResponseError( "Active variables not present in the response")
def __init__(self, client, data): # client handles async api requests (via local thread pool) self.client = client # data for each solver includes at least: id, description, properties, # status and avg_load self.data = data # Each solver has an ID field try: self.id = data['id'] except KeyError: raise InvalidAPIResponseError("Missing solver property: 'id'") # Properties of this solver the server presents: dict try: self.properties = data['properties'] except KeyError: raise SolverPropertyMissingError( "Missing solver property: 'properties'") # The set of extra parameters this solver will accept in sample_ising or sample_qubo: dict self.parameters = self.properties.get('parameters', {}) # Ensure this remote solver supports at least one of the problem types we know how to handle try: self.supported_problem_types = set( self.properties['supported_problem_types']) except KeyError: raise SolverPropertyMissingError( "Missing solver property: 'properties.supported_problem_types'" ) if self.supported_problem_types.isdisjoint( self._handled_problem_types): raise UnsupportedSolverError( ("Remote solver {id!r} supports {supports} problems, " "but {cls!r} class of solvers handles only {handled}").format( id=self.id, supports=list(self.supported_problem_types), cls=type(self).__name__, handled=list(self._handled_problem_types))) # When True the solution data will be returned as numpy matrices: False # TODO: deprecate self.return_matrix = False # Derived solver properties (not present in solver data properties dict) self.derived_properties = { 'qpu', 'hybrid', 'software', 'online', 'avg_load', 'name' }