Skip to content

fix: exponential method ambiguity resolutions#253

Merged
Jutho merged 9 commits into
QuantumKitHub:mainfrom
sanderdemeyer:exp_new
Jul 7, 2026
Merged

fix: exponential method ambiguity resolutions#253
Jutho merged 9 commits into
QuantumKitHub:mainfrom
sanderdemeyer:exp_new

Conversation

@sanderdemeyer

@sanderdemeyer sanderdemeyer commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

This is another type restriction (see #252) to make sure the exponential in TensorKit will be implemented correctly (see QuantumKitHub/TensorKit.jl#465). If I don't restrict these types, it will be ambiguous with this function in TensorKit (src/factorizations/matrixalgebrakit.jl).

for f! in (
        :qr_null!, :lq_null!,
        :svd_vals!, :eig_vals!, :eigh_vals!,
        :project_hermitian!, :project_antihermitian!, :project_isometric!,
        :exponential!,
    )
    @eval function MAK.$f!(t::AbstractTensorMap, N, alg::AbstractAlgorithm)
        $(f! in (:eig_vals!, :eigh_vals!, :project_hermitian!, :project_antihermitian!) && :(LinearAlgebra.checksquare(t)))
        foreachblock(t, N) do _, (tblock, Nblock)
            Nblock′ = $f!(tblock, Nblock, alg)
            # deal with the case where the output is not the same as the input
            Nblock === Nblock′ || copy!(Nblock, Nblock′)
            return nothing
        end
        return N
    end
end

@lkdvos lkdvos left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did a quick search throughout the codebase, and it seems like except for svd_compact, we always combine DiagonalAlgorithm with AbstractMatrix, so this is consistent with most of it.

Comment thread src/implementations/exponential.jl Outdated
@codecov

codecov Bot commented Jul 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 63.15789% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/implementations/exponential.jl 75.00% 4 Missing ⚠️
src/interface/exponential.jl 0.00% 3 Missing ⚠️
Files with missing lines Coverage Δ
src/interface/exponential.jl 0.00% <0.00%> (ø)
src/implementations/exponential.jl 94.52% <75.00%> (-5.48%) ⬇️

... and 23 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/implementations/exponential.jl Outdated
Co-authored-by: Lukas Devos <ldevos98@gmail.com>
@Jutho

Jutho commented Jul 5, 2026

Copy link
Copy Markdown
Member

There are still ambiguities currently. Also, I do think the current these specializations invalidate some of the discussions we had previously, e.g. regarding map_diagonal vs broadcasting.

@sanderdemeyer

Copy link
Copy Markdown
Contributor Author

These ambiguities should now be removed. It is indeed a bit strange that we're specialising these methods, when we indeed wanted to keep them general and not use broadcasting. I think it was probably still the right choice, even if we restrict some of the methods here.

@lkdvos lkdvos changed the title restrict types diagonal fix: exponential method ambiguity resolutions Jul 6, 2026

@lkdvos lkdvos left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a slight change to the implementation to remain consistent with the decompositions - we are now never specializing the out arguments, and only using input::AbstractMatrix. I'm not saying this is really the best solution, and I agree that it is unfortunate we can't (yet?) handle this in a more satisfactory way, but barring the option to actually fully solve this right now, which I think will take a substantial refactor, I would vote to just keep this consistent with the decompositions, where this problem is also present.

@lkdvos lkdvos requested a review from Jutho July 7, 2026 16:48
@Jutho Jutho merged commit 4443df0 into QuantumKitHub:main Jul 7, 2026
46 of 49 checks passed
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

Successfully merging this pull request may close these issues.

3 participants