Transpose array-like in herm_conj
If onsite/hopping value was supplied to the builder as array-like instead of proper array, Hamiltonian could be generated silently without any Hermitian conjugation, if required.
This MR fixes the problem, trying to cast the value to the proper array, if it can't be conjugated and is not a number.
Fixes #406 (closed)
Merge request reports
Activity
added 2 commits
Thanks, this should do the job. However, I believe that the following points should be addressed before merging:
It would be nice if there was a test that fails with the old code and showcases the problem. That could be a separate commit followed up by the fix.
Also, it would be interesting to check how much slower
hamiltonian_submatrix
becomes for the common case where values are functions. With the new code, an exception will be thrown and caught for each timeherm_conj
is called (that's for 50% of the values on average) which may result in a significant slowdown. If this is indeed the case, we should seek an alternative approach.In addition, since this is a user-visible change, I suggest adding it to the changelog file below "Changes in Kwant 1.4.2". The subsection could be called "Changes after the release of Kwant 1.4.2" and we would then change it when we release.
Moreover, since the issue is already present in stable, I believe we should fix it there. (Independently of whether we will release a new stable version of the 1.4.x series.)
Edited by Christoph GrothAlso, it would be interesting to check how much slower
hamiltonian_submatrix
becomes for the common case where values are functions.It will not affect it, because
herm_conj
is used only withinHermConjOfFunc.__call__()
(herm_conj()
is not called on a function based on a conditional checkif callable(value)
), and there exception also will appear only if returned value is not an array, not a number and can't be casted to a tinyarray, the same as in the case of non-callable value.It would be nice if there was a test that fails with the old code and showcases the problem.
Modified
test_builder.py::test_hermitian_conjugation
to capture this, decided to leave it as a single atomic commit.I suggest adding it to the changelog file below "Changes in Kwant 1.4.2".
Done.
Moreover, since the issue is already present in stable, I believe we should fix it there.
I suggest just cherry-picking it there after getting merged into master, together with f8331485 to fix CI failures.
added 2 commits
added 2 commits
I rebased to
stable
and separated test and fix commits. The pipeline will fail, however, before f8331485 is not applied. I still suggest to cherry-pick it and then rebase the MR on top of it.The pipeline will fail, however, before f8331485 is not applied. I still suggest to cherry-pick it and then rebase the MR on top of it.
Definitely. Looks good to me!
mentioned in commit a9fedcf5