Skip to content

Commit ac4ebed

Browse files
authored
[ITensors] Introduce ITensorsPackageCompilerExt (#1403)
1 parent cf40eea commit ac4ebed

File tree

11 files changed

+80
-63
lines changed

11 files changed

+80
-63
lines changed

ITensorGaussianMPS/Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ITensorGaussianMPS"
22
uuid = "2be41995-7c9f-4653-b682-bfa4e7cebb93"
33
authors = ["Matthew Fishman <[email protected]> and contributors"]
4-
version = "0.1.5"
4+
version = "0.1.6"
55

66
[deps]
77
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
@@ -10,6 +10,6 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1010

1111
[compat]
1212
Compat = "3.40.0, 4"
13-
ITensors = "0.3.58, 0.4"
13+
ITensors = "0.3.58, 0.4, 0.5"
1414
LinearAlgebra = "1.6"
1515
julia = "1.6"

ITensorVisualizationBase/Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ITensorVisualizationBase"
22
uuid = "cd2553d2-8bef-4d93-8a38-c62f17d5ad23"
33
authors = ["Matthew Fishman <[email protected]> and contributors"]
4-
version = "0.1.6"
4+
version = "0.1.7"
55

66
[deps]
77
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
@@ -20,7 +20,7 @@ AbstractTrees = "0.4"
2020
Compat = "3.40.0, 4"
2121
GeometryBasics = "0.4.1"
2222
Graphs = "1.4.1"
23-
ITensors = "0.2.12, 0.3, 0.4"
23+
ITensors = "0.2.12, 0.3, 0.4, 0.5"
2424
MetaGraphs = "0.7.1"
2525
NetworkLayout = "0.4.3"
2626
Statistics = "1"

Project.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ITensors"
22
uuid = "9136182c-28ba-11e9-034c-db9fb085ebd5"
33
authors = ["Matthew Fishman <[email protected]>", "Miles Stoudenmire <[email protected]>"]
4-
version = "0.4.1"
4+
version = "0.5.0"
55

66
[deps]
77
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
@@ -16,7 +16,6 @@ KrylovKit = "0b1a1467-8014-51b9-945f-bf0ae24f4b77"
1616
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1717
LinearMaps = "7a12625a-238d-50fd-b39a-03d52299707e"
1818
NDTensors = "23ae76d9-e61a-49c4-8f12-3f1a16adf9cf"
19-
PackageCompiler = "9b87118b-4619-50d2-8e1e-99f35a4d4d9d"
2019
PackageExtensionCompat = "65ce6f38-6b18-4e1d-a461-8949797d7930"
2120
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
2221
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
@@ -35,11 +34,13 @@ ZygoteRules = "700de1a5-db45-46bc-99cf-38207098b444"
3534
[weakdeps]
3635
HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
3736
Observers = "338f10d5-c7f1-4033-a7d1-f9dec39bcaa0"
37+
PackageCompiler = "9b87118b-4619-50d2-8e1e-99f35a4d4d9d"
3838
VectorInterface = "409d34a3-91d5-4945-b6ec-7529ddf182d8"
3939

4040
[extensions]
4141
ITensorsHDF5Ext = "HDF5"
4242
ITensorsObserversExt = "Observers"
43+
ITensorsPackageCompilerExt = "PackageCompiler"
4344
ITensorsVectorInterfaceExt = "VectorInterface"
4445

4546
[compat]
@@ -56,7 +57,7 @@ KrylovKit = "0.4.2, 0.5, 0.6, 0.7"
5657
LinearAlgebra = "1.6"
5758
LinearMaps = "3"
5859
NDTensors = "0.3.0"
59-
PackageCompiler = "1.0.0, 2"
60+
PackageCompiler = "1, 2"
6061
PackageExtensionCompat = "1"
6162
Pkg = "1.6"
6263
Printf = "1.6"
@@ -77,4 +78,5 @@ julia = "1.6"
7778
[extras]
7879
HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
7980
Observers = "338f10d5-c7f1-4033-a7d1-f9dec39bcaa0"
81+
PackageCompiler = "9b87118b-4619-50d2-8e1e-99f35a4d4d9d"
8082
VectorInterface = "409d34a3-91d5-4945-b6ec-7529ddf182d8"

docs/src/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ Development of ITensor is supported by the Flatiron Institute, a division of the
2929

3030
## News
3131

32-
- April 16, 2024: ITensors.jl v0.4 has been released. This version removes HDF5 as a dependency (a breaking change) and moves the HDF5 read and write functions for ITensor, MPS, MPO, and other associated types into a package extension. To enable ITensor HDF5 features, install the HDF5 package and put `using HDF5` together with `using ITensors` in your code. Other recent changes include support for multiple GPU backends using package extensions.
32+
- May 2, 2024: ITensors.jl v0.5 has been released. This version removes PackageCompiler.jl as a dependency and moves the package compilation functionality into a package extension. In order to use the `ITensors.compile()` function going forward, you need to install the PackageCompiler.jl package with `using Pkg: Pkg; Pkg.add("PackageCompiler")` and put `using PackageCompiler` together with `using ITensors` in your code.
33+
34+
- April 16, 2024: ITensors.jl v0.4 has been released. This version removes HDF5.jl as a dependency and moves the HDF5 read and write functions for ITensor, MPS, MPO, and other associated types into a package extension. To enable ITensor HDF5 features, install the HDF5.jl package with `using Pkg: Pkg; Pkg.add("HDF5")` and put `using HDF5` together with `using ITensors` in your code. Other recent changes include support for multiple GPU backends using package extensions.
3335

3436
- March 25, 2022: ITensors.jl v0.3 has been released. The main breaking change is that we no longer support versions of Julia below 1.6. Julia 1.6 is the long term support version of Julia (LTS), which means that going forward versions below Julia 1.6 won't be as well supported with bug fixes and improvements. Additionally, Julia 1.6 introduced many improvements including syntax improvements that we would like to start using with ITensors.jl, which becomes challenging if we try to support Julia versions below 1.6. See [here](https://www.oxinabox.net/2021/02/13/Julia-1.6-what-has-changed-since-1.0.html) and [here](https://julialang.org/blog/2021/03/julia-1.6-highlights/) for some nice summaries of the Julia 1.6 release.
3537

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module ITensorsPackageCompilerExt
2+
include("compile.jl")
3+
include("precompile_itensors.jl")
4+
end
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using NDTensors: @Algorithm_str
2+
using ITensors: ITensors
3+
using PackageCompiler: PackageCompiler
4+
5+
function ITensors.compile(
6+
::Algorithm"PackageCompiler";
7+
dir::AbstractString=ITensors.default_compile_dir(),
8+
filename::AbstractString=ITensors.default_compile_filename(),
9+
)
10+
if !isdir(dir)
11+
println("""The directory "$dir" doesn't exist yet, creating it now.""")
12+
println()
13+
mkdir(dir)
14+
end
15+
path = joinpath(dir, filename)
16+
println(
17+
"""Creating the system image "$path" containing the compiled version of ITensors. This may take a few minutes.""",
18+
)
19+
PackageCompiler.create_sysimage(
20+
:ITensors;
21+
sysimage_path=path,
22+
precompile_execution_file=joinpath(@__DIR__, "precompile_itensors.jl"),
23+
)
24+
println(ITensors.compile_note(; dir, filename))
25+
return path
26+
end
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using ITensors.ITensorMPS: MPO, OpSum, dmrg, randomMPS, siteinds
2+
3+
# TODO: This uses all of the tests to make
4+
# precompile statements, but takes a long time
5+
# (e.g. 700 seconds).
6+
# Try again with later versions of PackageCompiler
7+
#
8+
# include(joinpath(joinpath(dirname(dirname(@__DIR__)),
9+
# test"),
10+
# "runtests.jl"))
11+
12+
function main(; N, dmrg_kwargs)
13+
opsum = OpSum()
14+
for j in 1:(N - 1)
15+
opsum += 0.5, "S+", j, "S-", j + 1
16+
opsum += 0.5, "S-", j, "S+", j + 1
17+
opsum += "Sz", j, "Sz", j + 1
18+
end
19+
for conserve_qns in (false, true)
20+
sites = siteinds("S=1", N; conserve_qns)
21+
H = MPO(opsum, sites)
22+
ψ0 = randomMPS(sites, j -> isodd(j) ? "" : ""; linkdims=2)
23+
dmrg(H, ψ0; outputlevel=0, dmrg_kwargs...)
24+
end
25+
return nothing
26+
end
27+
28+
main(; N=6, dmrg_kwargs=(; nsweeps=3, maxdim=10, cutoff=1e-13))

src/packagecompile/compile.jl

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
default_compile_dir() = joinpath(homedir(), ".julia", "sysimages")
32

43
default_compile_filename() = "sys_itensors.so"
@@ -37,26 +36,14 @@ function compile_note(; dir=default_compile_dir(), filename=default_compile_file
3736
"""
3837
end
3938

40-
function compile(;
41-
dir::AbstractString=default_compile_dir(),
42-
filename::AbstractString=default_compile_filename(),
43-
)
44-
if !isdir(dir)
45-
println("""The directory "$dir" doesn't exist yet, creating it now.""")
46-
println()
47-
mkdir(dir)
48-
end
49-
path = joinpath(dir, filename)
50-
println(
51-
"""Creating the system image "$path" containing the compiled version of ITensors. This may take a few minutes.""",
52-
)
53-
create_sysimage(
54-
:ITensors;
55-
sysimage_path=path,
56-
precompile_execution_file=joinpath(@__DIR__, "precompile_itensors.jl"),
39+
function compile(; backend=Algorithm"PackageCompiler"(), kwargs...)
40+
return compile(backend; kwargs...)
41+
end
42+
43+
function compile(::Algorithm; kwargs...)
44+
return error(
45+
"As of ITensors v0.5, you must install `PackageCompiler.jl` (`using Pkg: Pkg; Pkg.add(\"PackageCompiler\")`) and execute `using PackageCompiler` to use `ITensors.compile`.",
5746
)
58-
println(compile_note(; dir=dir, filename=filename))
59-
return path
6047
end
6148

6249
@doc """

src/packagecompile/precompile_itensors.jl

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/usings.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ using IsApprox
1414
using LinearAlgebra
1515
using NDTensors
1616
using NDTensors.RankFactorization: Spectrum, eigs, entropy, truncerror
17-
using PackageCompiler
1817
using Pkg
1918
using Printf
2019
using Random

0 commit comments

Comments
 (0)