def test_sample_bqm(self, mock_client): mock_client.from_config.side_effect = MockClient bqm = dimod.BinaryQuadraticModel({'a': -1, 'b': 1, 'c': 1}, {'ab': -0.8, 'ac': -0.7, 'bc': -1}, 0, dimod.SPIN) sampler = LeapHybridSampler() response = sampler.sample(bqm) rows, cols = response.record.sample.shape self.assertEqual(cols, 3) self.assertFalse(np.any(response.record.sample == 0)) self.assertIs(response.vartype, dimod.SPIN) self.assertIn('num_occurrences', response.record.dtype.fields)
config = sigma_is_one_constraints(G.number_of_nodes()) for node in G.nodes(): variables = [str(node) + str(pos) for pos in G.nodes()] csp.add_constraint(config, variables) for pos in G.nodes(): variables = [str(node) + str(pos) for node in G.nodes()] csp.add_constraint(config, variables) bqm = dwavebinarycsp.stitch(csp, max_graph_size=15) #%% sampler = LeapHybridSampler() response = sampler.sample(bqm) # %% from collections import defaultdict data = create_tsp_data_model(5) G = nx.from_numpy_matrix(data["distance_matrix_numpy"]) time_window = defaultdict(bool) i = 0 for node in range(5): i += 1 for pos in range(5): if pos < i: time_window[(4 - node, pos)] = True else: