Skip to content

Possible bug in affine_transform_core #44

@MFrankenbach

Description

@MFrankenbach

I noticed that the following call to affine_transform_mpo results in a segmentation fault:

using ITensors
using Quantics

function main()
    A = [ 1 1;
        -1 1 ]
    b = [-32, 32]

    R = 6
    D = 2
    y_sites = [ Index(2, "d=$(d),r=$(r)") for d in 1:D for r in 1:R ]
    x_sites = prime.(y_sites)
        # using "new" indices doesn't help
    # x_sites = [ Index(2, "d=$(d),r=$(r)")' for d in 1:D for r in 1:R ]
    y_sites_mat = reshape(y_sites, R, D)
    x_sites_mat = reshape(x_sites, R, D)
    display(y_sites_mat)
    display(x_sites_mat)
    # CRASHES (segfault)
    trafo_mpo = Quantics.affine_transform_mpo(
        y_sites_mat,
        x_sites_mat,
        A,
        b,
        Quantics.OpenBoundaryConditions()
    )
end

main()

This is due to the use of @inbounds in affine_transform_core. Removing these gives the expected

**ERROR**: BoundsError: attempt to access 5×1×1 Array{Bool, 3} at index [1, 2, 1]

because bitrange has length 1 in this case.

Tentatively changing the line

    bitrange = activebit ? range(0, 1) : range(0, 0)

to

bitrange = range(0,1)

removes the bounds error, but causes the above script to be killed due to excess memory usage (~50 GB) on my Macbook Pro M1.

Julia version: 1.11.7
Branch/commit: main / 7c15521

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions