-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Adapt which enables converting tensor networks to GPU (…
…#187) * Add support for Adapt which enables converting tensor networks to GPU * Bump to v0.11.13
- Loading branch information
Showing
5 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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,14 @@ | ||
module ITensorNetworksAdaptExt | ||
using Adapt: Adapt, adapt | ||
using ITensorNetworks: AbstractITensorNetwork, map_vertex_data_preserve_graph | ||
function Adapt.adapt_structure(to, tn::AbstractITensorNetwork) | ||
# TODO: Define and use: | ||
# | ||
# @preserve_graph map_vertex_data(adapt(to), tn) | ||
# | ||
# or just: | ||
# | ||
# @preserve_graph map(adapt(to), tn) | ||
return map_vertex_data_preserve_graph(adapt(to), tn) | ||
end | ||
end |
This file contains 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 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,5 @@ | ||
[deps] | ||
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" | ||
ITensorNetworks = "2919e153-833c-4bdc-8836-1ea460a35fc7" | ||
ITensors = "9136182c-28ba-11e9-034c-db9fb085ebd5" | ||
NamedGraphs = "678767b0-92e7-4007-89e4-4527a8725b19" |
This file contains 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,23 @@ | ||
@eval module $(gensym()) | ||
using Adapt: Adapt, adapt | ||
using NamedGraphs.NamedGraphGenerators: named_grid | ||
using ITensorNetworks: random_tensornetwork, siteinds | ||
using ITensors: ITensors | ||
using Test: @test, @testset | ||
|
||
struct SinglePrecisionAdaptor end | ||
single_precision(::Type{<:AbstractFloat}) = Float32 | ||
single_precision(type::Type{<:Complex}) = complex(single_precision(real(type))) | ||
Adapt.adapt_storage(::SinglePrecisionAdaptor, x) = single_precision(eltype(x)).(x) | ||
|
||
@testset "Test ITensorNetworksAdaptExt (eltype=$elt)" for elt in ( | ||
Float32, Float64, Complex{Float32}, Complex{Float64} | ||
) | ||
g = named_grid((2, 2)) | ||
s = siteinds("S=1/2", g) | ||
tn = random_tensornetwork(elt, s) | ||
@test ITensors.scalartype(tn) === elt | ||
tn′ = adapt(SinglePrecisionAdaptor(), tn) | ||
@test ITensors.scalartype(tn′) === single_precision(elt) | ||
end | ||
end |
b4659b9
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.
@JuliaRegistrator register
b4659b9
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.
Registration pull request created: JuliaRegistries/General/107974
Tip: Release Notes
Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.
To add them here just re-invoke and the PR will be updated.
Tagging
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: