def __init__(self, L, Nmax, t, U, mu, V, Vint, offset): """ Initialization. Input: system size L (int), maximum occupation number N (int), t, U, mu, V, Vint (all are either float or numpy float array of length L) and offset (float). Will generate the MPO of Hamiltonian in self.hamil. """ self.L = L self.d = Nmax + 1 self.t = Common.toArray(L, t) self.U = Common.toArray(L, U) self.mu = Common.toArray(L, mu) self.V = Common.toArray(L, V) self.Vint = Common.toArray(L, Vint) self.hamil = MPO.MPO(L, 5, self.d) self.offset = offset delta = offset / L self.Z = np.zeros((5, self.d, self.d), dtype=complex) self.Z[0, :, :] = np.identity(self.d, dtype=complex) # Id self.Z[1, :, :] = np.diag( np.arange(self.d) * (np.arange(self.d) - 1) + 0j) # n(n-1) self.Z[2, :, :] = np.diag(np.sqrt(np.arange(self.d - 1) + 1) + 0j, -1) # b^dag self.Z[3, :, :] = np.diag(np.sqrt(np.arange(self.d - 1) + 1) + 0j, 1) # b self.Z[4, :, :] = np.diag(np.arange(self.d) + 0j) # n opL = np.zeros((1, 5, 5), dtype=complex) opL[0, 0, 0] = 1 opL[0, 1, 2] = 1 opL[0, 2, 3] = 1 opL[0, 3, 4] = 1 opL[0, 4, 4] = self.V[0] - self.mu[0] opL[0, 4, 1] = self.U[0] / 2 opL[0, 4, 0] = delta self.hamil.setA(0, np.einsum('ijk,kmn->mnij', opL, self.Z)) opR = np.zeros((5, 1, 5), dtype=complex) opR[0, 0, 4] = self.V[self.L - 1] - self.mu[self.L - 1] opR[0, 0, 1] = self.U[self.L - 1] / 2 opR[0, 0, 0] = delta opR[1, 0, 3] = -self.t[self.L - 1] opR[2, 0, 2] = -self.t[self.L - 1] opR[3, 0, 4] = self.Vint[self.L - 2] opR[4, 0, 0] = 1 self.hamil.setA(L - 1, np.einsum('ijk,kmn->mnij', opR, self.Z)) for i in range(1, L - 1): opM = np.zeros((5, 5, 5), dtype=complex) opM[0, 0, 0] = 1 opM[0, 1, 2] = 1 opM[0, 2, 3] = 1 opM[0, 3, 4] = 1 opM[0, 4, 4] = self.V[i] - self.mu[i] opM[0, 4, 1] = self.U[i] / 2 opM[0, 4, 0] = delta opM[1, 4, 3] = -self.t[i] opM[2, 4, 2] = -self.t[i] opM[3, 4, 4] = self.Vint[i - 1] opM[4, 4, 0] = 1 self.hamil.setA(i, np.einsum('ijk,kmn->mnij', opM, self.Z))
def test_common_populate2(self): temp_com = Common() xml_string = "<Common><Citations><li>Random Citation</li></Citations><Summary>Random Summary</Summary></Common>" root = ET.fromstring(xml_string) temp_com.populate(root) self.assertEqual(temp_com.citations[0].floating_text, "Random Citation")
def __init__(self, L, Jx, Jy, Jz, g, h, offset): """ Initialization. Input: system size L (int), interaction Jx, Jy and Jz, longitudinal field g, transverse field h (Jx, Jy, Jz, g and h are either float or numpy float array of length L) and offset (float). Will generate the MPO of Hamiltonian in self.hamil. """ self.L = L self.Jx = Common.toArray(L, Jx) self.Jy = Common.toArray(L, Jy) self.Jz = Common.toArray(L, Jz) self.g = Common.toArray(L, g) self.h = Common.toArray(L, h) self.offset = offset self.hamil = MPO.MPO(L, 5, 2) opL = np.array([[[1, 0, 0, 0], [0, self.Jx[0], 0, 0], [0, 0, self.Jy[0], 0], [0, 0, 0, self.Jz[0]], [offset / L, self.g[0], 0, self.h[0]]]]) opR = np.array([[[offset / L, self.g[L - 1], 0, self.h[L - 1]]], [[0, 1, 0, 0]], [[0, 0, 1, 0]], [[0, 0, 0, 1]], [[1, 0, 0, 0]]]) self.hamil.ops[0].A = np.einsum('ijk,kml->mlij', opL, PauliSigma) self.hamil.ops[L - 1].A = np.einsum('ijk,kml->mlij', opR, PauliSigma) for i in range(1, L - 1): opM = np.array([[[1, 0, 0, 0], [0, self.Jx[i], 0, 0], [0, 0, self.Jy[i], 0], [0, 0, 0, self.Jz[i]], [offset / L, self.g[i], 0, self.h[i]]], [[0, 0, 0, 0], [0, 0, 0, 0], [ 0, 0, 0, 0], [0, 0, 0, 0], [0, 1, 0, 0]], [[0, 0, 0, 0], [0, 0, 0, 0], [ 0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 1, 0]], [[0, 0, 0, 0], [0, 0, 0, 0], [ 0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 1]], [[0, 0, 0, 0], [0, 0, 0, 0], [ 0, 0, 0, 0], [0, 0, 0, 0], [1, 0, 0, 0]] ]) self.hamil.ops[i].A = np.einsum('ijk,kml->mlij', opM, PauliSigma)
def test_print_xml2(self): temp_com = Common() xml_string = "<Common><Citations><li>dvfjnkjdnv</li></Citations><ExternalLinks><li>sdcbkjsnbd</li></ExternalLinks><Images><li>efvdjkjnfv</li></Images><Videos><li>dfvnldkfjvnbo</li></Videos></Common>" root = ET.fromstring(xml_string) temp_com.populate(root) common_xml = temp_com.print_xml() self.assertEqual(xml_string, common_xml)
def test_print_xml1(self): temp_com = Common() xml_string = "<Common><Citations><li>Citation</li></Citations><ExternalLinks><li>Link</li></ExternalLinks><Images><li>Image</li></Images><Videos><li>Video</li></Videos></Common>" root = ET.fromstring(xml_string) temp_com.populate(root) common_xml = temp_com.print_xml() self.assertEqual(xml_string, common_xml)
def test_common_populate1(self): temp_com = Common() xml_string = '<Common><Citations><li>Random Citation</li></Citations><ExternalLinks><li href="http://en.wikipedia.org/wiki/2013_North_India_floods">Wikipedia</li></ExternalLinks><Images><li embed="http://timesofindia.indiatimes.com/photo/15357310.cms" /></Images><Summary>Random Summary</Summary></Common>' root = ET.fromstring(xml_string) temp_com.populate(root) self.assertEqual(temp_com.citations[0].floating_text, "Random Citation") self.assertEqual(temp_com.external_links[0].href, "http://en.wikipedia.org/wiki/2013_North_India_floods") self.assertEqual(temp_com.images[0].embed, "http://timesofindia.indiatimes.com/photo/15357310.cms")
def test_common_populate0(self): temp_com = Common() xml_string = '<Common><Citations><li>The Hindustan Times</li></Citations><ExternalLinks><li href="http://en.wikipedia.org/wiki/2013_North_India_floods">Wikipedia</li></ExternalLinks><Images><li embed="http://timesofindia.indiatimes.com/photo/15357310.cms" /></Images><Videos><li embed="//www.youtube.com/embed/qV3s7Sa6B6w" /></Videos><Maps><li embed="https://www.google.com/maps?sll=30.08236989592049,79.31189246107706&sspn=3.2522150867582833,7.2072687770004205&t=m&q=uttarakhand&dg=opt&ie=UTF8&hq=&hnear=Uttarakhand,+India&ll=30.066753,79.0193&spn=2.77128,5.07019&z=8&output=embed" /></Maps><Feeds><li embed="[WHATEVER A FEED URL LOOKS LIKE]" /></Feeds><Summary>Lorem ipsum...</Summary></Common>' root = ET.fromstring(xml_string) temp_com.populate(root) self.assertEqual(temp_com.citations[0].floating_text, "The Hindustan Times") self.assertEqual(temp_com.external_links[0].href, "http://en.wikipedia.org/wiki/2013_North_India_floods") self.assertEqual(temp_com.images[0].embed, "http://timesofindia.indiatimes.com/photo/15357310.cms") self.assertEqual(temp_com.videos[0].embed, "//www.youtube.com/embed/qV3s7Sa6B6w") #self.assertEqual(temp_com.maps[0].href, "https://www.google.com/maps?sll=30.08236989592049,79.31189246107706&sspn=3.2522150867582833,7.2072687770004205&t=m&q=uttarakhand&dg=opt&ie=UTF8&hq=&hnear=Uttarakhand,+India&ll=30.066753,79.0193&spn=2.77128,5.07019&z=8&output=embed") self.assertEqual(temp_com.feeds[0].embed, "[WHATEVER A FEED URL LOOKS LIKE]") self.assertEqual(temp_com.videos[0].embed, "//www.youtube.com/embed/qV3s7Sa6B6w")
def populate_common(node, modl_id, model_instance): """ Searches through node's tree for a common node and calls common's populate method on it. @type node: Element @param node: a node in the ElementTree passed in to populate_models() @type modl_id: string @param modl_id: the idref of the model the common instance maps to @type model_instance: element @param model_instance: a node in the ElementTree passed in to populate_models() @rtype: N/A @return: function does not return """ found_common = node.find('Common') if found_common is not None: common = Common() common.populate(found_common, modl_id) found_summary = found_common.find("Summary") if found_summary is not None and found_summary is not "": if found_summary.text is not None and found_summary.text is not "": model_instance.common_summary = found_summary.text
def populate_common(node, modl_id, model_instance): """ Searches through node's tree for a common node and calls common's populate method on it. @type node: Element @param node: a node in the ElementTree passed in to populate_models() @type modl_id: string @param modl_id: the idref of the model the common instance maps to @type model_instance: element @param model_instance: a node in the ElementTree passed in to populate_models() @rtype: N/A @return: function does not return """ found_common = node.find('Common') if found_common is not None: common = Common() common.populate(found_common, modl_id) found_summary = found_common.find("Summary") if found_summary is not None and found_summary is not "" : if found_summary.text is not None and found_summary.text is not "" : model_instance.common_summary = found_summary.text
def test_xml_from_li2(self): temp_com = Common() xml_string = "<Common><Citations><li>dvfjnkjdnv</li></Citations><ExternalLinks><li>sdcbkjsnbd</li></ExternalLinks><Images><li>efvdjkjnfv</li></Images><Videos><li>dfvnldkfjvnbo</li></Videos></Common>" root = ET.fromstring(xml_string) temp_com.populate(root) li_xml = "<Common>" c_cites = temp_com.xml_from_li("Citations", temp_com.citations) li_xml += c_cites c_links = temp_com.xml_from_li("ExternalLinks", temp_com.external_links) li_xml += c_links c_ims = temp_com.xml_from_li("Images", temp_com.images) li_xml += c_ims c_vids = temp_com.xml_from_li("Videos", temp_com.videos) li_xml += c_vids li_xml += "</Common>" self.assertEqual(li_xml, xml_string )
def test_xml_from_li1(self): temp_com = Common() xml_string = "<Common><Citations><li>Citation</li></Citations><ExternalLinks><li>Link</li></ExternalLinks><Images><li>Image</li></Images><Videos><li>Video</li></Videos></Common>" root = ET.fromstring(xml_string) temp_com.populate(root) li_xml = "<Common>" c_cites = temp_com.xml_from_li("Citations", temp_com.citations) li_xml += c_cites c_links = temp_com.xml_from_li("ExternalLinks", temp_com.external_links) li_xml += c_links c_ims = temp_com.xml_from_li("Images", temp_com.images) li_xml += c_ims c_vids = temp_com.xml_from_li("Videos", temp_com.videos) li_xml += c_vids li_xml += "</Common>" self.assertEqual(li_xml, xml_string )