Cannot create Spin hilbert with odd sites and S=1
Created by: PhilipVinc
Reported by @fabienalet
>>> import netket as nk
>>> nk.hilbert.Spin(1.0, N=3, total_sz=1.0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/filippovicentini/Dropbox/Ricerca/Codes/Python/netket/netket/hilbert/spin.py", line 88, in __init__
_check_total_sz(total_sz, N)
File "/home/filippovicentini/Dropbox/Ricerca/Codes/Python/netket/netket/hilbert/spin.py", line 40, in _check_total_sz
raise Exception(
Exception: Cannot fix the total magnetization: Nspins + totalSz must be even.
the cuprit is the second check in here: (size is number of spins)
def _check_total_sz(total_sz, size):
if total_sz is None:
return
m = round(2 * total_sz)
if np.abs(m) > size:
raise Exception(
"Cannot fix the total magnetization: 2|M| cannot " "exceed Nspins."
)
if (size + m) % 2 != 0:
raise Exception(
"Cannot fix the total magnetization: Nspins + " "totalSz must be even."
)
The second check works only for Spins 1/2. Can we generalise it to always work? I'm too tired to think how to now.