Skip to content

Fix sign of the Hamiltonian in HeisenbergModel and IsingModel docstrings - #1410

Open
edubraqd wants to merge 1 commit into
qiskit-community:mainfrom
edubraqd:fix/1380-spin-model-docstring-sign
Open

edubraqd wants to merge 1 commit into
qiskit-community:mainfrom
edubraqd:fix/1380-spin-model-docstring-sign

Conversation

@edubraqd

Copy link
Copy Markdown

Summary

Fixes #1380

The docstrings of HeisenbergModel and IsingModel write the Hamiltonian with an overall minus sign on the coupling and field terms, but second_q_op() builds the operator with the coefficients as given:

line = LineLattice(2, boundary_condition=BoundaryCondition.OPEN)
HeisenbergModel(line, coupling_constants=(-1, -1, -1), ext_magnetic_field=(1, 1, 1)).second_q_op()
# -1 * X_0 X_1 + ... + 1 * X_0 + ...   (docstring says the opposite signs)
IsingModel(line.uniform_parameters(2.0, 4.0)).second_q_op()
# 2.0 * Z_0 Z_1 + 4.0 * X_0 + 4.0 * X_1

Details and comments

I chose to fix the documentation rather than the code: the +J / +h convention has been the behaviour since the models were introduced, the 0.5 migration guide documents it (uniform_parameters(2.0, 4.0) → 2.0 * Z_0 Z_1 + 4.0 * X_0 + ...), and test_heisenberg_model.test_ising relies on both models agreeing. Flipping the signs in second_q_op() would silently change results for every existing user.

Changes:

  • HeisenbergModel and IsingModel docstring formulas now match the operator, with a sentence stating that no overall sign is applied (ferromagnetic coupling = negative J).
  • Release note (fixes).
  • ferromagnetic added to .pylintdict for the spell check.

No behaviour change; test_heisenberg_model and test_ising_model pass unchanged (8 tests). I could not run the spell target locally (pyenchant has no en_US dictionary on Windows), so CI will be the check for that one.

AI disclosure: the change was prepared with the help of Claude (Claude Code); I reviewed and verified it.

🤖 Generated with Claude Code

…rings

Both docstrings stated the Hamiltonian with an overall minus sign on the
coupling and field terms, but `second_q_op()` has always used the
coefficients as given (and the migration guide documents that behaviour).
Update the formulas to match the code and state explicitly that no sign is
applied, so a ferromagnetic coupling is a negative J.

Fixes qiskit-community#1380

Co-Authored-By: Claude Opus 5 <[email protected]>
@CLAassistant

CLAassistant commented Sep 19, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

This branch has not been deployed

No deployments
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.

Sign error in HeisenbergModel construction

2 participants