{ "cells": [ { "cell_type": "markdown", "id": "3d1fdfd5", "metadata": {}, "source": [ "(operator-basics)=\n", "# Basics\n", "\n", "The [`quimb.operator`](quimb.operator) module provides a unified way of 'symbolically' defining Hamiltonians or operators, including in symmetry sub-sectors, which can then be built into multiple different concrete representations for consumption by either the matrix or tensor network routines in quimb.\n", "\n", "Matrix representations:\n", "\n", "- *Dense matrix*\n", "- *Sparse matrix*\n", "- *Linear operator* (action on a dense vector)\n", "\n", "Tensor network representations:\n", "\n", "- *Matrix product operator (MPO)*\n", "- *Dict of local dense terms* (for PEPS algorithms)\n", "- *Projected entangled pair operator (PEPO)*\n", "\n", "VMC routines:\n", "\n", "- *Coupled configurations*\n", "\n", "There is also support for certain transformations of the terms, such as the [*Jordan-Wigner* transformation](quimb.operator.SparseOperatorBuilder.jordan_wigner_transform) and [pauli decomposition](quimb.operator.SparseOperatorBuilder.pauli_decompose).\n", "\n", "Here we'll illustrate with a 2D Heisenberg model." ] }, { "cell_type": "code", "execution_count": null, "id": "633065b0", "metadata": {}, "outputs": [], "source": [ "%config InlineBackend.figure_formats = ['svg']\n", "import matplotlib as mpl\n", "import matplotlib.pyplot as plt\n", "\n", "import quimb as qu\n", "import quimb.operator as qop\n", "import quimb.tensor as qtn\n", "\n", "mpl.style.use(qu.NEUTRAL_STYLE)" ] }, { "cell_type": "markdown", "id": "ad9cb975", "metadata": {}, "source": [ "## The `HilbertSpace`\n", "\n", "For full control over the sites in our system and how to order them we first explicitly declare a [`HilbertSpace`](quimb.operator.HilbertSpace) object, here for a 2D square lattice." ] }, { "cell_type": "code", "execution_count": 2, "id": "e7680077", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "HilbertSpace(nsites=20, total_size=184_756, symmetry=U1, sector=10)" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Lx = 4\n", "Ly = 5\n", "sites = [(i, j) for i in range(Lx) for j in range(Ly)]\n", "nsites = len(sites)\n", "\n", "# define a default symmetry sector for efficiency\n", "symmetry = \"U1\"\n", "sector = nsites // 2\n", "\n", "hilbert_space = qop.HilbertSpace(\n", " sites=sites,\n", " symmetry=symmetry,\n", " sector=sector,\n", ")\n", "hilbert_space" ] }, { "cell_type": "markdown", "id": "17aa23a5", "metadata": {}, "source": [ "On its own this just has a few helpful tools for enumerating the valid configurations. The terminology used here is:\n", "\n", "- `site`: the labels of the individual sites in the system, these can be arbtirary hashable and sortable objects, e.g. our 2D coordinates above.\n", "- `reg`: in a linear ordering of the sites, the `reg` is the integer index or 'register' of a site. This can be controlled using the `order` argument to the `HilbertSpace` constructor." ] }, { "cell_type": "code", "execution_count": 3, "id": "1fd3f5c4", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "13" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "hilbert_space.site_to_reg((2, 3))" ] }, { "cell_type": "code", "execution_count": 4, "id": "21b42b0b", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(3, 4)" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "hilbert_space.reg_to_site(nsites - 1)" ] }, { "cell_type": "markdown", "id": "d24804f3", "metadata": {}, "source": [ "Individual configurations can be referred to in three ways:\n", "\n", "- `config`: a dict of site to local state.\n", "- `flatconfig`: a `numpy.ndarray[uint8]` of local states in register order.\n", "- `rank`: an integer between 0 and `hilbert_space.size - 1` indexing the configurations in lexicographically sorted order." ] }, { "cell_type": "code", "execution_count": 5, "id": "87f01213", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{(0, 0): np.uint8(0), (0, 1): np.uint8(0), (0, 2): np.uint8(0), (0, 3): np.uint8(0), (0, 4): np.uint8(0), (1, 0): np.uint8(0), (1, 1): np.uint8(0), (1, 2): np.uint8(0), (1, 3): np.uint8(0), (1, 4): np.uint8(0), (2, 0): np.uint8(1), (2, 1): np.uint8(1), (2, 2): np.uint8(1), (2, 3): np.uint8(1), (2, 4): np.uint8(1), (3, 0): np.uint8(1), (3, 1): np.uint8(1), (3, 2): np.uint8(1), (3, 3): np.uint8(1), (3, 4): np.uint8(1)}\n" ] } ], "source": [ "# the first configuration (00..011..1) as a dict:\n", "print(hilbert_space.rank_to_config(0))" ] }, { "cell_type": "code", "execution_count": 6, "id": "93a4a737", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{(0, 0): np.uint8(0), (0, 1): np.uint8(0), (0, 2): np.uint8(0), (0, 3): np.uint8(1), (0, 4): np.uint8(1), (1, 0): np.uint8(1), (1, 1): np.uint8(0), (1, 2): np.uint8(0), (1, 3): np.uint8(1), (1, 4): np.uint8(0), (2, 0): np.uint8(1), (2, 1): np.uint8(1), (2, 2): np.uint8(0), (2, 3): np.uint8(0), (2, 4): np.uint8(0), (3, 0): np.uint8(1), (3, 1): np.uint8(1), (3, 2): np.uint8(1), (3, 3): np.uint8(0), (3, 4): np.uint8(1)}\n" ] } ], "source": [ "# get a random configuration\n", "config = hilbert_space.rand_config(seed=42)\n", "print(config)" ] }, { "cell_type": "code", "execution_count": 7, "id": "91f0effe", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "16489" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# find its rank\n", "hilbert_space.config_to_rank(config)" ] }, { "cell_type": "code", "execution_count": 8, "id": "e33967d0", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n", " dtype=uint8)" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# the last configuration (11..100..0) as a flat vector\n", "hilbert_space.rank_to_flatconfig(hilbert_space.size - 1)" ] }, { "cell_type": "markdown", "id": "f831873a", "metadata": {}, "source": [ "## The `SparseOperatorBuilder`\n", "\n", "Now we can 'symbolically' define operators for this Hilbert space using the [`SparseOperatorBuilder`](quimb.operator.SparseOperatorBuilder) object. Here we'll define a 2D Heisenberg Hamiltonian:" ] }, { "cell_type": "code", "execution_count": 9, "id": "91a7ff5e", "metadata": {}, "outputs": [], "source": [ "H = qop.SparseOperatorBuilder(hilbert_space=hilbert_space)\n", "\n", "# add nearest neighbor Heisenberg interactions\n", "for i in range(Lx):\n", " for j in range(Ly):\n", " if i < Lx - 1:\n", " H += 0.5, (\"+\", (i, j)), (\"-\", (i + 1, j))\n", " H += 0.5, (\"-\", (i, j)), (\"+\", (i + 1, j))\n", " H += 1.0, (\"z\", (i, j)), (\"z\", (i + 1, j))\n", " if j < Ly - 1:\n", " H += 0.5, (\"+\", (i, j)), (\"-\", (i, j + 1))\n", " H += 0.5, (\"-\", (i, j)), (\"+\", (i, j + 1))\n", " H += 1.0, (\"z\", (i, j)), (\"z\", (i, j + 1))\n", "\n", "# and a single site magnetic field to break symmetry\n", "H += -0.1, (\"z\", (0, 0))" ] }, { "cell_type": "markdown", "id": "72c86afd", "metadata": {}, "source": [ "```{note}\n", "If you don't supply a `HilbertSpace` then the operator builder will build the default one for the minimal set of sites in has seen so far.\n", "```\n", "\n", "We can see all the terms visually with the `show` method (again the ordering is given by the register order):" ] }, { "cell_type": "code", "execution_count": 10, "id": "de1a90f5", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "SparseOperatorBuilder(nsites=20, nterms=94, locality=2)\n", "+ . . . . - . . . . . . . . . . . . . . +0.5\n", "- . . . . + . . . . . . . . . . . . . . +0.5\n", "z . . . . z . . . . . . . . . . . . . . +1.0\n", "+ - . . . . . . . . . . . . . . . . . . +0.5\n", "- + . . . . . . . . . . . . . . . . . . +0.5\n", "z z . . . . . . . . . . . . . . . . . . +1.0\n", ". + . . . . - . . . . . . . . . . . . . +0.5\n", ". - . . . . + . . . . . . . . . . . . . +0.5\n", ". z . . . . z . . . . . . . . . . . . . +1.0\n", ". + - . . . . . . . . . . . . . . . . . +0.5\n", ". - + . . . . . . . . . . . . . . . . . +0.5\n", ". z z . . . . . . . . . . . . . . . . . +1.0\n", ". . + . . . . - . . . . . . . . . . . . +0.5\n", ". . - . . . . + . . . . . . . . . . . . +0.5\n", ". . z . . . . z . . . . . . . . . . . . +1.0\n", ". . + - . . . . . . . . . . . . . . . . +0.5\n", ". . - + . . . . . . . . . . . . . . . . +0.5\n", ". . z z . . . . . . . . . . . . . . . . +1.0\n", ". . . + . . . . - . . . . . . . . . . . +0.5\n", ". . . - . . . . + . . . . . . . . . . . +0.5\n", ". . . z . . . . z . . . . . . . . . . . +1.0\n", ". . . + - . . . . . . . . . . . . . . . +0.5\n", ". . . - + . . . . . . . . . . . . . . . +0.5\n", ". . . z z . . . . . . . . . . . . . . . +1.0\n", ". . . . + . . . . - . . . . . . . . . . +0.5\n", ". . . . - . . . . + . . . . . . . . . . +0.5\n", ". . . . z . . . . z . . . . . . . . . . +1.0\n", ". . . . . + . . . . - . . . . . . . . . +0.5\n", ". . . . . - . . . . + . . . . . . . . . +0.5\n", ". . . . . z . . . . z . . . . . . . . . +1.0\n", ". . . . . + - . . . . . . . . . . . . . +0.5\n", ". . . . . - + . . . . . . . . . . . . . +0.5\n", ". . . . . z z . . . . . . . . . . . . . +1.0\n", ". . . . . . + . . . . - . . . . . . . . +0.5\n", ". . . . . . - . . . . + . . . . . . . . +0.5\n", ". . . . . . z . . . . z . . . . . . . . +1.0\n", ". . . . . . + - . . . . . . . . . . . . +0.5\n", ". . . . . . - + . . . . . . . . . . . . +0.5\n", ". . . . . . z z . . . . . . . . . . . . +1.0\n", ". . . . . . . + . . . . - . . . . . . . +0.5\n", ". . . . . . . - . . . . + . . . . . . . +0.5\n", ". . . . . . . z . . . . z . . . . . . . +1.0\n", ". . . . . . . + - . . . . . . . . . . . +0.5\n", ". . . . . . . - + . . . . . . . . . . . +0.5\n", ". . . . . . . z z . . . . . . . . . . . +1.0\n", ". . . . . . . . + . . . . - . . . . . . +0.5\n", ". . . . . . . . - . . . . + . . . . . . +0.5\n", ". . . . . . . . z . . . . z . . . . . . +1.0\n", ". . . . . . . . + - . . . . . . . . . . +0.5\n", ". . . . . . . . - + . . . . . . . . . . +0.5\n", ". . . . . . . . z z . . . . . . . . . . +1.0\n", ". . . . . . . . . + . . . . - . . . . . +0.5\n", ". . . . . . . . . - . . . . + . . . . . +0.5\n", ". . . . . . . . . z . . . . z . . . . . +1.0\n", ". . . . . . . . . . + . . . . - . . . . +0.5\n", ". . . . . . . . . . - . . . . + . . . . +0.5\n", ". . . . . . . . . . z . . . . z . . . . +1.0\n", ". . . . . . . . . . + - . . . . . . . . +0.5\n", ". . . . . . . . . . - + . . . . . . . . +0.5\n", ". . . . . . . . . . z z . . . . . . . . +1.0\n", ". . . . . . . . . . . + . . . . - . . . +0.5\n", ". . . . . . . . . . . - . . . . + . . . +0.5\n", ". . . . . . . . . . . z . . . . z . . . +1.0\n", ". . . . . . . . . . . + - . . . . . . . +0.5\n", ". . . . . . . . . . . - + . . . . . . . +0.5\n", ". . . . . . . . . . . z z . . . . . . . +1.0\n", ". . . . . . . . . . . . + . . . . - . . +0.5\n", ". . . . . . . . . . . . - . . . . + . . +0.5\n", ". . . . . . . . . . . . z . . . . z . . +1.0\n", ". . . . . . . . . . . . + - . . . . . . +0.5\n", ". . . . . . . . . . . . - + . . . . . . +0.5\n", ". . . . . . . . . . . . z z . . . . . . +1.0\n", ". . . . . . . . . . . . . + . . . . - . +0.5\n", ". . . . . . . . . . . . . - . . . . + . +0.5\n", ". . . . . . . . . . . . . z . . . . z . +1.0\n", ". . . . . . . . . . . . . + - . . . . . +0.5\n", ". . . . . . . . . . . . . - + . . . . . +0.5\n", ". . . . . . . . . . . . . z z . . . . . +1.0\n", ". . . . . . . . . . . . . . + . . . . - +0.5\n", ". . . . . . . . . . . . . . - . . . . + +0.5\n", ". . . . . . . . . . . . . . z . . . . z +1.0\n", ". . . . . . . . . . . . . . . + - . . . +0.5\n", ". . . . . . . . . . . . . . . - + . . . +0.5\n", ". . . . . . . . . . . . . . . z z . . . +1.0\n", ". . . . . . . . . . . . . . . . + - . . +0.5\n", ". . . . . . . . . . . . . . . . - + . . +0.5\n", ". . . . . . . . . . . . . . . . z z . . +1.0\n", ". . . . . . . . . . . . . . . . . + - . +0.5\n", ". . . . . . . . . . . . . . . . . - + . +0.5\n", ". . . . . . . . . . . . . . . . . z z . +1.0\n", ". . . . . . . . . . . . . . . . . . + - +0.5\n", ". . . . . . . . . . . . . . . . . . - + +0.5\n", ". . . . . . . . . . . . . . . . . . z z +1.0\n", "z . . . . . . . . . . . . . . . . . . . -0.1\n" ] } ], "source": [ "H.show()" ] }, { "cell_type": "markdown", "id": "69225d21", "metadata": {}, "source": [ "Currently the supported local operators are:\n", "```python\n", "{\n", " \"I\": {0: (0, 1.0), 1: (1, 1.0)},\n", " # pauli matrices\n", " \"x\": {0: (1, 1.0), 1: (0, 1.0)},\n", " \"y\": {0: (1, 1.0j), 1: (0, -1.0j)},\n", " \"z\": {0: (0, 1.0), 1: (1, -1.0)},\n", " # ZX=iY: 'real Y'\n", " \"⧖\": {0: (1, -1.0), 1: (0, 1.0)},\n", " # spin 1/2 matrices (scaled paulis)\n", " \"sx\": {0: (1, 0.5), 1: (0, 0.5)},\n", " \"sy\": {0: (1, 0.5j), 1: (0, -0.5j)},\n", " \"sz\": {0: (0, 0.5), 1: (1, -0.5)},\n", " # creation / annihilation operators\n", " \"+\": {0: (1, 1.0)},\n", " \"-\": {1: (0, 1.0)},\n", " # number, symmetric number, and hole operators\n", " \"n\": {1: (1, 1.0)},\n", " \"sn\": {0: (0, -0.5), 1: (1, 0.5)},\n", " \"h\": {0: (0, 1.0)},\n", "}\n", "```\n", "\n", "### Building matrices\n", "\n", "Now we can build out concrete realizations of the operator. For example the sparse matrix representation:\n", "\n", "```{hint}\n", "By default this will pick up the default `sector` and `symmetry` from the hilbert space object, or you can explicitly override it here.\n", "```" ] }, { "cell_type": "code", "execution_count": 11, "id": "e479c67f", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "CPU times: user 992 ms, sys: 180 ms, total: 1.17 s\n", "Wall time: 1.18 s\n" ] }, { "data": { "text/plain": [ "" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "%%time\n", "H_sparse = H.build_sparse_matrix()\n", "H_sparse" ] }, { "cell_type": "markdown", "id": "0531fd27", "metadata": {}, "source": [ "This allows us to find the full exact groundstate and energy:" ] }, { "cell_type": "code", "execution_count": 12, "id": "c089e9f5", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "CPU times: user 5.01 s, sys: 82.5 ms, total: 5.09 s\n", "Wall time: 694 ms\n" ] } ], "source": [ "%%time\n", "energy, psi = qu.eigh(H_sparse, k=1)" ] }, { "cell_type": "code", "execution_count": 13, "id": "548e9b17", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([-32.01392954])" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "energy" ] }, { "cell_type": "markdown", "id": "d27a50da", "metadata": {}, "source": [ "Now we can define some other operators that act on the same hilbert space, and measure their expectation, here the Z magnetization acting on every site:" ] }, { "cell_type": "code", "execution_count": 14, "id": "129284b7", "metadata": {}, "outputs": [], "source": [ "zijs = [[None for j in range(Ly)] for i in range(Lx)]\n", "\n", "for i in range(Lx):\n", " for j in range(Ly):\n", " zop_ij = qop.SparseOperatorBuilder(\n", " # we can supply all the terms at construction\n", " terms=[(1.0, (\"z\", (i, j)))],\n", " # because we only act on 1 site of many, we do\n", " # need to explicitly provide the hilbert space\n", " hilbert_space=hilbert_space,\n", " )\n", "\n", " # build the sparse matrix\n", " zsparse_ij = zop_ij.build_sparse_matrix()\n", "\n", " # evaluate \n", " zijs[i][j] = qu.expec(psi, zsparse_ij)" ] }, { "cell_type": "code", "execution_count": 15, "id": "1744f587", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" }, { "data": { "image/svg+xml": [ "" ], "text/plain": [ "
" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" } ], "source": [ "plt.imshow(zijs)" ] }, { "cell_type": "markdown", "id": "cc3dc240", "metadata": {}, "source": [ "If this was a smaller space we could also build the full dense matrix with\n", "[`build_dense_matrix`](quimb.operator.SparseOperatorBuilder.build_dense_matrix).\n", "\n", "The [`SparseOperatorBuilder`](quimb.operator.SparseOperatorBuilder) also has a\n", "[`matvec`](quimb.operator.SparseOperatorBuilder.matvec) method which computes the action on a dense vector without forming the explicit matrix. You can use this directly or call [`.aslinearoperator`](quimb.operator.SparseOperatorBuilder.aslinearoperator) to get a [`scipy.sparse.linalg.LinearOperator`](scipy.sparse.linalg.LinearOperator) object which can be used with [`scipy.sparse.linalg`](scipy.sparse.linalg) routines.\n", "\n", "```{warning}\n", "This is not a very efficient implementation yet, you may want to consider for example [`quspin`](https://quspin.github.io/QuSpin/) if performance is critical.\n", "```\n", "\n", "### Building tensor network representations\n", "\n", "#### Building MPOs for MPS algorithms\n", "\n", "We can also build out concrete representations of the operator for consumption by various tensor network algorithms in [`quimb.tensor`](quimb.tensor).\n", "\n", "For example as a matrix product operator (MPO) using [`build_mpo`](quimb.operator.SparseOperatorBuilder.build_mpo):" ] }, { "cell_type": "code", "execution_count": 16, "id": "5d26ba8a", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
MatrixProductOperator(tensors=20, indices=59, L=20, max_bond=17)
Tensor(shape=(4, 2, 2), inds=[_23d24bAAAAB, k0, b0], tags={I0}),backend=numpy, dtype=float64, data=array([[[ 0., 0.],\n", " [ 1., 0.]],\n", "\n", " [[ 0., 1.],\n", " [ 0., 0.]],\n", "\n", " [[ 1., 0.],\n", " [ 0., -1.]],\n", "\n", " [[ 1., 0.],\n", " [ 0., 1.]]])
Tensor(shape=(4, 8, 2, 2), inds=[_23d24bAAAAB, _23d24bAAAAC, k1, b1], tags={I1}),backend=numpy, dtype=float64, data=...
Tensor(shape=(8, 11, 2, 2), inds=[_23d24bAAAAC, _23d24bAAAAD, k2, b2], tags={I2}),backend=numpy, dtype=float64, data=...
Tensor(shape=(11, 14, 2, 2), inds=[_23d24bAAAAD, _23d24bAAAAE, k3, b3], tags={I3}),backend=numpy, dtype=float64, data=...
Tensor(shape=(14, 17, 2, 2), inds=[_23d24bAAAAE, _23d24bAAAAF, k4, b4], tags={I4}),backend=numpy, dtype=float64, data=...
Tensor(shape=(17, 17, 2, 2), inds=[_23d24bAAAAF, _23d24bAAAAG, k5, b5], tags={I5}),backend=numpy, dtype=float64, data=...
Tensor(shape=(17, 17, 2, 2), inds=[_23d24bAAAAG, _23d24bAAAAH, k6, b6], tags={I6}),backend=numpy, dtype=float64, data=...
Tensor(shape=(17, 17, 2, 2), inds=[_23d24bAAAAH, _23d24bAAAAI, k7, b7], tags={I7}),backend=numpy, dtype=float64, data=...
Tensor(shape=(17, 17, 2, 2), inds=[_23d24bAAAAI, _23d24bAAAAJ, k8, b8], tags={I8}),backend=numpy, dtype=float64, data=...
Tensor(shape=(17, 17, 2, 2), inds=[_23d24bAAAAJ, _23d24bAAAAK, k9, b9], tags={I9}),backend=numpy, dtype=float64, data=...
Tensor(shape=(17, 17, 2, 2), inds=[_23d24bAAAAK, _23d24bAAAAL, k10, b10], tags={I10}),backend=numpy, dtype=float64, data=...
Tensor(shape=(17, 17, 2, 2), inds=[_23d24bAAAAL, _23d24bAAAAM, k11, b11], tags={I11}),backend=numpy, dtype=float64, data=...
Tensor(shape=(17, 17, 2, 2), inds=[_23d24bAAAAM, _23d24bAAAAN, k12, b12], tags={I12}),backend=numpy, dtype=float64, data=...
Tensor(shape=(17, 17, 2, 2), inds=[_23d24bAAAAN, _23d24bAAAAO, k13, b13], tags={I13}),backend=numpy, dtype=float64, data=...
Tensor(shape=(17, 17, 2, 2), inds=[_23d24bAAAAO, _23d24bAAAAP, k14, b14], tags={I14}),backend=numpy, dtype=float64, data=...
Tensor(shape=(17, 14, 2, 2), inds=[_23d24bAAAAP, _23d24bAAAAQ, k15, b15], tags={I15}),backend=numpy, dtype=float64, data=...
Tensor(shape=(14, 11, 2, 2), inds=[_23d24bAAAAQ, _23d24bAAAAR, k16, b16], tags={I16}),backend=numpy, dtype=float64, data=...
Tensor(shape=(11, 8, 2, 2), inds=[_23d24bAAAAR, _23d24bAAAAS, k17, b17], tags={I17}),backend=numpy, dtype=float64, data=...
Tensor(shape=(8, 4, 2, 2), inds=[_23d24bAAAAS, _23d24bAAAAT, k18, b18], tags={I18}),backend=numpy, dtype=float64, data=...
Tensor(shape=(4, 2, 2), inds=[_23d24bAAAAT, k19, b19], tags={I19}),backend=numpy, dtype=float64, data=array([[[ 1., 0.],\n", " [ 0., 1.]],\n", "\n", " [[ 0., 1.],\n", " [ 0., 0.]],\n", "\n", " [[ 0., 0.],\n", " [ 1., 0.]],\n", "\n", " [[ 1., 0.],\n", " [ 0., -1.]]])
" ], "text/plain": [ "MatrixProductOperator(tensors=20, indices=59, L=20, max_bond=17)" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "H_mpo = H.build_mpo()\n", "H_mpo" ] }, { "cell_type": "markdown", "id": "af90e809", "metadata": {}, "source": [ "The algorithm to build the MPO is a greedy algorithm that works well for local Hamiltonians, but will not be optimal for complicated long range models. You can check the underyling finite state machine representatino with [`draw_state_machine`](quimb.operator.SparseOperatorBuilder.draw_state_machine):" ] }, { "cell_type": "code", "execution_count": 17, "id": "e39f002b", "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "" ], "text/plain": [ "
" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" } ], "source": [ "H.draw_state_machine()" ] }, { "cell_type": "markdown", "id": "69108cf9", "metadata": {}, "source": [ "We can use the MPO to find the groundstate with [`DMRG`](quimb.tensor.tn1d.dmrg.DMRG):" ] }, { "cell_type": "code", "execution_count": 18, "id": "90ba887c", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1, R, max_bond=(8/8), cutoff:1e-08\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "100%|##########################################| 19/19 [00:00<00:00, 306.08it/s]" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Energy: -31.656832428772546 ... not converged.\n", "2, R, max_bond=(8/16), cutoff:1e-08\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "\n", "100%|##########################################| 19/19 [00:00<00:00, 362.23it/s]" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Energy: -31.813407135272556 ... not converged.\n", "3, R, max_bond=(16/32), cutoff:1e-08\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "\n", "100%|##########################################| 19/19 [00:00<00:00, 279.30it/s]" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Energy: -31.818448856710024 ... not converged.\n", "4, R, max_bond=(29/64), cutoff:1e-08\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "\n", "100%|##########################################| 19/19 [00:00<00:00, 192.93it/s]" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Energy: -31.81932769634487 ... not converged.\n", "5, R, max_bond=(39/128), cutoff:1e-08\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "\n", "100%|##########################################| 19/19 [00:00<00:00, 152.65it/s]" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Energy: -31.81949636476171 ... not converged.\n", "6, R, max_bond=(42/256), cutoff:1e-08\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "\n", "100%|##########################################| 19/19 [00:00<00:00, 210.71it/s]" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Energy: -31.819509858329468 ... converged!\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "\n" ] }, { "data": { "text/plain": [ "np.True_" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dmrg = qtn.DMRG2(H_mpo)\n", "dmrg.solve(verbosity=1)" ] }, { "cell_type": "markdown", "id": "5876a193", "metadata": {}, "source": [ "Then we can check the relative error in the groundstate energy:" ] }, { "cell_type": "code", "execution_count": 19, "id": "963d2dc6", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "np.float64(0.006072971495561852)" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1 - dmrg.energy / energy.item()" ] }, { "cell_type": "markdown", "id": "5bab5a3e", "metadata": {}, "source": [ "#### Building local terms for PEPS\n", "\n", "For projected entangled pair states (PEPS) algorithms we often need the local terms of the Hamiltonian as dense matrices. We can build these with [`build_local_ham`](quimb.operator.SparseOperatorBuilder.build_local_ham):" ] }, { "cell_type": "code", "execution_count": 20, "id": "a69e2370", "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "" ], "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "(
, )" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "H_local = H.build_local_ham()\n", "H_local.draw()" ] }, { "cell_type": "markdown", "id": "31439a8f", "metadata": {}, "source": [ "We can then feed this into algorithms such as [`simple update`](quimb.tensor.tnag.tebd.SimpleUpdateGen):" ] }, { "cell_type": "code", "execution_count": 21, "id": "96952e00", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "n=100, D=4, tau=0.1, energy≈-31.9678: 100%|##########| 100/100 [00:02<00:00, 35.70it/s]\n" ] } ], "source": [ "peps = qtn.PEPS.rand(Lx, Ly, 4, seed=42)\n", "su = qtn.SimpleUpdate(peps, H_local)\n", "su.evolve(100, tau=0.1)" ] }, { "cell_type": "code", "execution_count": 22, "id": "24b9e53c", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.0014423055073261581" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1 - su.energy / energy.item()" ] }, { "cell_type": "markdown", "id": "121566f2", "metadata": {}, "source": [ "### Monte carlo usage" ] }, { "cell_type": "markdown", "id": "85f30db1", "metadata": {}, "source": [ "For variational monte carlo (VMC) or other monte carlo routines one needs to the compute the 'local energy'. This is encapsulated in the [`config_coupling`](quimb.operator.SparseOperatorBuilder.config_coupling) and [`flatconfig_coupling`](quimb.operator.SparseOperatorBuilder.flatconfig_coupling) methods. These return a tuple with A) the coupled configurations and B) the corresponding coefficients.\n", "\n", "Mathematically, for a given configuration $| x \\rangle$, this returns the non-zero coupled configurations: $\\{| y \\rangle\\} $, as well as the coefficients $\\{ \\langle x | H | y \\rangle \\}$ such that the 'local energy' is given by:\n", "\n", "$$\n", "E_{\\text{loc}}(x) = \\sum_j \\dfrac{ \\langle x | H | y \\rangle \\langle y | \\psi \\rangle } { \\langle x | \\psi \\rangle }\n", "$$" ] }, { "cell_type": "code", "execution_count": 23, "id": "04e72917", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1],\n", " dtype=uint8)" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "flatconfig = hilbert_space.rand_flatconfig(seed=42)\n", "flatconfig" ] }, { "cell_type": "code", "execution_count": 24, "id": "f74fff2d", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(array([[1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1],\n", " [0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1],\n", " [0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1],\n", " [0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1],\n", " [0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1],\n", " [0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1],\n", " [0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1],\n", " [0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1],\n", " [0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1],\n", " [0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1],\n", " [0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1],\n", " [0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0],\n", " [0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1],\n", " [0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0]],\n", " dtype=uint8),\n", " array([0.5, 4.9, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,\n", " 0.5]))" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "coupled_flatconfigs, coupled_coeffs = H.flatconfig_coupling(flatconfig)\n", "coupled_flatconfigs, coupled_coeffs" ] }, { "cell_type": "code", "execution_count": 25, "id": "be825435", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" }, { "data": { "image/svg+xml": [ "" ], "text/plain": [ "
" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" } ], "source": [ "plt.imshow(coupled_flatconfigs)" ] }, { "cell_type": "markdown", "id": "e3512021", "metadata": {}, "source": [ "### Transforming operators\n", "\n", "The [`SparseOperatorBuilder`](quimb.operator.SparseOperatorBuilder) also has some methods for transforming the terms.\n", "\n", "#### Jordan-Wigner transformation\n", "\n", "For example the [*Jordan-Wigner* transformation](quimb.operator.SparseOperatorBuilder.jordan_wigner_transform) which maps spin-1/2 operators to fermionic ones:" ] }, { "cell_type": "code", "execution_count": 26, "id": "bb1e5075", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "HilbertSpace(nsites=24, total_size=853_776, symmetry=U1U1, sector=((12, 6), (12, 6)))" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Lx = 4\n", "Ly = 3\n", "sites = [(s, i, j) for s in (\"u\", \"d\") for i in range(Lx) for j in range(Ly)]\n", "nsites = len(sites)\n", "\n", "# define half filling in each species\n", "symmetry = \"U1U1\"\n", "sector = (nsites // 2, nsites // 4), (nsites // 2, nsites // 4)\n", "\n", "hilbert_space = qop.HilbertSpace(\n", " sites=sites,\n", " symmetry=symmetry,\n", " sector=sector,\n", ")\n", "hilbert_space" ] }, { "cell_type": "code", "execution_count": 27, "id": "ba9afbdf", "metadata": {}, "outputs": [], "source": [ "H = qop.SparseOperatorBuilder(hilbert_space=hilbert_space)\n", "\n", "t = 1.0\n", "U = 8.0\n", "\n", "# add nearest neighbor Heisenberg interactions\n", "for i in range(Lx):\n", " for j in range(Ly):\n", " for s in (\"u\", \"d\"):\n", " # hopping\n", " if i < Lx - 1:\n", " # the relative ordering within the term now matters too\n", " H.add_term(-t, (\"+\", (s, i, j)), (\"-\", (s, i + 1, j)))\n", " H.add_term(-t, (\"+\", (s, i + 1, j)), (\"-\", (s, i, j)))\n", " if j < Ly - 1:\n", " H.add_term(-t, (\"+\", (s, i, j)), (\"-\", (s, i, j + 1)))\n", " H.add_term(-t, (\"+\", (s, i, j + 1)), (\"-\", (s, i, j)))\n", "\n", " # interaction\n", " H.add_term(U, (\"n\", (\"u\", i, j)), (\"n\", (\"d\", i, j)))" ] }, { "cell_type": "markdown", "id": "9029ce5c", "metadata": {}, "source": [ "```{note}\n", "You can either call the method\n", "[`jordan_wigner_transform`](quimb.operator.SparseOperatorBuilder.jordan_wigner_transform)\n", "to toggle the transformation, or supply `jordan_wigner=True` to the\n", "[`SparseOperatorBuilder`](quimb.operator.SparseOperatorBuilder) constructor.\n", "```" ] }, { "cell_type": "code", "execution_count": 28, "id": "81b674c6", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "SparseOperatorBuilder(nsites=24, nterms=80, locality=4, jordan_wigner=True)\n", "+ z z - . . . . . . . . . . . . . . . . . . . . -1.0\n", "- z z + . . . . . . . . . . . . . . . . . . . . -1.0\n", "+ - . . . . . . . . . . . . . . . . . . . . . . -1.0\n", "- + . . . . . . . . . . . . . . . . . . . . . . -1.0\n", ". . . . . . . . . . . . + z z - . . . . . . . . -1.0\n", ". . . . . . . . . . . . - z z + . . . . . . . . -1.0\n", ". . . . . . . . . . . . + - . . . . . . . . . . -1.0\n", ". . . . . . . . . . . . - + . . . . . . . . . . -1.0\n", "n . . . . . . . . . . . n . . . . . . . . . . . +8.0\n", ". + z z - . . . . . . . . . . . . . . . . . . . -1.0\n", ". - z z + . . . . . . . . . . . . . . . . . . . -1.0\n", ". + - . . . . . . . . . . . . . . . . . . . . . -1.0\n", ". - + . . . . . . . . . . . . . . . . . . . . . -1.0\n", ". . . . . . . . . . . . . + z z - . . . . . . . -1.0\n", ". . . . . . . . . . . . . - z z + . . . . . . . -1.0\n", ". . . . . . . . . . . . . + - . . . . . . . . . -1.0\n", ". . . . . . . . . . . . . - + . . . . . . . . . -1.0\n", ". n . . . . . . . . . . . n . . . . . . . . . . +8.0\n", ". . + z z - . . . . . . . . . . . . . . . . . . -1.0\n", ". . - z z + . . . . . . . . . . . . . . . . . . -1.0\n", ". . . . . . . . . . . . . . + z z - . . . . . . -1.0\n", ". . . . . . . . . . . . . . - z z + . . . . . . -1.0\n", ". . n . . . . . . . . . . . n . . . . . . . . . +8.0\n", ". . . + z z - . . . . . . . . . . . . . . . . . -1.0\n", ". . . - z z + . . . . . . . . . . . . . . . . . -1.0\n", ". . . + - . . . . . . . . . . . . . . . . . . . -1.0\n", ". . . - + . . . . . . . . . . . . . . . . . . . -1.0\n", ". . . . . . . . . . . . . . . + z z - . . . . . -1.0\n", ". . . . . . . . . . . . . . . - z z + . . . . . -1.0\n", ". . . . . . . . . . . . . . . + - . . . . . . . -1.0\n", ". . . . . . . . . . . . . . . - + . . . . . . . -1.0\n", ". . . n . . . . . . . . . . . n . . . . . . . . +8.0\n", ". . . . + z z - . . . . . . . . . . . . . . . . -1.0\n", ". . . . - z z + . . . . . . . . . . . . . . . . -1.0\n", ". . . . + - . . . . . . . . . . . . . . . . . . -1.0\n", ". . . . - + . . . . . . . . . . . . . . . . . . -1.0\n", ". . . . . . . . . . . . . . . . + z z - . . . . -1.0\n", ". . . . . . . . . . . . . . . . - z z + . . . . -1.0\n", ". . . . . . . . . . . . . . . . + - . . . . . . -1.0\n", ". . . . . . . . . . . . . . . . - + . . . . . . -1.0\n", ". . . . n . . . . . . . . . . . n . . . . . . . +8.0\n", ". . . . . + z z - . . . . . . . . . . . . . . . -1.0\n", ". . . . . - z z + . . . . . . . . . . . . . . . -1.0\n", ". . . . . . . . . . . . . . . . . + z z - . . . -1.0\n", ". . . . . . . . . . . . . . . . . - z z + . . . -1.0\n", ". . . . . n . . . . . . . . . . . n . . . . . . +8.0\n", ". . . . . . + z z - . . . . . . . . . . . . . . -1.0\n", ". . . . . . - z z + . . . . . . . . . . . . . . -1.0\n", ". . . . . . + - . . . . . . . . . . . . . . . . -1.0\n", ". . . . . . - + . . . . . . . . . . . . . . . . -1.0\n", ". . . . . . . . . . . . . . . . . . + z z - . . -1.0\n", ". . . . . . . . . . . . . . . . . . - z z + . . -1.0\n", ". . . . . . . . . . . . . . . . . . + - . . . . -1.0\n", ". . . . . . . . . . . . . . . . . . - + . . . . -1.0\n", ". . . . . . n . . . . . . . . . . . n . . . . . +8.0\n", ". . . . . . . + z z - . . . . . . . . . . . . . -1.0\n", ". . . . . . . - z z + . . . . . . . . . . . . . -1.0\n", ". . . . . . . + - . . . . . . . . . . . . . . . -1.0\n", ". . . . . . . - + . . . . . . . . . . . . . . . -1.0\n", ". . . . . . . . . . . . . . . . . . . + z z - . -1.0\n", ". . . . . . . . . . . . . . . . . . . - z z + . -1.0\n", ". . . . . . . . . . . . . . . . . . . + - . . . -1.0\n", ". . . . . . . . . . . . . . . . . . . - + . . . -1.0\n", ". . . . . . . n . . . . . . . . . . . n . . . . +8.0\n", ". . . . . . . . + z z - . . . . . . . . . . . . -1.0\n", ". . . . . . . . - z z + . . . . . . . . . . . . -1.0\n", ". . . . . . . . . . . . . . . . . . . . + z z - -1.0\n", ". . . . . . . . . . . . . . . . . . . . - z z + -1.0\n", ". . . . . . . . n . . . . . . . . . . . n . . . +8.0\n", ". . . . . . . . . + - . . . . . . . . . . . . . -1.0\n", ". . . . . . . . . - + . . . . . . . . . . . . . -1.0\n", ". . . . . . . . . . . . . . . . . . . . . + - . -1.0\n", ". . . . . . . . . . . . . . . . . . . . . - + . -1.0\n", ". . . . . . . . . n . . . . . . . . . . . n . . +8.0\n", ". . . . . . . . . . + - . . . . . . . . . . . . -1.0\n", ". . . . . . . . . . - + . . . . . . . . . . . . -1.0\n", ". . . . . . . . . . . . . . . . . . . . . . + - -1.0\n", ". . . . . . . . . . . . . . . . . . . . . . - + -1.0\n", ". . . . . . . . . . n . . . . . . . . . . . n . +8.0\n", ". . . . . . . . . . . n . . . . . . . . . . . n +8.0\n" ] } ], "source": [ "H.jordan_wigner_transform()\n", "H.show()" ] }, { "cell_type": "code", "execution_count": 29, "id": "25508d06", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "H_sparse = H.build_sparse_matrix()\n", "H_sparse" ] }, { "cell_type": "code", "execution_count": 30, "id": "f07317fd", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([-0.40943827])" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "energy, psi = qu.eigh(H_sparse, k=1)\n", "energy / (Lx * Ly)" ] }, { "cell_type": "markdown", "id": "d81a5951", "metadata": {}, "source": [ "#### Pauli Decomposition\n", "\n", "You can also decompose an operator into strings of Pauli operators using the\n", "[`pauli_decompose`](quimb.operator.SparseOperatorBuilder.pauli_decompose) method,\n", "or by supplying `pauli_decompose=True` to the\n", "[`SparseOperatorBuilder`](quimb.operator.SparseOperatorBuilder) constructor.\n", "The `use_zx` argument enables decomposing Y operators into the real combination of\n", "Z and X (i.e. ⴵ = ZX = iY) to avoid complex coefficients:" ] }, { "cell_type": "code", "execution_count": 31, "id": "7e18b8de", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "SparseOperatorBuilder(nsites=24, nterms=105, locality=4, jordan_wigner=True, pauli_decompose=zx)\n", "x z z x . . . . . . . . . . . . . . . . . . . . -0.5\n", "ⴵ z z ⴵ . . . . . . . . . . . . . . . . . . . . +0.5\n", "x x . . . . . . . . . . . . . . . . . . . . . . -0.5\n", "ⴵ ⴵ . . . . . . . . . . . . . . . . . . . . . . +0.5\n", ". . . . . . . . . . . . x z z x . . . . . . . . -0.5\n", ". . . . . . . . . . . . ⴵ z z ⴵ . . . . . . . . +0.5\n", ". . . . . . . . . . . . x x . . . . . . . . . . -0.5\n", ". . . . . . . . . . . . ⴵ ⴵ . . . . . . . . . . +0.5\n", "z . . . . . . . . . . . . . . . . . . . . . . . -2.0\n", ". . . . . . . . . . . . z . . . . . . . . . . . -2.0\n", "z . . . . . . . . . . . z . . . . . . . . . . . +2.0\n", ". x z z x . . . . . . . . . . . . . . . . . . . -0.5\n", ". ⴵ z z ⴵ . . . . . . . . . . . . . . . . . . . +0.5\n", ". x x . . . . . . . . . . . . . . . . . . . . . -0.5\n", ". ⴵ ⴵ . . . . . . . . . . . . . . . . . . . . . +0.5\n", ". . . . . . . . . . . . . x z z x . . . . . . . -0.5\n", ". . . . . . . . . . . . . ⴵ z z ⴵ . . . . . . . +0.5\n", ". . . . . . . . . . . . . x x . . . . . . . . . -0.5\n", ". . . . . . . . . . . . . ⴵ ⴵ . . . . . . . . . +0.5\n", ". z . . . . . . . . . . . . . . . . . . . . . . -2.0\n", ". . . . . . . . . . . . . z . . . . . . . . . . -2.0\n", ". z . . . . . . . . . . . z . . . . . . . . . . +2.0\n", ". . x z z x . . . . . . . . . . . . . . . . . . -0.5\n", ". . ⴵ z z ⴵ . . . . . . . . . . . . . . . . . . +0.5\n", ". . . . . . . . . . . . . . x z z x . . . . . . -0.5\n", ". . . . . . . . . . . . . . ⴵ z z ⴵ . . . . . . +0.5\n", ". . z . . . . . . . . . . . . . . . . . . . . . -2.0\n", ". . . . . . . . . . . . . . z . . . . . . . . . -2.0\n", ". . z . . . . . . . . . . . z . . . . . . . . . +2.0\n", ". . . x z z x . . . . . . . . . . . . . . . . . -0.5\n", ". . . ⴵ z z ⴵ . . . . . . . . . . . . . . . . . +0.5\n", ". . . x x . . . . . . . . . . . . . . . . . . . -0.5\n", ". . . ⴵ ⴵ . . . . . . . . . . . . . . . . . . . +0.5\n", ". . . . . . . . . . . . . . . x z z x . . . . . -0.5\n", ". . . . . . . . . . . . . . . ⴵ z z ⴵ . . . . . +0.5\n", ". . . . . . . . . . . . . . . x x . . . . . . . -0.5\n", ". . . . . . . . . . . . . . . ⴵ ⴵ . . . . . . . +0.5\n", ". . . z . . . . . . . . . . . . . . . . . . . . -2.0\n", ". . . . . . . . . . . . . . . z . . . . . . . . -2.0\n", ". . . z . . . . . . . . . . . z . . . . . . . . +2.0\n", ". . . . x z z x . . . . . . . . . . . . . . . . -0.5\n", ". . . . ⴵ z z ⴵ . . . . . . . . . . . . . . . . +0.5\n", ". . . . x x . . . . . . . . . . . . . . . . . . -0.5\n", ". . . . ⴵ ⴵ . . . . . . . . . . . . . . . . . . +0.5\n", ". . . . . . . . . . . . . . . . x z z x . . . . -0.5\n", ". . . . . . . . . . . . . . . . ⴵ z z ⴵ . . . . +0.5\n", ". . . . . . . . . . . . . . . . x x . . . . . . -0.5\n", ". . . . . . . . . . . . . . . . ⴵ ⴵ . . . . . . +0.5\n", ". . . . z . . . . . . . . . . . . . . . . . . . -2.0\n", ". . . . . . . . . . . . . . . . z . . . . . . . -2.0\n", ". . . . z . . . . . . . . . . . z . . . . . . . +2.0\n", ". . . . . x z z x . . . . . . . . . . . . . . . -0.5\n", ". . . . . ⴵ z z ⴵ . . . . . . . . . . . . . . . +0.5\n", ". . . . . . . . . . . . . . . . . x z z x . . . -0.5\n", ". . . . . . . . . . . . . . . . . ⴵ z z ⴵ . . . +0.5\n", ". . . . . z . . . . . . . . . . . . . . . . . . -2.0\n", ". . . . . . . . . . . . . . . . . z . . . . . . -2.0\n", ". . . . . z . . . . . . . . . . . z . . . . . . +2.0\n", ". . . . . . x z z x . . . . . . . . . . . . . . -0.5\n", ". . . . . . ⴵ z z ⴵ . . . . . . . . . . . . . . +0.5\n", ". . . . . . x x . . . . . . . . . . . . . . . . -0.5\n", ". . . . . . ⴵ ⴵ . . . . . . . . . . . . . . . . +0.5\n", ". . . . . . . . . . . . . . . . . . x z z x . . -0.5\n", ". . . . . . . . . . . . . . . . . . ⴵ z z ⴵ . . +0.5\n", ". . . . . . . . . . . . . . . . . . x x . . . . -0.5\n", ". . . . . . . . . . . . . . . . . . ⴵ ⴵ . . . . +0.5\n", ". . . . . . z . . . . . . . . . . . . . . . . . -2.0\n", ". . . . . . . . . . . . . . . . . . z . . . . . -2.0\n", ". . . . . . z . . . . . . . . . . . z . . . . . +2.0\n", ". . . . . . . x z z x . . . . . . . . . . . . . -0.5\n", ". . . . . . . ⴵ z z ⴵ . . . . . . . . . . . . . +0.5\n", ". . . . . . . x x . . . . . . . . . . . . . . . -0.5\n", ". . . . . . . ⴵ ⴵ . . . . . . . . . . . . . . . +0.5\n", ". . . . . . . . . . . . . . . . . . . x z z x . -0.5\n", ". . . . . . . . . . . . . . . . . . . ⴵ z z ⴵ . +0.5\n", ". . . . . . . . . . . . . . . . . . . x x . . . -0.5\n", ". . . . . . . . . . . . . . . . . . . ⴵ ⴵ . . . +0.5\n", ". . . . . . . z . . . . . . . . . . . . . . . . -2.0\n", ". . . . . . . . . . . . . . . . . . . z . . . . -2.0\n", ". . . . . . . z . . . . . . . . . . . z . . . . +2.0\n", ". . . . . . . . x z z x . . . . . . . . . . . . -0.5\n", ". . . . . . . . ⴵ z z ⴵ . . . . . . . . . . . . +0.5\n", ". . . . . . . . . . . . . . . . . . . . x z z x -0.5\n", ". . . . . . . . . . . . . . . . . . . . ⴵ z z ⴵ +0.5\n", ". . . . . . . . z . . . . . . . . . . . . . . . -2.0\n", ". . . . . . . . . . . . . . . . . . . . z . . . -2.0\n", ". . . . . . . . z . . . . . . . . . . . z . . . +2.0\n", ". . . . . . . . . x x . . . . . . . . . . . . . -0.5\n", ". . . . . . . . . ⴵ ⴵ . . . . . . . . . . . . . +0.5\n", ". . . . . . . . . . . . . . . . . . . . . x x . -0.5\n", ". . . . . . . . . . . . . . . . . . . . . ⴵ ⴵ . +0.5\n", ". . . . . . . . . z . . . . . . . . . . . . . . -2.0\n", ". . . . . . . . . . . . . . . . . . . . . z . . -2.0\n", ". . . . . . . . . z . . . . . . . . . . . z . . +2.0\n", ". . . . . . . . . . x x . . . . . . . . . . . . -0.5\n", ". . . . . . . . . . ⴵ ⴵ . . . . . . . . . . . . +0.5\n", ". . . . . . . . . . . . . . . . . . . . . . x x -0.5\n", ". . . . . . . . . . . . . . . . . . . . . . ⴵ ⴵ +0.5\n", ". . . . . . . . . . z . . . . . . . . . . . . . -2.0\n", ". . . . . . . . . . . . . . . . . . . . . . z . -2.0\n", ". . . . . . . . . . z . . . . . . . . . . . z . +2.0\n", ". . . . . . . . . . . . . . . . . . . . . . . . +24.0\n", ". . . . . . . . . . . z . . . . . . . . . . . . -2.0\n", ". . . . . . . . . . . . . . . . . . . . . . . z -2.0\n", ". . . . . . . . . . . z . . . . . . . . . . . z +2.0\n" ] } ], "source": [ "H.pauli_decompose(use_zx=True)\n", "H.show()" ] }, { "cell_type": "markdown", "id": "35bb2145", "metadata": {}, "source": [ "### Builtin operators\n", "\n", "The following hamiltonians are built in:\n", "\n", "- [`heisenberg_from_edges`](quimb.operator.heisenberg_from_edges): the Heisenberg model on an arbitrary graph defined by `edges`, includes the transverse field ising model as a special case of the coupling and magnetic field terms.\n", "- [`fermi_hubbard_from_edges`](quimb.operator.fermi_hubbard_from_edges): the Fermi-Hubbard model on an arbitrary graph defined by `edges`.\n", "- [`fermi_hubbard_spinless_from_edges`](quimb.operator.fermi_hubbard_spinless_from_edges): the spinless Fermi-Hubbard model (aka t-V model) on an arbitrary graph defined by `edges`." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3" } }, "nbformat": 4, "nbformat_minor": 5 }