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

Fix error throw in replace! #201

Merged
merged 2 commits into from
Sep 12, 2024
Merged

Fix error throw in replace! #201

merged 2 commits into from
Sep 12, 2024

Conversation

jofrevalles
Copy link
Member

This PR resolves #191, so now if we use replace! and it throws an error, we do not get any destructive problems.

Example

julia> using Tenet

julia> psi = rand(Chain, Open, State; n=5, χ=8)
MPS (inputs=0, outputs=5)

julia> i2 = inds(tensors(psi, at=Site(2)))
3-element Vector{Symbol}: ...

julia> t2n_alt = Tensor(rand(2,2,10), i2)
2×2×10 Tensor{Float64, 3, Array{Float64, 3}}: ...

julia> size.(tensors(psi))
5-element Vector{Tuple{Int64, Int64, Vararg{Int64}}}:
 (2, 2)
 (2, 2, 4)
 (4, 2, 4)
 (4, 2, 2)
 (2, 2)

julia> replace!(psi, tensors(psi,at=Site(2)) => t2n_alt)
ERROR: DimensionMismatch: size(tensor,G)=10 but should be equal to size(tn,G)=4
Stacktrace:
 [1] push!(tn::TensorNetwork, tensor::Tensor{Float64, 3, Array{Float64, 3}})
   @ Tenet ~/git/Tenet.jl/src/TensorNetwork.jl:538
 [2] replace!(tn::Chain, pair::Pair{Tensor{Float64, 3, Array{Float64, 3}}, Tensor{Float64, 3, Array{Float64, 3}}})
   @ Tenet ~/git/Tenet.jl/src/TensorNetwork.jl:228
 [3] top-level scope
   @ REPL[6]:1

julia> size.(tensors(psi))
5-element Vector{Tuple{Int64, Int64, Vararg{Int64}}}:
 (2, 2)
 (2, 2, 4)
 (4, 2, 4)
 (4, 2, 2)
 (2, 2)

@jofrevalles jofrevalles merged commit db23164 into master Sep 12, 2024
6 checks passed
@jofrevalles jofrevalles deleted the fix/replace! branch September 12, 2024 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

replace(!)(::Chain, tensor => newtensor) only works for tensors of the same size
2 participants