mps

package
v0.0.0-...-7d893d1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 13, 2025 License: BSD-3-Clause Imports: 8 Imported by: 0

README

Matrix Product States Go Reference

Documentation

Overview

Package mps implements the Matrix Product State algorithm.

References:

  • The density-matrix renormalization group in the age of matrix product states, Ulrich Schollwock
Example
package main

import (
	"fmt"
	"log"
	"math/cmplx"

	"github.com/fumin/qising/mps"
	"github.com/fumin/tensor"
)

func main() {
	// Create an Ising chain of length n and transverse field strength h.
	const n = 4
	const h = 0.031623
	mpo := mps.Ising([2]int{n, 1}, h)

	// Buffers.
	fs := make([]*tensor.Dense, 0, len(mpo))
	for _ = range mpo {
		fs = append(fs, tensor.Zeros(1))
	}
	var bufs [10]*tensor.Dense
	for i := range len(bufs) {
		bufs[i] = tensor.Zeros(1)
	}

	// Search for the ground state.
	const bondDim = 8
	state := mps.RandMPS(mpo, bondDim)
	if err := mps.SearchGroundState(fs, mpo, state, bufs); err != nil {
		log.Fatalf("%+v", err)
	}
	// Compute expectation values of the ground state.
	bufs2 := [2]*tensor.Dense(bufs[:2])
	norm2 := mps.InnerProduct(state, state, bufs2)        // <state|state>
	e0 := mps.LExpressions(fs, mpo, state, bufs2) / norm2 // ground energy
	const expected = -3.001501
	if abs(e0-expected) < 2e-6 {
		fmt.Println("Ground energy", expected)
	}

}

func abs(x complex64) float64 {
	return cmplx.Abs(complex128(x))
}
Output:

Ground energy -3.001501

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func H2

func H2(ws, ms []*tensor.Dense, bufs [2]*tensor.Dense) complex64

H2 returns <psi|H^2|psi>. See Figure 44, Section 6.4 Conventional DMRG in MPS language: the subtle differences, Ulrich Schollwock for a graphical explanation.

func InnerProduct

func InnerProduct(x, y []*tensor.Dense, bufs [2]*tensor.Dense) complex64

InnerProduct computes the inner product between x and y. See Section 4.2.1 Efficient evaluation of contractions, Ulrich Schollwock.

func Ising

func Ising(n [2]int, h complex64) []*tensor.Dense

Ising returns the MPO hamiltonian of the Transverse Field Ising Model. n is the shape of the lattic, and h is the field strength.

func LExpressions

func LExpressions(fs, ws, ms []*tensor.Dense, bufs [2]*tensor.Dense) complex64

LExpressions returns the L expressions defined in Equation 192, Section 6.2 Applying a Hamiltonian MPO to a mixed canonical state, Ulrich Schollwock. See Figure 38, Ulrich Schollwock for a graphical explanation.

func MagnetizationZ

func MagnetizationZ(n [2]int) []*tensor.Dense

MagnetizationZ returns the MPO hamiltonian of the Z axis magnetization. The shape of the lattice is specified by n.

func NewMPS

func NewMPS(state *tensor.Dense, bufs [2]*tensor.Dense) []*tensor.Dense

NewMPS create a matrix product representation from a general state.

func RExpressions

func RExpressions(fs, ws, ms []*tensor.Dense, bufs [2]*tensor.Dense) complex64

RExpressions returns the R expressions defined in Equation 193, Section 6.2 Applying a Hamiltonian MPO to a mixed canonical state, Ulrich Schollwock. See Figure 38, Ulrich Schollwock for a graphical explanation.

func RandMPS

func RandMPS(mpo []*tensor.Dense, maxD int) []*tensor.Dense

RandMPS creates a random matrix product state. maxD is the maximum bond dimension, which is D in the discussion below equation 71 in section 4.1.4, Ulrich Schollwock.

func SearchGroundState

func SearchGroundState(fs, ws, ms []*tensor.Dense, bufs [10]*tensor.Dense, options ...SearchGroundStateOptions) error

SearchGroundState performs the MPS ground state search. See Section 6.3 Iterative ground state search, Ulrich Schollwock.

Types

type SearchGroundStateOptions

type SearchGroundStateOptions struct {
	// contains filtered or unexported fields
}

SearchGroundStateOptions are options for the MPS ground state search algorithm.

func NewSearchGroundStateOptions

func NewSearchGroundStateOptions() SearchGroundStateOptions

NewSearchGroundStateOptions returns the default MPS ground state search options.

func (SearchGroundStateOptions) MaxIterations

MaxIterations sets the maximum iterations.

func (SearchGroundStateOptions) Tol

Tol sets the tolerance of the convergence criterion <H^2> - (<H>)^2.

Directories

Path Synopsis
cmd
run

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL