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

Support conversion to/from ITensors.jl and ITensorNetworks.jl #200

Merged
merged 18 commits into from
Sep 11, 2024

Conversation

mofeing
Copy link
Member

@mofeing mofeing commented Sep 9, 2024

CC @JoeyT1994

To do

  •  Convert ITensor to Tensor
  • Convert Tensor to ITensor
  • Convert ITensorNetwork to TensorNetwork
  • Convert TensorNetwork to ITensorNetwork
  • Convert ITensorNetwork to Quantum
  • Convert Quantum to ITensorNetwork
  • Test conversions

@mofeing mofeing changed the title Support conversion to/from ITensors.jl Support conversion to/from ITensors.jl and ITensorNetworks.jl Sep 9, 2024
Copy link

codecov bot commented Sep 10, 2024

Codecov Report

Attention: Patch coverage is 0% with 24 lines in your changes missing coverage. Please review.

Project coverage is 72.46%. Comparing base (882049b) to head (50f5a4f).
Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
ext/TenetITensorsExt.jl 0.00% 14 Missing ⚠️
ext/TenetITensorNetworksExt.jl 0.00% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #200      +/-   ##
==========================================
- Coverage   72.73%   72.46%   -0.28%     
==========================================
  Files          27       31       +4     
  Lines        1944     1990      +46     
==========================================
+ Hits         1414     1442      +28     
- Misses        530      548      +18     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mofeing
Copy link
Member Author

mofeing commented Sep 10, 2024

@starsfordummies would you mind checking this conversions with some code of your own?

You can just activate a temporary environment and add this version of Tenet with

]add Tenet#integration-itensornetworks

@jofrevalles I've added a sites method to get the site associated to an index. Currently it uses findfirst to search through the dictionary, but maybe we could use a bidirectional dictionary if we can assure that the 2 sets (the sites and the physical indices) are isomorphic. One case where they aren't is open indices without any tensor connected to it; it's a very edgy case anyway.

@mofeing mofeing marked this pull request as ready for review September 10, 2024 21:20
@starsfordummies
Copy link
Contributor

I can test stuff, if you tell me what I should test!
I skimmed through the code, love how you decided to use convert() to make it impossible to find documentation 🦆

anyway, works for ITensor with data, breaks down with empty ITensor,

julia> a = random_itensor(Index(3),Index(4));
julia> at = convert(Tensor, a);   #works 

julia> a = ITensor(Index(3),Index(4))
ITensor ord=2 (dim=3|id=248) (dim=4|id=955)
NDTensors.EmptyStorage{NDTensors.EmptyNumber, NDTensors.Dense{NDTensors.EmptyNumber, Vector{NDTensors.EmptyNumber}}}

julia> at = convert(Tensor, a)
ERROR: StackOverflowError:

for MPS I don't know how to do it, with random attempts I was able to get it to do something but I don't know if that's the intended way

julia> psi = random_mps(siteinds("S=1/2", 10));

julia> tpsi = convert(Chain, psi)
ERROR: MethodError: Cannot `convert` an object of type ITensors.ITensorMPS.MPS to an object of type Chain
The function `convert` exists, but no method is defined for this combination of argument types.

julia> tpsi = convert(TensorNetwork, psi)
ERROR: MethodError: Cannot `convert` an object of type ITensors.ITensorMPS.MPS to an object of type TensorNetwork
The function `convert` exists, but no method is defined for this combination of argument types.

julia> tpsi = convert(Chain, psi.data)
ERROR: MethodError: Cannot `convert` an object of type Vector{ITensor} to an object of type Chain
The function `convert` exists, but no method is defined for this combination of argument types.


julia> tpsi = convert(TensorNetwork, psi.data)   # works 
TensorNetwork (#tensors=10, #inds=19)

@mofeing
Copy link
Member Author

mofeing commented Sep 11, 2024

I can test stuff, if you tell me what I should test! I skimmed through the code, love how you decided to use convert() to make it impossible to find documentation 🦆

ups, sorry 😬😅

anyway, works for ITensor with data, breaks down with empty ITensor,

julia> a = random_itensor(Index(3),Index(4));
julia> at = convert(Tensor, a);   #works 

julia> a = ITensor(Index(3),Index(4))
ITensor ord=2 (dim=3|id=248) (dim=4|id=955)
NDTensors.EmptyStorage{NDTensors.EmptyNumber, NDTensors.Dense{NDTensors.EmptyNumber, Vector{NDTensors.EmptyNumber}}}

julia> at = convert(Tensor, a)
ERROR: StackOverflowError:

this is... kind of expected. what can we do with sth that doesn't even have an eltype?

for MPS I don't know how to do it, with random attempts I was able to get it to do something but I don't know if that's the intended way

yeah, MPS is not yet supported because I haven't add support for ITensorMPS package, just for ITensors and ITensorNetworks

i will once we have refactored Chain to MPS and MPO

@mofeing mofeing merged commit 03a6ad1 into master Sep 11, 2024
6 checks passed
@mofeing mofeing deleted the integration-itensornetworks branch September 11, 2024 12:25
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.

2 participants