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

Method sample_ising

dwave/cloud/solver.py:1203–1255  ·  view source on GitHub ↗

Sample from the specified :term:`Ising` model. Args: linear (dict/list): Linear biases of the Ising problem. If a dict, should be of the form `{v: bias, ...}` where v is a spin-valued variable and `bias` is its associated bias. If

(self, linear, quadratic, offset=0, label=None, **params)

Source from the content-addressed store, hash-verified

1201 # Sampling methods
1202
1203 def sample_ising(self, linear, quadratic, offset=0, label=None, **params):
1204 """Sample from the specified :term:`Ising` model.
1205
1206 Args:
1207 linear (dict/list):
1208 Linear biases of the Ising problem. If a dict, should be of the
1209 form `{v: bias, ...}` where v is a spin-valued variable and `bias`
1210 is its associated bias. If a list, it is treated as a list of
1211 biases where the indices are the variable labels.
1212
1213 quadratic (dict[(int, int), float]):
1214 Quadratic terms of the model (J), stored in a dict. With keys
1215 that are 2-tuples of variables and values are quadratic biases
1216 associated with the pair of variables (the interaction).
1217
1218 offset (float, optional, default=0):
1219 Constant offset applied to the model.
1220
1221 label (str, optional):
1222 Problem label you can optionally tag submissions with for ease
1223 of identification.
1224
1225 **params:
1226 Parameters for the sampling method, solver-specific.
1227
1228 Returns:
1229 :class:`~dwave.cloud.computation.Future`
1230
1231 Examples:
1232 This example creates a client using the local system's default D-Wave
1233 Cloud Client configuration file, which is configured to access an
1234 Advantage QPU, submits a simple :term:`Ising` problem (opposite
1235 linear biases on two coupled qubits), and samples 5 times.
1236
1237 >>> from dwave.cloud import Client
1238 >>> with Client.from_config() as client:
1239 ... solver = client.get_solver()
1240 ... u, v = next(iter(solver.edges))
1241 ... computation = solver.sample_ising({u: -1, v: 1}, {}, num_reads=5) # doctest: +SKIP
1242 ... for i in range(5):
1243 ... print(computation.samples[i][u], computation.samples[i][v])
1244 ...
1245 ...
1246 (1, -1)
1247 (1, -1)
1248 (1, -1)
1249 (1, -1)
1250 (1, -1)
1251
1252 """
1253 # Our linear and quadratic objective terms are already separated in an
1254 # ising model so we can just directly call `_sample`.
1255 return self._sample('ising', linear, quadratic, offset, params, label=label)
1256
1257 def sample_qubo(self, qubo, offset=0, label=None, **params):
1258 """Sample from the specified :term:`QUBO`.

Calls 1

_sampleMethod · 0.95