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

contract() should accept a Chain as input #183

Closed
starsfordummies opened this issue Aug 12, 2024 · 3 comments
Closed

contract() should accept a Chain as input #183

starsfordummies opened this issue Aug 12, 2024 · 3 comments
Milestone

Comments

@starsfordummies
Copy link
Contributor

currently I'm getting

contract(sergio_mps)
ERROR: MethodError: no method matching getindex(::Chain, ::Symbol, ::Symbol)

quick workaround to return a tensor is to just

Tenet.contract(mps::Chain) = contract(TensorNetwork(mps))

but if we want to reuse the indices, I came up with something like

 Dense(Quantum(TensorNetwork([contract(TensorNetwork(sergio_mps))]), sergio_mps.super.sites))

oh my

@starsfordummies starsfordummies changed the title contract!() should accept a Chain as input contract() should accept a Chain as input Aug 12, 2024
@mofeing
Copy link
Member

mofeing commented Aug 13, 2024

contract on Chain should be now fixed in the PR but... what is the last thing you're trying to achieve? Converting a MPS into a Dense representation? Why?

@starsfordummies
Copy link
Contributor Author

oh I just thought if it works for a TN, then it should also work for an MPS - it could even be useful for some benchmark at some point
( I'd probably even put a warning when trying to do it with more than 10 legs or so)

@mofeing mofeing added this to the 0.8 milestone Aug 14, 2024
@mofeing
Copy link
Member

mofeing commented Aug 14, 2024

Closing because this works with the latest PR #172

julia> using Tenet
Precompiling Tenet
  1 dependency successfully precompiled in 3 seconds. 50 already precompiled.
[ Info: Precompiling TenetChainRulesCoreExt [4c48fc49-ee8c-5c6e-a164-94f373290340]

julia> mps = rand(Chain, Open, State; n=5, p=2, χ=20)
MPS (inputs=0, outputs=5)

julia> contract(mps)
2×2×2×2×2 Tensor{Float64, 5, Array{Float64, 5}}:
[:, :, 1, 1, 1] =
 -0.476082  -0.530897
 -0.108129  -0.212065

[:, :, 2, 1, 1] =
 -0.315495  -0.115779
 -0.076073  -0.0214035

[:, :, 1, 2, 1] =
 -0.117174   -0.167136
 -0.0260362   0.0109016

[:, :, 2, 2, 1] =
 -0.154203   -0.127011
 -0.0392941  -0.0132862

[:, :, 1, 1, 2] =
 0.0589333   0.00149326
 0.0189144  -0.0870499

[:, :, 2, 1, 2] =
 0.165494    0.230064
 0.0127105  -0.00592115

[:, :, 1, 2, 2] =
 0.113758   -0.0558552
 0.0175383   0.0481059

[:, :, 2, 2, 2] =
 0.163475   0.246799
 0.0260987  0.180637

@mofeing mofeing closed this as completed Aug 14, 2024
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

No branches or pull requests

2 participants