Skip to content

Conversation

@ebelnikola
Copy link
Contributor

Hi!

I encountered an issue with automatic differentiation. When I tried to differentiate a piece of code that involved taking multiple traces of a single tensor, I got an error. Here is a minimal failing example:

using TensorOperations
using Zygote

A = rand(2, 2, 2, 2)

function tst(x)
    @tensoropt res = x[1, 1, 2, 2]
    return sum(res)
end

withgradient(tst, A)

The issue was in the _kron function, which had a typo in the argument order for the call to tensorproduct.

This PR fixes the issue and adds a test to "ad.jl" to verify that the tensortrace! rrule works correctly when taking more than one trace.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 22, 2026

Your PR no longer requires formatting changes. Thank you for your contribution!

@lkdvos
Copy link
Member

lkdvos commented Jan 22, 2026

Thank you so much for the report as well as the fix, this is enormously appreciated!
I took the liberty of quickly running the formatter (we've switched to using Runic.jl these days), but otherwise this looks great and will merge as soon as tests pass.

@lkdvos lkdvos enabled auto-merge (squash) January 22, 2026 12:30
@ebelnikola
Copy link
Contributor Author

Thanks!

@codecov
Copy link

codecov bot commented Jan 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
src/utils.jl 100.00% <100.00%> (+100.00%) ⬆️

... and 30 files with indirect coverage changes

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

@lkdvos lkdvos merged commit 903d650 into QuantumKitHub:master Jan 22, 2026
13 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.

2 participants