Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Run tests

on:
push:
branches:
- main
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

# needed to allow julia-actions/cache to delete old caches that it has created
permissions:
actions: write
contents: read

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
julia-version: ['lts', '1', 'pre']
julia-arch: [x64, x86]
os: [ubuntu-latest, windows-latest, macOS-latest]
exclude:
- os: macOS-latest
julia-arch: x86

steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.julia-version }}
arch: ${{ matrix.julia-arch }}
- uses: julia-actions/cache@v2
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
# with:
# annotate: true
3 changes: 3 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ KrylovKit = "0.10.2"
ProgressMeter = "1.11.0"
TensorOperations = "5.6.0"
julia = "1.10"

[workspace]
projects = ["test"]
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# TensorTimeSteps.jl

### A collection of time evolution algorithms for tensor network states
[![Run tests](https://github.com/BenjaminDecker/TensorTimeSteps.jl/actions/workflows/test.yml/badge.svg)](https://github.com/BenjaminDecker/TensorTimeSteps.jl/actions/workflows/test.yml)

## A collection of time evolution algorithms for tensor network states

Given a Hamiltonian operator $H$ in [MPO](https://tensornetwork.org/mpo/) form, and an initial state $\psi_0$ in [MPS](https://tensornetwork.org/mps/) form, calculate

Expand All @@ -12,7 +14,7 @@ $$

For now, only the 1-site and 2-site [TDVP](https://tensornetwork.org/mps/algorithms/timeevo/tdvp.html) algorithms are supported, and $H$ and $\psi_0$ must be given as [ITensor](https://docs.itensor.org/ITensorMPS/stable/examples/MPSandMPO.html) MPS/MPO types.

## Usage
### Usage

Provide some $H$ and $\psi_0$
```julia
Expand Down
6 changes: 6 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[deps]
ITensorMPS = "0d1a4710-d33b-49a5-8f18-73bdf49b47e2"
ITensors = "9136182c-28ba-11e9-034c-db9fb085ebd5"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
TensorTimeSteps = "1f4dac17-e489-46a5-8247-1c82af6382b6"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
64 changes: 64 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using TensorTimeSteps, Test, ITensors, ITensorMPS, Random

function create_tfim(N; J=1, g=0.5)
sites = siteinds("Qubit", N)

# tfim Hamiltonian
os = OpSum()
for j=1:(N-1)
os .+= -J, "Z", j, "Z", j+1
os .+= -g*J, "X", j
end
os .+= -g*J, "X", N
MPO(os, sites)
end

function exact_evolution(H, psi_0, T)
noprime(
contract(
exp(-im*T*contract(H)),
contract(psi_0)
)
)
end

@testset let
N = 6
T = 1
num_steps = 10
sweeps_per_time_step = 10
maxdim = 32
cutoff = 1e-10

H = create_tfim(N)
psi_0 = random_mps(dag(firstsiteinds(H)); linkdims=maxdim)
exact=exact_evolution(H, psi_0, T)

results1 = tdvp1(
H,
psi_0;
step_size=T/num_steps,
num_steps=num_steps,
sweeps_per_time_step=sweeps_per_time_step,
max_bond_dim=maxdim
)

@test isapprox(contract(contract(results1[end]), dag(exact))[1], 1)
@test isapprox(contract(contract(results1[1]), dag(contract(psi_0)))[1], 1)
@test length(results1) == (num_steps + 1)

results2 = tdvp2(
H,
psi_0;
step_size=T/num_steps,
num_steps=num_steps,
sweeps_per_time_step=sweeps_per_time_step,
max_bond_dim=maxdim,
svd_epsilon=cutoff,
switch_when_maxdim_reached=false
)

@test isapprox(contract(contract(results2[end]), dag(exact))[1], 1)
@test isapprox(contract(contract(results2[1]), dag(contract(psi_0)))[1], 1)
@test length(results2) == (num_steps + 1)
end
Loading