-
Notifications
You must be signed in to change notification settings - Fork 47
Changes for non-CPU array support #375
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
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
011f496
Changes for non-CPU array support
kshyatt 2c66082
Set algo
kshyatt 3ad5f04
More dumb fixes
kshyatt ee113fa
More stuff working
kshyatt 6790f37
Another fix and no sources needed
kshyatt b8169a9
One more try
kshyatt e428a7e
Enable more tests
kshyatt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| using .TestSetup | ||
| using Test, TestExtras | ||
| using MPSKit | ||
| using MPSKit: GeometryStyle, FiniteChainStyle, InfiniteChainStyle, OperatorStyle, MPOStyle | ||
| using TensorKit | ||
| using MatrixAlgebraKit | ||
| using TensorKit: ℙ, tensormaptype, TensorMapWithStorage | ||
| using Adapt, CUDA, cuTENSOR | ||
|
|
||
| # TODO revisit this once https://github.com/QuantumKitHub/MatrixAlgebraKit.jl/issues/176 | ||
| # is resolved | ||
| MPSKit.Defaults.alg_svd() = CUSOLVER_QRIteration() | ||
|
|
||
| @testset "CuFiniteMPO" for V in (ℂ^2, U1Space(0 => 1, 1 => 1)) | ||
| # start from random operators | ||
| L = 4 | ||
| T = ComplexF64 | ||
|
|
||
| O₁ = rand(T, V^L, V^L) | ||
| O₂ = rand(T, space(O₁)) | ||
| O₃ = rand(real(T), space(O₁)) | ||
|
|
||
| dO₁ = adapt(CuArray, O₁) | ||
| dO₂ = adapt(CuArray, O₂) | ||
| dO₃ = adapt(CuArray, O₃) | ||
|
|
||
| mpo₁ = adapt(CuVector{T, CUDA.DeviceMemory}, FiniteMPO(O₁)) | ||
| mpo₂ = adapt(CuVector{T, CUDA.DeviceMemory}, FiniteMPO(O₂)) | ||
| mpo₃ = adapt(CuVector{T, CUDA.DeviceMemory}, FiniteMPO(O₃)) | ||
|
|
||
| @test isfinite(mpo₁) | ||
| @test isfinite(typeof(mpo₁)) | ||
| @test GeometryStyle(typeof(mpo₁)) == FiniteChainStyle() | ||
| @test GeometryStyle(mpo₁) == FiniteChainStyle() | ||
| @test OperatorStyle(typeof(mpo₁)) == MPOStyle() | ||
| @test TensorKit.storagetype(mpo₁) == CuVector{T, CUDA.DeviceMemory} | ||
| @test TensorKit.storagetype(mpo₂) == CuVector{T, CUDA.DeviceMemory} | ||
| @test TensorKit.storagetype(mpo₃) == CuVector{T, CUDA.DeviceMemory} | ||
|
|
||
| @test @constinferred physicalspace(mpo₁) == fill(V, L) | ||
| Vleft = @constinferred left_virtualspace(mpo₁) | ||
| Vright = @constinferred right_virtualspace(mpo₂) | ||
| for i in 1:L | ||
| @test Vleft[i] == left_virtualspace(mpo₁, i) | ||
| @test Vright[i] == right_virtualspace(mpo₁, i) | ||
| end | ||
|
|
||
| TM = TensorMap | ||
| @test convert(TM, mpo₁) ≈ dO₁ | ||
| @test convert(TM, -mpo₂) ≈ -dO₂ | ||
| @test convert(TM, @constinferred complex(mpo₃)) ≈ complex(dO₃) | ||
|
|
||
| # test scalar multiplication | ||
| α = rand(T) | ||
| @test convert(TM, α * mpo₁) ≈ α * dO₁ | ||
| @test convert(TM, mpo₁ * α) ≈ dO₁ * α | ||
| @test α * mpo₃ ≈ α * complex(mpo₃) atol = 1.0e-6 | ||
|
|
||
| # test addition and multiplication | ||
| @test convert(TM, mpo₁ + mpo₂) ≈ dO₁ + dO₂ | ||
| @test convert(TM, mpo₁ + mpo₃) ≈ dO₁ + dO₃ | ||
| @test convert(TM, mpo₁ * mpo₂) ≈ dO₁ * dO₂ | ||
| @test convert(TM, mpo₁ * mpo₃) ≈ dO₁ * dO₃ | ||
|
|
||
| # test application to a state | ||
| ψ₁ = adapt(CuArray, rand(T, domain(O₁))) | ||
| #ψ₂ = adapt(CuArray, rand(real(T), domain(O₂))) # not allowed due to cuTENSOR | ||
lkdvos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| mps₁ = adapt(CuArray, FiniteMPS(ψ₁)) | ||
| #mps₂ = adapt(CuArray, FiniteMPS(ψ₂)) | ||
|
|
||
| @test @constinferred GeometryStyle(mps₁, mpo₁, mps₁) == GeometryStyle(mps₁) | ||
|
|
||
| @test convert(TM, mpo₁ * mps₁) ≈ dO₁ * ψ₁ | ||
| @test mpo₁ * ψ₁ ≈ dO₁ * ψ₁ | ||
| @test convert(TM, mpo₃ * mps₁) ≈ dO₃ * ψ₁ | ||
| @test mpo₃ * ψ₁ ≈ dO₃ * ψ₁ | ||
| #@test convert(TM, mpo₁ * mps₂) ≈ dO₁ * ψ₂ | ||
| #@test mpo₁ * ψ₂ ≈ dO₁ * ψ₂ | ||
|
|
||
| @test dot(mps₁, mpo₁, mps₁) ≈ dot(ψ₁, dO₁, ψ₁) | ||
| @test dot(mps₁, mpo₁, mps₁) ≈ dot(mps₁, mpo₁ * mps₁) | ||
| # test conversion to and from mps | ||
| mpomps₁ = convert(FiniteMPS, mpo₁) | ||
| mpompsmpo₁ = convert(FiniteMPO, mpomps₁) | ||
|
|
||
| @test convert(FiniteMPO, mpomps₁) ≈ mpo₁ rtol = 1.0e-6 | ||
|
|
||
| @test dot(mpomps₁, mpomps₁) ≈ dot(mpo₁, mpo₁) | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| using MPSKit | ||
| using MPSKit: _transpose_front, _transpose_tail | ||
| using MPSKit: GeometryStyle, InfiniteChainStyle, TransferMatrix | ||
| using TensorKit | ||
| using TensorKit: ℙ | ||
| using Adapt, CUDA, cuTENSOR | ||
|
|
||
| @testset "CuMPS ($(sectortype(D)), $elt)" for (D, d, elt) in | ||
| [(ℙ^10, ℙ^2, ComplexF64), (Rep[U₁](1 => 3), Rep[U₁](0 => 1), ComplexF64)] | ||
| tol = Float64(eps(real(elt)) * 100) | ||
|
|
||
| ψ = adapt(CuArray, InfiniteMPS([rand(elt, D * d, D), rand(elt, D * d, D)]; tol)) | ||
| @test TensorKit.storagetype(ψ) == CuVector{ComplexF64, CUDA.DeviceMemory} | ||
| @test eltype(ψ) == eltype(typeof(ψ)) | ||
|
|
||
| for i in 1:length(ψ) | ||
| @plansor difference[-1 -2; -3] := ψ.AL[i][-1 -2; 1] * ψ.C[i][1; -3] - | ||
| ψ.C[i - 1][-1; 1] * ψ.AR[i][1 -2; -3] | ||
| @test norm(difference, Inf) < tol * 10 | ||
|
|
||
| @test l_LL(ψ, i) * TransferMatrix(ψ.AL[i], ψ.AL[i]) ≈ l_LL(ψ, i + 1) | ||
| @test l_LR(ψ, i) * TransferMatrix(ψ.AL[i], ψ.AR[i]) ≈ l_LR(ψ, i + 1) | ||
| @test l_RL(ψ, i) * TransferMatrix(ψ.AR[i], ψ.AL[i]) ≈ l_RL(ψ, i + 1) | ||
| @test l_RR(ψ, i) * TransferMatrix(ψ.AR[i], ψ.AR[i]) ≈ l_RR(ψ, i + 1) | ||
|
|
||
| @test TransferMatrix(ψ.AL[i], ψ.AL[i]) * r_LL(ψ, i) ≈ r_LL(ψ, i + 1) | ||
| @test TransferMatrix(ψ.AL[i], ψ.AR[i]) * r_LR(ψ, i) ≈ r_LR(ψ, i + 1) | ||
| @test TransferMatrix(ψ.AR[i], ψ.AL[i]) * r_RL(ψ, i) ≈ r_RL(ψ, i + 1) | ||
| @test TransferMatrix(ψ.AR[i], ψ.AR[i]) * r_RR(ψ, i) ≈ r_RR(ψ, i + 1) | ||
| end | ||
|
|
||
| L = rand(3:20) | ||
| ψ = adapt(CuArray, FiniteMPS(rand, elt, L, d, D)) | ||
| @test TensorKit.storagetype(ψ) == CuVector{ComplexF64, CUDA.DeviceMemory} | ||
| @test eltype(ψ) == eltype(typeof(ψ)) | ||
| ovl = dot(ψ, ψ) | ||
|
|
||
| @test ovl ≈ norm(ψ.AC[1])^2 | ||
|
|
||
| for i in 1:length(ψ) | ||
| @test ψ.AC[i] ≈ ψ.AL[i] * ψ.C[i] | ||
| @test ψ.AC[i] ≈ _transpose_front(ψ.C[i - 1] * _transpose_tail(ψ.AR[i])) | ||
| end | ||
|
|
||
| @test ComplexF64 == scalartype(ψ) | ||
| ψ = ψ * 3 | ||
| @test ovl * 9 ≈ norm(ψ)^2 | ||
| ψ = 3 * ψ | ||
| @test ovl * 9 * 9 ≈ norm(ψ)^2 | ||
|
|
||
| @test norm(2 * ψ + ψ - 3 * ψ) ≈ 0.0 atol = sqrt(eps(real(ComplexF64))) | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.