diff --git a/Project.toml b/Project.toml index cee381a164..8e40708073 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ITensors" uuid = "9136182c-28ba-11e9-034c-db9fb085ebd5" authors = ["Matthew Fishman ", "Miles Stoudenmire "] -version = "0.3.59" +version = "0.3.60" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" diff --git a/src/ITensors.jl b/src/ITensors.jl index 37cef8adae..d726694025 100644 --- a/src/ITensors.jl +++ b/src/ITensors.jl @@ -53,26 +53,7 @@ module ITensors ##################################### # External packages # -using Adapt -using BitIntegers -using ChainRulesCore -using Compat -using DocStringExtensions -using Functors -using HDF5 -using IsApprox -using LinearAlgebra -using NDTensors -using PackageCompiler -using Pkg -using Printf -using Random -using Reexport -using SerializedElementArrays -using StaticArrays -using TimerOutputs -using TupleTools -using Zeros +include("usings.jl") ##################################### # General utility functions diff --git a/src/exports.jl b/src/exports.jl index 659331b788..08ba0c8986 100644 --- a/src/exports.jl +++ b/src/exports.jl @@ -1,5 +1,3 @@ -using NDTensors.RankFactorization: Spectrum, eigs, entropy, truncerror - export # From external modules # LinearAlgebra diff --git a/src/usings.jl b/src/usings.jl new file mode 100644 index 0000000000..f1bb1cf284 --- /dev/null +++ b/src/usings.jl @@ -0,0 +1,32 @@ +# TODO: Delete these and move them to the tops of files where +# they are be used, and change to explicit usings, i.e. +# `using NDTensors: tensor`. +# Try using `ExplicitImports.jl`: +# https://github.com/ericphanson/ExplicitImports.jl +# to automate the process. +using Adapt +using BitIntegers +using ChainRulesCore +using Compat +using DocStringExtensions +using Functors +using HDF5 +using IsApprox +using LinearAlgebra +using NDTensors +using NDTensors.RankFactorization: Spectrum, eigs, entropy, truncerror +using PackageCompiler +using Pkg +using Printf +using Random +using Reexport +using SerializedElementArrays +using StaticArrays +using TimerOutputs +using TupleTools +using Zeros + +# This makes `scalartype` available externally as +# `ITensors.scalartype`, this isn't be used within +# the `ITensors` module right now. +using NDTensors: scalartype diff --git a/test/base/Project.toml b/test/base/Project.toml new file mode 100644 index 0000000000..87b49b773d --- /dev/null +++ b/test/base/Project.toml @@ -0,0 +1,7 @@ +[deps] +Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa" +HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f" +ITensors = "9136182c-28ba-11e9-034c-db9fb085ebd5" +QuadGK = "1fd47b50-473d-5c70-9696-f719f8f3bcdc" +Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/test/base/runtests.jl b/test/base/runtests.jl index c2fe5a8b6f..ff4b5e43d1 100644 --- a/test/base/runtests.jl +++ b/test/base/runtests.jl @@ -1,10 +1,9 @@ -using ITensors -using Test - +@eval module $(gensym()) +using ITensors: ITensors +using Test: @testset ITensors.Strided.disable_threads() ITensors.BLAS.set_num_threads(1) ITensors.disable_threaded_blocksparse() - @testset "$(@__DIR__)" begin filenames = filter(readdir(@__DIR__)) do f startswith("test_")(f) && endswith(".jl")(f) @@ -14,3 +13,4 @@ ITensors.disable_threaded_blocksparse() @time include(filename) end end +end diff --git a/test/base/test_exports.jl b/test/base/test_exports.jl new file mode 100644 index 0000000000..ccfdb65762 --- /dev/null +++ b/test/base/test_exports.jl @@ -0,0 +1,9 @@ +@eval module $(gensym()) +using ITensors: ITensors +using Test: @test, @testset +include("utils/TestITensorsExportedNames/TestITensorsExportedNames.jl") +using .TestITensorsExportedNames: ITENSORS_EXPORTED_NAMES +@testset "Test $name is exported" for name in ITENSORS_EXPORTED_NAMES + @test Base.isexported(ITensors, name) +end +end diff --git a/test/base/test_itensor.jl b/test/base/test_itensor.jl index 73a9e47d34..a8b01c765e 100644 --- a/test/base/test_itensor.jl +++ b/test/base/test_itensor.jl @@ -1,16 +1,83 @@ -using ITensors -using LinearAlgebra -using Test - +@eval module $(gensym()) using Combinatorics: permutations - -import Random: seed! -import ITensors.NDTensors: DenseTensor +using ITensors: + ITensors, + Index, + IndexSet, + ITensor, + Order, + QN, + ⊕, + δ, + addtags, + allhastags, + anyhastags, + commonind, + convert_eltype, + convert_leaf_eltype, + dag, + directsum, + eachindval, + eachval, + filterinds, + firstind, + hascommoninds, + hasind, + hasinds, + hassameinds, + hastags, + inner, + itensor, + mapprime, + noprime, + onehot, + order, + permute, + prime, + product, + randomITensor, + removetags, + replaceind, + replaceind!, + replaceinds, + replaceinds!, + replacetags, + scalar, + setelt, + setprime, + settags, + sim, + swapinds, + swapinds!, + swapprime, + uniqueind, + uniqueindex, + val +using ITensors.NDTensors: + NDTensors, + DenseTensor, + array, + dim, + dims, + eigen, + factorize, + ind, + inds, + matrix, + maxdim, + mindim, + polar, + storage, + vector +using LinearAlgebra: + LinearAlgebra, axpy!, diag, dot, ishermitian, mul!, norm, nullspace, qr, rmul!, svd, tr +using Random: Random +using Test: @test, @test_throws, @testset # Enable debug checking for these tests ITensors.enable_debug_checks() -seed!(12345) +Random.seed!(12345) function invdigits(::Type{T}, x...) where {T} return T(sum([x[length(x) - k + 1] * 10^(k - 1) for k in 1:length(x)])) @@ -72,6 +139,15 @@ end @test iszero(ITensor(i, j)) end + elts = (Float32, Float64, Complex{Float32}, Complex{Float64}) + @testset "ITensors.scalartype (eltype=$elt)" for elt in elts + i, j = Index.((2, 2)) + a = ITensor(elt, i, j) + @test ITensors.scalartype(a) === elt + a = randomITensor(elt, i, j) + @test ITensors.scalartype(a) === elt + end + @testset "map" begin A = randomITensor(Index(2)) @test eltype(A) == Float64 @@ -1847,3 +1923,4 @@ end # End Dense ITensor basic functionality # Disable debug checking once tests are completed ITensors.disable_debug_checks() +end diff --git a/test/base/utils/TestITensorsExportedNames/TestITensorsExportedNames.jl b/test/base/utils/TestITensorsExportedNames/TestITensorsExportedNames.jl new file mode 100644 index 0000000000..c7a0f9e9ff --- /dev/null +++ b/test/base/utils/TestITensorsExportedNames/TestITensorsExportedNames.jl @@ -0,0 +1,347 @@ +module TestITensorsExportedNames +#= +# List constructed with (along with cleaning up +# macro symbols): +using DelimitedFiles: writedlm +using ITensors: ITensors +open("itensors_exported_names.jl", "w") do io + writedlm(io, repr.(names(ITensors)) .* ",") +end +=# +const ITENSORS_EXPORTED_NAMES = [ + Symbol("@OpName_str"), + Symbol("@SiteType_str"), + Symbol("@StateName_str"), + Symbol("@TagType_str"), + Symbol("@ValName_str"), + Symbol("@disable_warn_order"), + Symbol("@preserve_ortho"), + Symbol("@reset_warn_order"), + Symbol("@set_warn_order"), + Symbol("@ts_str"), + Symbol("@visualize"), + Symbol("@visualize!"), + Symbol("@visualize_noeval"), + Symbol("@visualize_noeval!"), + Symbol("@visualize_sequence"), + Symbol("@visualize_sequence_noeval"), + :AbstractMPS, + :AbstractObserver, + :Apply, + :AutoMPO, + :Block, + :DMRGMeasurement, + :DMRGObserver, + :ITensor, + :ITensorMPS, + :ITensors, + :Index, + :IndexSet, + :IndexVal, + :Lattice, + :LatticeBond, + :LinearAlgebra, + :MPO, + :MPS, + :NDTensors, + :NoObserver, + :Op, + :OpName, + :OpSum, + :Ops, + :Order, + :Prod, + :ProjMPO, + :ProjMPOSum, + :ProjMPO_MPS, + :QN, + :Scaled, + :SiteType, + :Spectrum, + :StateName, + :Sum, + :Sweeps, + :TagSet, + :TagType, + :Trotter, + :ValName, + :add, + :add!, + :addblock!, + :addtags, + :addtags!, + :allhastags, + :anyhastags, + :apply, + :applyMPO, + :applympo, + :argsdict, + :array, + :axpy!, + :blockdim, + :blockoffsets, + :checkdone!, + :checkflux, + :coefficient, + :combinedind, + :combiner, + :common_siteind, + :common_siteinds, + :commonind, + :commonindex, + :commoninds, + :complex!, + :contract, + :convert_eltype, + :convert_leaf_eltype, + :correlation_matrix, + :cutoff, + :cutoff!, + :dag, + :delta, + :dense, + :denseblocks, + :diag, + :diagITensor, + :diagitensor, + :dim, + :dims, + :dir, + :directsum, + :disable_combine_contract!, + :disable_tblis!, + :disable_warn_order!, + :disk, + :dmrg, + :dot, + :eachindval, + :eachnzblock, + :eachval, + :eigen, + :eigs, + :emptyITensor, + :enable_combine_contract!, + :enable_tblis!, + :energies, + :entropy, + :errorMPOprod, + :error_contract, + :error_mpoprod, + :error_mul, + :expect, + :factorize, + :filterinds, + :findfirstsiteind, + :findfirstsiteinds, + :findindex, + :findinds, + :findsite, + :findsites, + :firstind, + :firstintersect, + :firstsetdiff, + :firstsiteind, + :firstsiteinds, + :flux, + :fparity, + :get_cutoffs, + :get_maxdims, + :get_mindims, + :get_noises, + :getfirst, + :getindex, + :hadamard_product, + :has_fermion_string, + :hascommoninds, + :hasid, + :hasind, + :hasinds, + :hasplev, + :hasqns, + :hassameinds, + :hastags, + :id, + :ind, + :index_id_rng, + :inds, + :inner, + :insertblock!, + :isactive, + :isfermionic, + :ishermitian, + :isindequal, + :isortho, + :itensor, + :linkdim, + :linkdims, + :linkind, + :linkindex, + :linkinds, + :logdot, + :loginner, + :lognorm, + :lproj, + :lq, + :mapprime, + :mapprime!, + :matmul, + :matrix, + :maxdim, + :maxdim!, + :maxlinkdim, + :measure!, + :measurements, + :mindim, + :mindim!, + :modulus, + :movesite, + :movesites, + :mul, + :mul!, + :multMPO, + :multmpo, + :nblocks, + :nnz, + :nnzblocks, + :noise, + :noise!, + :noiseterm, + :noncommonind, + :noncommoninds, + :noprime, + :noprime!, + :norm, + :normalize, + :normalize!, + :not, + :nsite, + :nsweep, + :nullspace, + :nzblock, + :nzblocks, + :onehot, + :op, + :ops, + :order, + :orthoCenter, + :ortho_lims, + :orthocenter, + :orthogonalize, + :orthogonalize!, + :outer, + :permute, + :plev, + :polar, + :pop, + :popfirst, + :position!, + :prime, + :prime!, + :primelinks!, + :product, + :productMPS, + :projector, + :promote_itensor_eltype, + :push, + :pushfirst, + :ql, + :qn, + :qr, + :randn!, + :randomITensor, + :randomMPO, + :randomMPS, + :readcpp, + :removeqn, + :removeqns, + :removetags, + :removetags!, + :replace_siteinds, + :replace_siteinds!, + :replacebond, + :replacebond!, + :replaceind, + :replaceind!, + :replaceindex!, + :replaceinds, + :replaceinds!, + :replaceprime, + :replacesites!, + :replacetags, + :replacetags!, + :reset_ortho_lims!, + :reset_warn_order!, + :rmul!, + :rproj, + :rq, + :sample, + :sample!, + :scalar, + :scale!, + :set_leftlim!, + :set_ortho_lims!, + :set_rightlim!, + :set_warn_order!, + :setcutoff!, + :setdir, + :setelt, + :setindex, + :setmaxdim!, + :setmindim!, + :setnoise!, + :setprime, + :setprime!, + :setspace, + :settags, + :settags!, + :sim, + :sim!, + :simlinks!, + :siteind, + :siteindex, + :siteinds, + :space, + :splitblocks, + :square_lattice, + :state, + :storage, + :store, + :sum, + :svd, + :swapbondsites, + :swapind, + :swapinds, + :swapinds!, + :swapprime, + :swapprime!, + :swaptags, + :swaptags!, + :sweepnext, + :tags, + :tensors, + :toMPO, + :totalqn, + :tr, + :transpose, + :triangular_lattice, + :truncate, + :truncate!, + :truncerror, + :truncerrors, + :unionind, + :unioninds, + :unique_siteind, + :unique_siteinds, + :uniqueind, + :uniqueindex, + :uniqueinds, + :use_combine_contract, + :use_debug_checks, + :val, + :vector, + :δ, + :⊕, + :⊙, + :⋅, +] +end