def test_unstructured_sampler(self): with self.assertRaises(ValueError): dimod.child_structure_dfs(dimod.NullSampler()) nested = dimod.TrackingComposite(dimod.NullSampler()) with self.assertRaises(ValueError): dimod.child_structure_dfs(nested)
def test_composed_sampler(self): nodelist = list(range(5)) edgelist = list(itertools.combinations(nodelist, 2)) structured_sampler = dimod.StructureComposite(dimod.NullSampler(), nodelist, edgelist) sampler = dimod.TrackingComposite(structured_sampler) structure = dimod.child_structure_dfs(sampler) self.assertEqual(structure.nodelist, nodelist) self.assertEqual(structure.edgelist, edgelist)
def embed_graph(self): """ Separate function as graph embedding can be reused so long as self.dim, self.k remain constant Embed graph maps the fully connected Ising model we have defined to the D-Wave Chimera topology """ source_edgelist = [(i, j) for i in range(int(self.nqubits)) for j in range(i, int(self.nqubits))] dws = DWaveSampler(qpu=True) # instantiate DWaveSampler dws_structure = dimod.child_structure_dfs(dws) target_edgelist = dws_structure.edgelist self.embedding = mm.find_embedding(source_edgelist, target_edgelist) physical_qubits = [] for qubit_list in self.embedding.values( ): # this loop just puts all the physical qubit indices into one list physical_qubits += qubit_list print("Number of physical qubits: ", len(physical_qubits))
def test_sampler(self): # not a composed sampler nodelist = list(range(5)) edgelist = list(itertools.combinations(nodelist, 2)) class Dummy(dimod.Structured): @property def nodelist(self): return nodelist @property def edgelist(self): return edgelist sampler = Dummy() structure = dimod.child_structure_dfs(sampler) self.assertEqual(structure.nodelist, nodelist) self.assertEqual(structure.edgelist, edgelist)