-
Notifications
You must be signed in to change notification settings - Fork 1
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 index dimension mismatch in TensorNetwork
construction
#219
Conversation
@jofrevalles @mofeing the dimension mismatch seems to be fixed with the verification I implemented in julia> mps = Chain(State(), Open(), [rand(2, 3), rand(2, 6, 4), rand(2, 5)])
ERROR: DimensionMismatch: Index D has inconsistent dimension: [3, 6]
Stacktrace:
[1] TensorNetwork(tensors::Vector{Tensor{Float64, N, A} where {N, A<:AbstractArray{Float64, N}}})
@ Tenet ~/QuanticGit/Tenet.jl/src/TensorNetwork.jl:58
[2] Chain(::State, boundary::Open, arrays::Vector{Array{Float64}}; order::Tuple{Symbol, Symbol, Symbol})
@ Tenet ~/QuanticGit/Tenet.jl/src/Ansatz/Chain.jl:99
[3] Chain(::State, boundary::Open, arrays::Vector{Array{Float64}})
@ Tenet ~/QuanticGit/Tenet.jl/src/Ansatz/Chain.jl:63
[4] top-level scope
@ REPL[3]:1 Also, let me know if there's something else needed, specially with what you commented in the issue about the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, nice! Since we already have tests for @unsafe_region
, and these are passing, we can merge this!
Do you mind benchmarking with and without the safe guards / checks for some large TNs? Like 100-1000 tensors |
Co-authored-by: Sergio Sánchez Ramírez <[email protected]>
I benchmarked for Without the indices safe region: julia> @benchmark tn = rand(TensorNetwork, 1000, 3)
BenchmarkTools.Trial: 88 samples with 1 evaluation.
Range (min … max): 17.460 ms … 560.275 ms ┊ GC (min … max): 0.00% … 12.05%
Time (median): 25.241 ms ┊ GC (median): 2.20%
Time (mean ± σ): 56.874 ms ± 82.945 ms ┊ GC (mean ± σ): 22.67% ± 24.72%
█▅▁
█████▅▁▅▁▁▅▆▆▅▇▅▁▁▅▁▆▁▁▁▁▁▅▁▁▁▁▁▁▁▁▁▅▁▁▁▅▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▅ ▁
17.5 ms Histogram: log(frequency) by time 407 ms <
Memory estimate: 25.09 MiB, allocs estimate: 64188. With the indices safe region: julia> @benchmark tn = rand(TensorNetwork, 1000, 3)
BenchmarkTools.Trial: 89 samples with 1 evaluation.
Range (min … max): 23.384 ms … 505.261 ms ┊ GC (min … max): 0.00% … 15.44%
Time (median): 30.132 ms ┊ GC (median): 0.00%
Time (mean ± σ): 61.098 ms ± 85.135 ms ┊ GC (mean ± σ): 12.13% ± 14.75%
█▃ ▁
████▇█▁▅▁▇▁▁▁▆▁▁▆▅▁▁▁▁▁▁▁▁▁▁▁▅▅▁▁▁▁▁▁▁▁▁▁▅▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▅ ▁
23.4 ms Histogram: log(frequency) by time 485 ms <
Memory estimate: 28.02 MiB, allocs estimate: 103174. Correct me if I am wrong, but as regularity may influence the times, I would just look at the minimum time: Without the checks |
@mofeing Another benchmark for Using checks: julia> @benchmark tn = rand(TensorNetwork, 200, 3)
BenchmarkTools.Trial: 400 samples with 1 evaluation.
Range (min … max): 2.218 ms … 253.500 ms ┊ GC (min … max): 0.00% … 23.87%
Time (median): 3.163 ms ┊ GC (median): 0.00%
Time (mean ± σ): 12.499 ms ± 28.164 ms ┊ GC (mean ± σ): 31.62% ± 21.23%
█▄▁
███▇▅▆▅▅▅▄▅▅▅▅▄▅▁▅▁▁▄▄▁▁▁▄▁▁▁▄▄▆▁▁▅▆▁▅▁▄▁▄▄▁▄▁▅▁▁▁▁▁▁▁▄▁▄▁▄▄ ▆
2.22 ms Histogram: log(frequency) by time 129 ms <
Memory estimate: 2.80 MiB, allocs estimate: 19763. Wiithout checks: julia> @benchmark tn = rand(TensorNetwork, 200, 3)
BenchmarkTools.Trial: 353 samples with 1 evaluation.
Range (min … max): 1.240 ms … 1.031 s ┊ GC (min … max): 0.00% … 0.32%
Time (median): 2.028 ms ┊ GC (median): 0.00%
Time (mean ± σ): 14.150 ms ± 65.195 ms ┊ GC (mean ± σ): 30.34% ± 22.77%
█
██▅▆▄▅▅▁▁▄▁▁▁▁▄▅▅▅▄▆▄▆▁▁▁▄▁▄▁▁▁▁▄▁▁▁▁▁▄▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▄ ▅
1.24 ms Histogram: log(frequency) by time 222 ms <
Memory estimate: 2.84 MiB, allocs estimate: 11968. Min. time: Checks |
Thanks!
Well, the min time can also be affected by jitter so I would take the mean which means there is a 20% increase in runtime... but it's still 25ms which is ok. |
Closes #155