From 74df45bf20e09d03c9b1b22a587f30fba58fffab Mon Sep 17 00:00:00 2001 From: Miles Date: Tue, 2 Apr 2024 18:59:29 -0400 Subject: [PATCH 1/8] Use update_observer! in alternating_update --- src/ITensorMPS/alternating_update.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ITensorMPS/alternating_update.jl b/src/ITensorMPS/alternating_update.jl index 3770f8b86e..63c62154c6 100644 --- a/src/ITensorMPS/alternating_update.jl +++ b/src/ITensorMPS/alternating_update.jl @@ -98,7 +98,7 @@ function alternating_update( ) end current_time += time_step - update!(step_observer!; psi, sweep, outputlevel, current_time) + update_observer!(step_observer!; psi, sweep, outputlevel, current_time) if outputlevel >= 1 print("After sweep ", sweep, ":") print(" maxlinkdim=", maxlinkdim(psi)) From ae16b3f9811f9129d7e725263dc337bbf382d02d Mon Sep 17 00:00:00 2001 From: Miles Date: Tue, 2 Apr 2024 22:26:56 -0400 Subject: [PATCH 2/8] Add ITensorsObserversExt extension and test --- Project.toml | 9 +++++++ .../ITensorsObserversExt.jl | 11 ++++++++ src/ITensors.jl | 10 +++++++ test/ITensorsObserversExt/Project.toml | 3 +++ test/ITensorsObserversExt/runtests.jl | 26 +++++++++++++++++++ test/Project.toml | 1 + test/runtests.jl | 1 + 7 files changed, 61 insertions(+) create mode 100644 ext/ITensorsObserversExt/ITensorsObserversExt.jl create mode 100644 test/ITensorsObserversExt/Project.toml create mode 100644 test/ITensorsObserversExt/runtests.jl diff --git a/Project.toml b/Project.toml index 9324e1c6a0..8c7a36ff85 100644 --- a/Project.toml +++ b/Project.toml @@ -33,6 +33,15 @@ TupleTools = "9d95972d-f1c8-5527-a6e0-b4b365fa01f6" Zeros = "bd1ec220-6eb4-527a-9b49-e79c3db6233b" ZygoteRules = "700de1a5-db45-46bc-99cf-38207098b444" +[weakdeps] +Observers = "338f10d5-c7f1-4033-a7d1-f9dec39bcaa0" + +[extensions] +ITensorsObserversExt = "Observers" + +[extras] +Observers = "338f10d5-c7f1-4033-a7d1-f9dec39bcaa0" + [compat] Adapt = "3.5, 4" BitIntegers = "0.2, 0.3" diff --git a/ext/ITensorsObserversExt/ITensorsObserversExt.jl b/ext/ITensorsObserversExt/ITensorsObserversExt.jl new file mode 100644 index 0000000000..32c16e1a09 --- /dev/null +++ b/ext/ITensorsObserversExt/ITensorsObserversExt.jl @@ -0,0 +1,11 @@ +module ITensorsObserversExt + +using ITensors.ITensorMPS: ITensorMPS +using Observers: Observers +using Observers.DataFrames: AbstractDataFrame + +function ITensorMPS.update_observer!(observer::AbstractDataFrame; kwargs...) + return Observers.update!(observer; kwargs...) +end + +end diff --git a/src/ITensors.jl b/src/ITensors.jl index d726694025..3738bbbc73 100644 --- a/src/ITensors.jl +++ b/src/ITensors.jl @@ -225,4 +225,14 @@ end # _precompile_() #end + + +# +# See section on "Transition from normal dependency to extension" +# in https://pkgdocs.julialang.org/v1/creating-packages +# +if !isdefined(Base, :get_extension) + include("../ext/ITensorsObserversExt.jl") +end + end # module ITensors diff --git a/test/ITensorsObserversExt/Project.toml b/test/ITensorsObserversExt/Project.toml new file mode 100644 index 0000000000..c279eee897 --- /dev/null +++ b/test/ITensorsObserversExt/Project.toml @@ -0,0 +1,3 @@ +[deps] +ITensors = "9136182c-28ba-11e9-034c-db9fb085ebd5" +Observers = "338f10d5-c7f1-4033-a7d1-f9dec39bcaa0" diff --git a/test/ITensorsObserversExt/runtests.jl b/test/ITensorsObserversExt/runtests.jl new file mode 100644 index 0000000000..430f4de7b4 --- /dev/null +++ b/test/ITensorsObserversExt/runtests.jl @@ -0,0 +1,26 @@ +@eval module $(gensym()) +using Test: @test, @testset +using ITensors.ITensorMPS: update_observer! +using Observers: observer + +@testset "ITensorsObserversExt" begin + + function iterative_function(niter; observer!, observe_step) + for n in 1:niter + if iszero(n % observe_step) + update_observer!(observer!; iteration=n) + end + end + end + + # Record the iteration + iteration(; iteration) = iteration + + obs = observer(iteration) + niter = 100 + iterative_function(niter; (observer!)=obs, observe_step=10) + + @test size(obs) == (10,1) +end + +end diff --git a/test/Project.toml b/test/Project.toml index 2203bd672e..938b333669 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -10,6 +10,7 @@ JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819" KrylovKit = "0b1a1467-8014-51b9-945f-bf0ae24f4b77" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" NDTensors = "23ae76d9-e61a-49c4-8f12-3f1a16adf9cf" +Observers = "338f10d5-c7f1-4033-a7d1-f9dec39bcaa0" OptimKit = "77e91f04-9b3b-57a6-a776-40b61faaebe0" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" QuadGK = "1fd47b50-473d-5c70-9696-f719f8f3bcdc" diff --git a/test/runtests.jl b/test/runtests.jl index c3195191c0..bd8b357b9f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -21,6 +21,7 @@ ITensors.disable_threaded_blocksparse() "ContractionSequenceOptimization", "ITensorChainRules", "ITensorNetworkMaps", + "ITensorsObserversExt", ] @time for dir in dirs println("\nTest $(@__DIR__)/$(dir)") From 13833e8f200141fd76e419b9e1fc8e4dbbc1356a Mon Sep 17 00:00:00 2001 From: Miles Date: Tue, 2 Apr 2024 22:30:03 -0400 Subject: [PATCH 3/8] Update src/ITensors.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/ITensors.jl | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/ITensors.jl b/src/ITensors.jl index 3738bbbc73..97ae09cdd6 100644 --- a/src/ITensors.jl +++ b/src/ITensors.jl @@ -225,8 +225,6 @@ end # _precompile_() #end - - # # See section on "Transition from normal dependency to extension" # in https://pkgdocs.julialang.org/v1/creating-packages From 6d2c1996b093b4818e621aff1dc927ace2f26411 Mon Sep 17 00:00:00 2001 From: Miles Date: Tue, 2 Apr 2024 22:30:10 -0400 Subject: [PATCH 4/8] Update test/ITensorsObserversExt/runtests.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- test/ITensorsObserversExt/runtests.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/test/ITensorsObserversExt/runtests.jl b/test/ITensorsObserversExt/runtests.jl index 430f4de7b4..4fe3ab10ed 100644 --- a/test/ITensorsObserversExt/runtests.jl +++ b/test/ITensorsObserversExt/runtests.jl @@ -4,7 +4,6 @@ using ITensors.ITensorMPS: update_observer! using Observers: observer @testset "ITensorsObserversExt" begin - function iterative_function(niter; observer!, observe_step) for n in 1:niter if iszero(n % observe_step) From 64242346de52be257a497d6afd0d77dc066ae1e6 Mon Sep 17 00:00:00 2001 From: Miles Date: Tue, 2 Apr 2024 22:30:15 -0400 Subject: [PATCH 5/8] Update test/ITensorsObserversExt/runtests.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- test/ITensorsObserversExt/runtests.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/ITensorsObserversExt/runtests.jl b/test/ITensorsObserversExt/runtests.jl index 4fe3ab10ed..5cdd0bdc2a 100644 --- a/test/ITensorsObserversExt/runtests.jl +++ b/test/ITensorsObserversExt/runtests.jl @@ -18,8 +18,8 @@ using Observers: observer obs = observer(iteration) niter = 100 iterative_function(niter; (observer!)=obs, observe_step=10) - - @test size(obs) == (10,1) + + @test size(obs) == (10, 1) end end From 930690834285bcb1062096f50e51f874b00d94de Mon Sep 17 00:00:00 2001 From: Miles Date: Wed, 3 Apr 2024 14:09:15 -0400 Subject: [PATCH 6/8] Remove unneeded extension code --- src/ITensors.jl | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/ITensors.jl b/src/ITensors.jl index 3ce0dec43d..eb9f911501 100644 --- a/src/ITensors.jl +++ b/src/ITensors.jl @@ -227,12 +227,4 @@ end # _precompile_() #end -# -# See section on "Transition from normal dependency to extension" -# in https://pkgdocs.julialang.org/v1/creating-packages -# -if !isdefined(Base, :get_extension) - include("../ext/ITensorsObserversExt.jl") -end - end # module ITensors From 38c86b88b9c793fdbf9efadc344d745344689756 Mon Sep 17 00:00:00 2001 From: Miles Date: Wed, 3 Apr 2024 14:10:22 -0400 Subject: [PATCH 7/8] Restore VectorInterface to weakdeps --- Project.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Project.toml b/Project.toml index b479ceb176..3a0918db14 100644 --- a/Project.toml +++ b/Project.toml @@ -36,6 +36,7 @@ ZygoteRules = "700de1a5-db45-46bc-99cf-38207098b444" [weakdeps] Observers = "338f10d5-c7f1-4033-a7d1-f9dec39bcaa0" +VectorInterface = "409d34a3-91d5-4945-b6ec-7529ddf182d8" [extensions] ITensorsObserversExt = "Observers" From 01de433153f9d6ff045a6fa41855f93d72d143bd Mon Sep 17 00:00:00 2001 From: Miles Date: Wed, 3 Apr 2024 21:43:15 -0400 Subject: [PATCH 8/8] Remove Observers as a main dependency --- Project.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/Project.toml b/Project.toml index 3a0918db14..b0e43f719d 100644 --- a/Project.toml +++ b/Project.toml @@ -17,7 +17,6 @@ KrylovKit = "0b1a1467-8014-51b9-945f-bf0ae24f4b77" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" LinearMaps = "7a12625a-238d-50fd-b39a-03d52299707e" NDTensors = "23ae76d9-e61a-49c4-8f12-3f1a16adf9cf" -Observers = "338f10d5-c7f1-4033-a7d1-f9dec39bcaa0" PackageCompiler = "9b87118b-4619-50d2-8e1e-99f35a4d4d9d" PackageExtensionCompat = "65ce6f38-6b18-4e1d-a461-8949797d7930" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"