Skip to content

TruncationStrategy does not accept space #400

Open

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], 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)  # 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.

Activity

  1. lkdvos commented on Apr 13, 2026

    @lkdvos
    Member

    I think this could be fixed if we rework the TruncationStrategy structs to be similar to Algorithm{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?

  2. ogauthe commented on Apr 13, 2026

    @ogauthe
    ContributorAuthor

    I was able to solve the issue by explicitly constructing the TruncationStrategy myself, 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions