ITensor / ITensor/ITensorMPS.jl
[BUG] ChainRule for norm function
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 85
- Forks
- 27
- Avg merge
- 22m
- Merged PRs (30d)
- 1
Description
Description of bug
Using AD to differentiate the norm gives error: "MethodError: Cannot convert an object of type ChainRulesCore.Tangent{Any, @NamedTuple{data::Vector{Any}, llim::ChainRulesCore.ZeroTangent, rlim::ChainRulesCore.ZeroTangent}} to an object of type MPS"
Minimal code demonstrating the bug or unexpected behavior
Minimal runnable code
using ITensors, ITensorMPS
using LinearAlgebra
using Zygote
function randhaar(s1,s2)
U = reshape(Matrix(qr(rand(ComplexF64,4,4)).Q),2,2,2,2)
return ITensor(U,s1,s2,s1',s2')
end
N = 6
d = 2
sites = siteinds(d,N)
M = randomMPS(sites,2)
function F(us::Vector{ITensor})
return norm(apply(us,M))
end
us = ITensor[randhaar(s1,s2) for (s1,s2) in zip(sites[1:end-1],sites[2:end])]
#F(us) ≈ 1
gradient(F,us) #fails
Expected output or behavior
Using the function inner instead of norm works, so the problem is probably the rrule for norm
Version information
~/.julia/environments/v1.10/Project.toml
⌃ [082447d4] ChainRules v1.71.0
[d360d2e6] ChainRulesCore v1.25.0
⌃ [0d1a4710] ITensorMPS v0.3.1
⌃ [9136182c] ITensors v0.7.3
⌃ [e88e6eb3] Zygote v0.6.72
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the minimal Julia example with ITensors, ITensorMPS, LinearAlgebra, and Zygote to reproduce the failure at gradient(F, us). Trace the norm call and its ChainRules rrule; done means differentiating F with norm succeeds without the Tangent-to-MPS MethodError, while preserving the working inner-based behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100