From a82f60ec3bb4782fe4104d76063bc6ac10d74b6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jofre=20Vall=C3=A8s=20Muns?= <61060572+jofrevalles@users.noreply.github.com> Date: Mon, 2 Dec 2024 14:06:11 +0100 Subject: [PATCH] Add default maxdim value in rand MPS and MPO constructor (#263) --- src/MPS.jl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/MPS.jl b/src/MPS.jl index c5dfd8ac..e56f7894 100644 --- a/src/MPS.jl +++ b/src/MPS.jl @@ -289,14 +289,14 @@ center at the first site). In order to avoid norm explosion issues, the tensors # Keyword Arguments - `n` The number of sites. - - `maxdim` The maximum bond dimension. + - `maxdim` The maximum bond dimension. If it is `nothing`, the maximum bond dimension increases exponentially with the number of sites up to `physdim^(n ÷ 2)`. - `eltype` The element type of the tensors. Defaults to `Float64`. - `physdim` The physical or output dimension of each site. Defaults to 2. """ -function Base.rand(rng::Random.AbstractRNG, ::Type{MPS}; n, maxdim, eltype=Float64, physdim=2) +function Base.rand(rng::Random.AbstractRNG, ::Type{MPS}; n, maxdim=nothing, eltype=Float64, physdim=2) p = physdim T = eltype - χ = maxdim + χ = isnothing(maxdim) ? p^(n ÷ 2) : maxdim arrays::Vector{AbstractArray{T,N} where {N}} = map(1:n) do i χl, χr = let after_mid = i > n ÷ 2, i = (n + 1 - abs(2i - n - 1)) ÷ 2 @@ -331,14 +331,14 @@ In order to avoid norm explosion issues, the tensors are orthogonalized by QR fa # Keyword Arguments - `n` The number of sites. - - `maxdim` The maximum bond dimension. + - `maxdim` The maximum bond dimension. If it is `nothing`, the maximum bond dimension increases exponentially with the number of sites up to `(physdim^2)^(n ÷ 2)`. - `eltype` The element type of the tensors. Defaults to `Float64`. - `physdim` The physical or output dimension of each site. Defaults to 2. """ -function Base.rand(rng::Random.AbstractRNG, ::Type{MPO}; n, maxdim, eltype=Float64, physdim=2) +function Base.rand(rng::Random.AbstractRNG, ::Type{MPO}; n, maxdim=nothing, eltype=Float64, physdim=2) T = eltype ip = op = physdim - χ = maxdim + χ = isnothing(maxdim) ? (ip * op)^(n ÷ 2) : maxdim arrays::Vector{AbstractArray{T,N} where {N}} = map(1:n) do i χl, χr = let after_mid = i > n ÷ 2, i = (n + 1 - abs(2i - n - 1)) ÷ 2