-
Notifications
You must be signed in to change notification settings - Fork 42
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
Confusing/bugged? index convention for braiding tensors. #93
Comments
Some further info : (sealion, nightingale) = (numout(T), numin(T))
numout(T) == 1 && (TensorKit.numin)(T) == 1 || throw(TensorOperations.IndexError("incorrect number of input-output indices: (1, 1) instead of " * string((sealion, nightingale)) * " for T."))
(dugong, fish) = (numout(B), numin(B))
numout(B) == 1 && (TensorKit.numin)(B) == 1 || throw(TensorOperations.IndexError("incorrect number of input-output indices: (1, 1) instead of " * string((dugong, fish)) * " for B."))
weasel = TensorKit.BraidingTensor(space(B, 1), (space(B, 2))') #this is tau2 ##To get this to work correctly we need to replace space(B, 1) with space(B, 1)' !
vicuña = TensorKit.BraidingTensor(space(B, 1), (space(B, 2))') #this is tau1
#define the scalartype of the contracted thing
porpoise = TensorOperations.promote_contract(TensorOperations.scalartype(weasel), TensorOperations.scalartype(T))
#contract tau2=weasel with T
heron = TensorOperations.tensoralloc_contract(porpoise, ((1, 2), ()), weasel, ((1, 2), (3, 4)), :N, T, ((2, 1), ()), :N, false)
heron = TensorKit._planarcontract!(heron, ((1, 2), ()), weasel, ((1, 2), (3, 4)), T, ((2, 1), ()), One(), Zero())
#again find the correct scalartype
okapi = TensorOperations.promote_contract(TensorOperations.scalartype(B), TensorOperations.scalartype(vicuña))
#contract tau1=vicuña with B
antelope = TensorOperations.tensoralloc_contract(okapi, ((), (2, 1)), B, ((), (1, 2)), :N, vicuña, ((3, 1), (2, 4)), :N, false)
antelope = TensorKit._planarcontract!(antelope, ((), (2, 1)), B, ((), (1, 2)), vicuña, ((3, 1), (2, 4)), One(), Zero())
#again find the correct scalartype
alpaca = TensorOperations.promote_contract(TensorOperations.scalartype(antelope), TensorOperations.scalartype(heron))
#contract T*tau and B*tau
monkey = TensorOperations.tensoralloc_contract(alpaca, ((), ()), antelope, ((), (1, 2)), :N, heron, ((1, 2), ()), :N, false)
monkey = TensorKit._planarcontract!(monkey, ((), ()), antelope, ((), (1, 2)), heron, ((1, 2), ()), One(), Zero())
#we don't need T*tau and B*tau anymore, free them up from memory !
TensorOperations.tensorfree!(antelope)
TensorOperations.tensorfree!(heron)
#free and typeset all other things.
rabbit = TensorOperations.scalartype(monkey)
cattle = TensorOperations.tensoralloc_add(rabbit, ((), ()), monkey, :N, true)
cattle = TensorKit._planaradd!(cattle, ((), ()), monkey, One(), Zero())
TensorOperations.tensorfree!(monkey)
lion = TensorOperations.tensorscalar(cattle)
TensorOperations.tensorfree!(cattle)
d = lion Which leads to a spacemismatch because weasel=tau2 has incorrectly inferred spaces ! Indeed, we can make the generated code run fie by replacing I think that the problem lies within the _construct_braidingtensors(ex::Expr) function. It seems to correctly infers which spaces are associated to the various tau tensors but then still constructs a braiding tensor with the wrong spaces. I can't figure out how to patch this though. |
hmm, that's interesting. I think it should have pulled the spaces for |
@lkdvos, I went trought the code a bit and I think it correctly recognizes where to pull the spaces from but it doesn't seem to know if they should be conjugate or not. Thanks for looking into it ! |
previously constructed indexmap, but this is ambiguous if an index appears on multiple braidingtensors. This should now be fixed by contructing braidingtensors independently. Fixes #93
This should be fixed and tagged as of v0.12.1 |
For the following contraction : To be fair this is not really problematic but is there any change the opt=true interferes with automatic differentiation as this would pose a problem later down the line... |
The This should not be relevant for automatic differentiation, but is definitely highly relevant for performance. In particular, at a later stage you might even want to consider specifying which indices are large, and which are not |
Thanks for your swift response ! How would this lead to a non planar diagram ? All crossings have been eliminated with tau tensors so I don't see how this is affected by the order of contraction. I could see that the order is ill defined due to my usage of names like w1, w2, W1, W2 etc but this doesn't seem to bother other contractions in in my code. |
Consider the following diagram, and compare contracting orders: @planar D[-1; -2] := A[-1; a b c] * B[b; b'] * C[a b' c; -2] In particular, any order starting with contracting index In this case however, because you're not using NCON index notation, but rather just the letters, @planar D[-1; -2] := (A[-1; a b c] * B[b; b']) * C[a b' c; -2] which would work, however this would not: @planar D[-1; -2] := (A[-1; a b c] * C[a b' c; -2]) * B[b; b']) |
As an aside, I am not sure if the "optimal" contraction order is guaranteed to be planar (I honestly don't think it is), but at least intuitively it feels like the example above would be less likely to occur in an optimal contraction path. |
Meaning that it has to permute A and C to be next to each other and that it introduces crossings by doing so ? |
Ok, that clarifies it ! Thank you ! |
In the following code, which contracts two tensors in various ways depicted below, I'd expect all diagrams to be equivalent.
Nevertheless I get a
spacemismatch
for d-type diagram for reasons that totally evade me. I'm not sure if this is intended behavior or a bug but either way I think it deserves clarification.Resulting error for the d-type diagram :
The text was updated successfully, but these errors were encountered: