Skip to content

TruncationStrategy does not accept space #400

@ogauthe

Description

@ogauthe

TensorKit introduces a truncspace strategy that does not exist in parent library MatrixAlgebraKit. Unfortunately it cannot be used inside a NamedTuple as other truncations.

using TensorKit

vd = Vect[SU2Irrep](1//2 => 1)
sds = TensorMap([-3/4,1/4], vdvdvdvd)
maxrank = 2
trcsp = fuse(vd,vd)
nt1 = (;maxrank)
nt2 = (;maxrank, space=trcsp)
trunc = truncrank(maxrank) & truncspace(trcsp)

@show eigh_trunc(sds; trunc)  # Ok
@show eigh_trunc(sds; trunc = nt1)  # Ok
@show eigh_trunc(sds; trunc = nt2)  # MethodError
ERROR: MethodError: no method matching MatrixAlgebraKit.TruncationStrategy(; maxrank::Int64, space::GradedSpace{SU2Irrep, TensorKit.SortedVectorDict{SU2Irrep, Int64}})

Closest candidates are:
  MatrixAlgebraKit.TruncationStrategy(; atol, rtol, maxrank, minrank, maxerror, filter) got unsupported keyword argument "space"
   @ MatrixAlgebraKit ~/.julia/packages/MatrixAlgebraKit/x7OBV/src/interface/truncation.jl:37

Stacktrace:
 [1] kwerr(kw::@NamedTuple{maxrank::Int64, space::GradedSpace{SU2Irrep, TensorKit.SortedVectorDict{SU2Irrep, Int64}}}, args::Type)
   @ Base ./error.jl:165
 [2] select_truncation(trunc::@NamedTuple{maxrank::Int64, space::GradedSpace{SU2Irrep, TensorKit.SortedVectorDict{SU2Irrep, Int64}}})
   @ MatrixAlgebraKit ~/.julia/packages/MatrixAlgebraKit/x7OBV/src/algorithms.jl:261
 [3] select_algorithm(::typeof(eigh_trunc!), A::TensorMap{…}, alg::Nothing; trunc::@NamedTuple{}, kwargs::@Kwargs{})
   @ MatrixAlgebraKit ~/.julia/packages/MatrixAlgebraKit/x7OBV/src/interface/eigh.jl:197
 [4] #select_algorithm#191
   @ ~/.julia/packages/MatrixAlgebraKit/x7OBV/src/algorithms.jl:373 [inlined]
 [5] select_algorithm
   @ ~/.julia/packages/MatrixAlgebraKit/x7OBV/src/algorithms.jl:372 [inlined]
 [6] #eigh_trunc#188
   @ ~/.julia/packages/MatrixAlgebraKit/x7OBV/src/algorithms.jl:357 [inlined]

This is not easy to fix without type piracy. Indeed ElementarySpace is owned by TensorKit types, however the current call in MatrixAlgebraKit is TruncationStrategy(; trunc...). Unfortunately Julia does not dispatch on keyword argument.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions