From d178325ecf4301a42abe792d6a60dcb1a8abe48f Mon Sep 17 00:00:00 2001 From: Benjamin Decker <39363928+BenjaminDecker@users.noreply.github.com> Date: Wed, 29 Jul 2026 19:40:53 +0200 Subject: [PATCH 1/8] write unit tests --- .github/test.yml | 38 ++++++++++++++++++++++++++++ Project.toml | 3 +++ test/Project.toml | 6 +++++ test/runtests.jl | 64 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 111 insertions(+) create mode 100644 .github/test.yml create mode 100644 test/Project.toml create mode 100644 test/runtests.jl diff --git a/.github/test.yml b/.github/test.yml new file mode 100644 index 0000000..0cb2d3a --- /dev/null +++ b/.github/test.yml @@ -0,0 +1,38 @@ +name: Run tests + +on: + push: + branches: + - master + - main + - test + pull_request: + +# 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 \ No newline at end of file diff --git a/Project.toml b/Project.toml index f7e9815..12cf5a2 100644 --- a/Project.toml +++ b/Project.toml @@ -17,3 +17,6 @@ KrylovKit = "0.10.2" ProgressMeter = "1.11.0" TensorOperations = "5.6.0" julia = "1.10" + +[workspace] +projects = ["test"] \ No newline at end of file diff --git a/test/Project.toml b/test/Project.toml new file mode 100644 index 0000000..807e39f --- /dev/null +++ b/test/Project.toml @@ -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" diff --git a/test/runtests.jl b/test/runtests.jl new file mode 100644 index 0000000..d73df26 --- /dev/null +++ b/test/runtests.jl @@ -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 \ No newline at end of file From 20a160061ca6b84fb12fa6bee8120e2b1466ed92 Mon Sep 17 00:00:00 2001 From: Benjamin Decker <39363928+BenjaminDecker@users.noreply.github.com> Date: Wed, 29 Jul 2026 19:46:25 +0200 Subject: [PATCH 2/8] move test.yml into correct directory --- .github/{ => workflows}/test.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/{ => workflows}/test.yml (100%) diff --git a/.github/test.yml b/.github/workflows/test.yml similarity index 100% rename from .github/test.yml rename to .github/workflows/test.yml From b081646e1c83e718e712b8cab3e8ebb942c2aa54 Mon Sep 17 00:00:00 2001 From: Benjamin Decker <39363928+BenjaminDecker@users.noreply.github.com> Date: Wed, 29 Jul 2026 19:52:45 +0200 Subject: [PATCH 3/8] Only run tests on pull requests --- .github/workflows/test.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0cb2d3a..593d671 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,11 +1,6 @@ name: Run tests on: - push: - branches: - - master - - main - - test pull_request: # needed to allow julia-actions/cache to delete old caches that it has created From ff10c009c490365fdd3aa398009e59a7e7cc33b5 Mon Sep 17 00:00:00 2001 From: Benjamin Decker <39363928+BenjaminDecker@users.noreply.github.com> Date: Wed, 29 Jul 2026 19:53:03 +0200 Subject: [PATCH 4/8] Cancel already running tests if pr changes --- .github/workflows/test.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 593d671..bc69e2a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,6 +3,10 @@ name: Run tests on: 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 From ef35b7f9364b8360f552bd5c04408edfe54f686a Mon Sep 17 00:00:00 2001 From: Benjamin Decker <39363928+BenjaminDecker@users.noreply.github.com> Date: Wed, 29 Jul 2026 19:55:16 +0200 Subject: [PATCH 5/8] Also run tests when main changes --- .github/workflows/test.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bc69e2a..b28dcf5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,9 @@ name: Run tests on: + push: + branches: + - main pull_request: concurrency: From b52be6f2924bae165140bace3df401872f09408e Mon Sep 17 00:00:00 2001 From: Benjamin Decker <39363928+BenjaminDecker@users.noreply.github.com> Date: Wed, 29 Jul 2026 20:19:05 +0200 Subject: [PATCH 6/8] Only linux, but with arm64 --- .github/workflows/test.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b28dcf5..fec6fb5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,11 +21,11 @@ jobs: 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 + julia-arch: [x64, x86, arm64] + os: [ubuntu-latest] + # exclude: + # - os: macOS-latest + # julia-arch: x86 steps: - uses: actions/checkout@v4 From 8e66450bd9f05ffddacd1789bd23d443bee52217 Mon Sep 17 00:00:00 2001 From: Benjamin Decker <39363928+BenjaminDecker@users.noreply.github.com> Date: Wed, 29 Jul 2026 20:23:39 +0200 Subject: [PATCH 7/8] Revert "Only linux, but with arm64" This reverts commit b52be6f2924bae165140bace3df401872f09408e. --- .github/workflows/test.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fec6fb5..b28dcf5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,11 +21,11 @@ jobs: strategy: matrix: julia-version: ['lts', '1', 'pre'] - julia-arch: [x64, x86, arm64] - os: [ubuntu-latest] - # exclude: - # - os: macOS-latest - # julia-arch: x86 + julia-arch: [x64, x86] + os: [ubuntu-latest, windows-latest, macOS-latest] + exclude: + - os: macOS-latest + julia-arch: x86 steps: - uses: actions/checkout@v4 From 8ec9f5e50cd90e5704dc333e5b94cabe780eff97 Mon Sep 17 00:00:00 2001 From: Benjamin Decker <39363928+BenjaminDecker@users.noreply.github.com> Date: Wed, 29 Jul 2026 20:32:08 +0200 Subject: [PATCH 8/8] Add a workflow badge --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9c189ea..2c0c445 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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