Repository navigation
Open
Labels
Description
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], vd⊗vd←vd⊗vd)
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) # MethodErrorERROR: 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.
Activity
lkdvos commentedon Apr 13, 2026
I think this could be fixed if we rework the
TruncationStrategystructs to be similar toAlgorithm{Name}, but that is definitely a very breaking change. I do admit that it could be nice to have everything in a similar shape, but this might have to go a bit lower on the priority list (at least for me), since there are some other things that seem like they are more helpful/urgent.Just trying to capture maybe partially what you are after, is the point that you can't easily have the combination of a space and maxrank without using the "expert mode" constructors? Could we resolve this differently by allowing
truncspace(V) & (; maxrank = ..)or does that not really solve the issue?ogauthe commentedon Apr 13, 2026
I was able to solve the issue by explicitly constructing the
TruncationStrategymyself, this is more a feature request. It would be nice to be able to use the namedtuple call in all cases, but I understand it is too much work to be worth it.