MCPcopy Create free account
hub / github.com/dwavesystems/dwave-cloud-client / __init__

Method __init__

dwave/cloud/solver.py:135–183  ·  view source on GitHub ↗
(self, client: Optional['dwave.cloud.Client'],
                 data: Union[dict, SolverConfiguration])

Source from the content-addressed store, hash-verified

133 return client
134
135 def __init__(self, client: Optional['dwave.cloud.Client'],
136 data: Union[dict, SolverConfiguration]):
137 # note: we use a weakref so that client can be closed and gc'ed
138 # while keeping solver instances alive
139 # dev note: allow None value for testing
140 self._client_ref = weakref.ref(client) if client is not None else None
141
142 # note: conversion to `SolverConfiguration` is cheap (order of ~10us)
143 if not isinstance(data, SolverConfiguration):
144 data = SolverConfiguration.model_validate(data)
145 self.data = data
146
147 self.identity = data.identity
148 if self.identity is None:
149 raise ValueError("Missing solver identity field")
150
151 # Properties of this solver the server presents: dict
152 try:
153 self.properties = data.properties
154 except AttributeError:
155 raise SolverPropertyMissingError("Missing solver property: 'properties'")
156
157 # The set of extra parameters this solver will accept in sample_ising or sample_qubo: dict
158 self.parameters = self.properties.get('parameters', {})
159
160 # Ensure this remote solver supports at least one of the problem types we know how to handle
161 try:
162 self.supported_problem_types = set(self.properties['supported_problem_types'])
163 except KeyError:
164 raise SolverPropertyMissingError(
165 "Missing solver property: 'properties.supported_problem_types'")
166
167 if self.supported_problem_types.isdisjoint(self._handled_problem_types):
168 raise UnsupportedSolverError(
169 ("Remote solver {name!r} supports {supports} problems, "
170 "but {cls!r} class of solvers handles only {handled}").format(
171 name=self.name,
172 supports=list(self.supported_problem_types),
173 cls=type(self).__name__,
174 handled=list(self._handled_problem_types)))
175
176 # When True the solution data will be returned as numpy matrices: False
177 # TODO: deprecate
178 self.return_matrix = False
179
180 # Derived solver properties (not present in solver data properties dict)
181 self.derived_properties = {
182 'id', 'name', 'online', 'avg_load', 'qpu', 'hybrid', 'software',
183 }
184
185 def __repr__(self):
186 return f"{type(self).__name__}(name={self.name!r})"

Callers 1

__init__Method · 0.45

Calls 4

getMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected