Skip to content

Typo in one-site Jordan AC Hamiltonian constructor - #493

Open
borisdevos wants to merge 5 commits into
mainfrom
bd/ACham-typo
Open

Typo in one-site Jordan AC Hamiltonian constructor#493
borisdevos wants to merge 5 commits into
mainfrom
bd/ACham-typo

Conversation

@borisdevos

Copy link
Copy Markdown
Member

This one took a while to debug since I don't really know how these Jordan MPOs work. I now understand a little better 😄

It turns out two things have to occur simultaneously for this to have been noticed. First, the scalartype of the Hamiltonian and the state must mismatch, such that the constructor of the AC Hamiltonian doesn't get fast-forwarded to the inner constructor but lands on the fallback one with the typo. Second, the Hamiltonian needed to not have the ending block while also have the finishing one. Since I was playing around with something semi-long range, I came across this, which makes sense. Nearest-neighbor Hamiltonians will always have B.

Coincidentally, we never caught this in the tests because we don't look at long-range Hamiltonians. So I added that to the tests, along with fairly extensive tests on the derivatives themselves directly. Some might be overkill, but better safe than sorry. Locally the performance of these long-range Hamiltonians is notably terrible (see #459)

I also discovered the changelog, so I decided to add to that :)

end

@testset "Long-range Hamiltonian with real scalartype" verbose = true begin
# A real `H` optimised over a complex MPS sends the derivative operators through their

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'm not sure I'm understanding what this means to be honest, would you mind explaining?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think I explained it elsewhere better, but basically when the scalartype of the Hamiltonian and the state aren't equal at the real/complex level (I didn't test at the level of precision), JordanMPO_AC_Hamiltonian will go through the fallback outer constructor.

Two things had to happen at the same time. First, there needs to be an onsite term so the B-block exists, and second it needs to have a different scalartype to the environments. The B-block doesn't inherit the type of these environments in this particular case, as can be seen in:

D = nonzero_length(WD) > 0 ? only(WD) : missing

So the typed inner constructor doesn't work, and it goes through the untyped one which wants to convert accordingly, which then errored due to the typo.

I think I wrote this poorly in the comments, so I can change this if it helps to remember why those tests exist.

@codecov

codecov Bot commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
.../algorithms/derivatives/hamiltonian_derivatives.jl 98.08% <ø> (+4.78%) ⬆️

... and 1 file with indirect coverage changes

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

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