AttributeError: module 'netket.hilbert' has no attribute 'constraint' #1970
-
I am trying to write my own Hilbert space class, which will be similar to the spin class. In this class, I want to use DiscreteHilbertConstraint and SumConstraint. I follow the example found here: but when doing so I get the error
at the line
I am on Netket 3.15.1. I would appreciate any advice on how to use the constraint class in a locally-defined hilbert class. Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Can you share the whole error? If I run on the last (3.15.1) netket the following code runs fine: import netket as nk
from netket.utils import struct
import jax; import jax.numpy as jnp
class SumConstraint(nk.hilbert.constraint.DiscreteHilbertConstraint):
# A simple constraint checking that the total sum of the elements
# in the configuration is equal to a given value.
# The value must be set as a pytree_node=False field, meaning
# that it is a constant and changes to this value represent different
# constraints.
total_sum : float = struct.field(pytree_node=False)
def __init__(self, total_sum):
self.total_sum = total_sum
def __call__(self, x):
# Makes it jax-compatible
return jnp.sum(x, axis=-1) == self.total_sum
def __hash__(self):
return hash(("SumConstraint", self.total_sum))
def __eq__(self, other):
if isinstance(other, SumConstraint):
return self.total_sum == other.total_sum
return False
print(nk.__version__)
# 3.15.1 Also, unrelated, but I'm curious about why you want to define a new 'spin' class. |
Beta Was this translation helpful? Give feedback.
Can you share the whole error?
And can you share the exact version of netket installed by doing
pip freeze | grep netket
or equivalent command?If I run on the last (3.15.1) netket the following code runs fine: