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

Wrong indices orders after optimization with SABipartite #31

Closed
ChenZhao44 opened this issue Jun 11, 2022 · 2 comments · Fixed by #32
Closed

Wrong indices orders after optimization with SABipartite #31

ChenZhao44 opened this issue Jun 11, 2022 · 2 comments · Fixed by #32

Comments

@ChenZhao44
Copy link
Collaborator

Version information:

  • Julia v1.7.3
  • OMEinsum v0.6.13
  • OMEinsumContractionOrders v0.6.8

Example:

using OMEinsum, OMEinsumContractionOrders
using Test

function z_tensor(n, α)
    t = zeros(ComplexF64, 1<<n)
    t[1] = 1
    t[end] = exp(im*α)
    return reshape(t, fill(2, n)...)
end

function x_gate()
    return ComplexF64[0 1; 1 0]
end

ec = EinCode([[1,2,3,4], [2,5], [3,6], [4,7]], [5,6,7,1])
ts = [z_tensor(4, pi), x_gate(), x_gate(), x_gate()]
ec_opt = optimize_code(ec, uniformsize(ec, 2), SABipartite())
@test ec(ts...)[:]  ec_opt(ts...)[:] # error
@GiggleLiu
Copy link
Member

julia> ec = EinCode([[1,2,3,4], [2,5], [3,6], [4,7]], [5,6,7,1])
1234, 25, 36, 47 -> 5671

julia> ec_opt = optimize_code(ec, uniformsize(ec, 2), SABipartite())
1375, 36 -> 1567
├─ 36
└─ 1237, 25 -> 1375
   ├─ 25
   └─ 1234, 47 -> 1237
      ├─ 47
      └─ 1234

The problem is caused by the incorrect permutation in the output. I will fix it ASAP. Thanks for the issue!

@GiggleLiu GiggleLiu mentioned this issue Jun 11, 2022
@GiggleLiu
Copy link
Member

GiggleLiu commented Jun 11, 2022

It is a single line fix. This issue happens only in a very rare case. So you do not need to worry about the correctness of your previous result if it does not fall into the following category:

  • You use KaHyParBipartite or SABiPartite, and the problem scale is small (default: number of tensors <= 40) such that there is only one valid partition.

I would suggest use TreeSA in most cases, with proper hyper-parameters, this one usually gives the best contraction order. And this one is the most tested one is practise.

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 a pull request may close this issue.

2 participants