def test_as_completed(self): """Submit a batch of problems then use `as_completed` to iterate over all of them.""" # Connect with Client(**config) as client: solver = client.get_solver() # Build a problem linear = [0] * (max(solver.nodes) + 1) for index in solver.nodes: linear[index] = random.choice([-1, 1]) quad = { key: random.choice([-1, 1]) for key in solver.undirected_edges } # Sample the solution 100x40 times computations = [ solver.sample_ising(linear, quad, num_reads=40) for _ in range(100) ] # Go over computations, one by one, as they're done and check they're OK for computation in dwave.cloud.computation.Future.as_completed( computations): self.assertTrue(computation.done()) self.assertTrue(40 == sum(computation.occurrences)) for energy, state in zip(computation.energies, computation.samples): self.assertTrue( energy == evaluate_ising(linear, quad, state))
def test_as_completed(self): """Submit a batch of problems then use `as_completed` to iterate over all of them.""" with Client(**config) as client: solver = client.get_solver() linear, quad = generate_random_ising_problem(solver) # Sample the solution 100x40 times computations = [solver.sample_ising(linear, quad, num_reads=40) for _ in range(100)] # Go over computations, one by one, as they're done and check they're OK for computation in dwave.cloud.computation.Future.as_completed(computations): self.assertTrue(computation.done()) self.assertEqual(40, sum(computation.occurrences)) for energy, state in zip(computation.energies, computation.samples): self.assertAlmostEqual(energy, evaluate_ising(linear, quad, state))