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

Method test_cancel_batch

tests/test_solver.py:406–435  ·  view source on GitHub ↗

Submit batch of problems, then cancel them.

(self)

Source from the content-addressed store, hash-verified

404 self.assertAlmostEqual(energy, evaluate_ising(linear, quad, state))
405
406 def test_cancel_batch(self):
407 """Submit batch of problems, then cancel them."""
408
409 with Client(**config) as client:
410 solver = client.get_solver()
411
412 linear, quad = generate_random_ising_problem(solver)
413
414 max_num_reads = max(solver.properties.get('num_reads_range', [1, 100]))
415 num_reads = min(max_num_reads, 50)
416
417 result_list = []
418 for _ in range(100):
419 results = solver.sample_ising(linear, quad, num_reads=num_reads)
420 result_list.append([results, linear, quad])
421
422 [r[0].cancel() for r in result_list]
423
424 for results, linear, quad in result_list:
425 # Responses must be canceled or correct
426 try:
427 # Did we get the right number of samples?
428 self.assertEqual(num_reads, sum(results.num_occurrences))
429
430 # Make sure the number of occurrences and energies are all correct
431 for energy, state in zip(results.energies, results.samples):
432 self.assertAlmostEqual(energy, evaluate_ising(linear, quad, state))
433
434 except CanceledFutureError:
435 pass
436
437 def test_wait_many(self):
438 """Submit a batch of problems then use `wait_multiple` to wait on all of them."""

Callers

nothing calls this directly

Calls 7

ClientClass · 0.90
evaluate_isingFunction · 0.90
cancelMethod · 0.80
get_solverMethod · 0.45
getMethod · 0.45
sample_isingMethod · 0.45

Tested by

no test coverage detected