Bug: incompatible matrix is accepted as input when creating local operator
Created by: VolodyaCO
I caught the following bug:
>>> import netket as nk
/Users/vladimirvargas/.local/share/virtualenvs/physics-jfSzH1Jb/lib/python3.9/site-packages/jax/_src/lib/__init__.py:33: UserWarning: JAX on Mac ARM machines is experimental and minimally tested. Please see https://github.com/google/jax/issues/5501 in the event of problems.
warnings.warn("JAX on Mac ARM machines is experimental and minimally tested. "
>>> hi = nk.hilbert.Fock(5, N=3)
>>> ham = nk.operator.boson.number(hi, 0) * nk.operator.boson.number(hi, 1)
>>> sparse_ham = ham.to_sparse()
>>> ham2 = nk.operator.LocalOperator(hi, sparse_ham, [0, 1])
>>> sparse_ham.shape
(216, 216)
>>> 6**3
216
You see, the Hilbert space has three parts. First I create ham
acting on parts 0 and 1 only. However, when I invoke the sparse form of this Hamiltonian ham
, I get a matrix for the whole Hilbert space, i.e. this is an operator that acts on the three parts. When I create another operator whose matrix is sparse_ham
acting on the parts 0 and 1 of the Hilbert space, an error should be raised.
I guess this can be solved by checking that the product of the elements of the input matrix shape must equal the product of the local sizes onto which the matrix acts on in the Hilbert space.