Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default maxdim value in rand MPS and MPO constructor #263

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/MPS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -288,14 +288,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
Expand Down Expand Up @@ -330,14 +330,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
Expand Down
Loading