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

Bug: Dimension mismatch when slicing some bonds #58

Open
brenjohn opened this issue Feb 14, 2022 · 1 comment
Open

Bug: Dimension mismatch when slicing some bonds #58

brenjohn opened this issue Feb 14, 2022 · 1 comment

Comments

@brenjohn
Copy link
Member

brenjohn commented Feb 14, 2022

I came across an example of a dsl file where slicing 4 bonds works fine but slicing 5 bonds gives the following error:

ERROR: LoadError: BoundsError: attempt to access 2-element Vector{ComplexF32} at index [3:3]
Stacktrace:
 [1] throw_boundserror(A::Vector{ComplexF32}, I::Tuple{UnitRange{Int64}})
   @ Base ./abstractarray.jl:691
 [2] checkbounds
   @ ./abstractarray.jl:656 [inlined]
 [3] view(A::Vector{ComplexF32}, I::UnitRange{Int64})
   @ Base ./subarray.jl:177
 [4] macro expansion
   @ ~/Code/QXContexts/QXContexts.jl/src/contexts/base.jl:115 [inlined]

I've checked with both QXContexts versions on master and simulation-refactor branches and the issue exists in both. It's not clear to me what's causing the issue yet. I've added the example dsl files here. Running the following should reproduce the error:

using QXContexts

dsl_file   = "./examples/sycamore/sycamore_53_4_0.qx"
data_file  = "./examples/sycamore/sycamore_53_4_0.jld2"

cg, _ = parse_dsl_files(dsl_file, data_file)
ctx = QXContext{Array{ComplexF32}}(cg)

bitstring = [true for _ in 1:53]

slice_params = params(cg, ViewCommand)
num_slices = 5
dims = map(x -> slice_params[Symbol("v$(x)")]::Int, 1:num_slices)
slices = CartesianIndices(Tuple(dims))
slice = slices[65] # using slice[64] works

ctx(bitstring, slice)
@nmoran
Copy link
Member

nmoran commented Feb 21, 2022

Issue here is that it's trying to slice a bond of dimension 2 with bond value 3. When calling set_slice_vals! the order of the values is not v1, v2, v3 etc... (as it does not care what format the symbols take). It is the order in which these appear in the slice_dims OrderedDict data member of QXContexts (whose order depends on the order of traversal when constructing the QXContexts struct from the compute graph).

The above example will run if updated to

using QXContexts

dsl_file   = "./examples/sycamore/sycamore_53_4_0.qx"
data_file  = "./examples/sycamore/sycamore_53_4_0.jld2"

cg, _ = parse_dsl_files(dsl_file, data_file)
ctx = QXContext{Array{ComplexF32}}(cg)

bitstring = [true for _ in 1:53]

slice_params = params(cg, ViewCommand)
num_slices = 5
dims = collect(values(ctx.slice_dims))[1:num_slices]
slices = CartesianIndices(Tuple(dims))
slice = slices[65] # using slice[64] works

ctx(bitstring, slice)

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