invalid batch size: PauliStrings operator, MetropolisLocal sampler and RBM machine
Created by: Jorawar-Singh
When running the VMC for a RBM with PauliStrings Hamiltonian and the MetropolisLocal sampler, I get the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "python3.8/site-packages/netket/abstract_variational_driver.py", line 228, in run
for step in itr:
File "python3.8/site-packages/tqdm/std.py", line 1167, in __iter__
for obj in iterable:
File "python3.8/site-packages/netket/abstract_variational_driver.py", line 128, in iter
dp = self._forward_and_backward()
File "python3.8/site-packages/netket/_vmc.py", line 136, in _forward_and_backward
eloc, self._loss_stats = self._get_mc_stats(self._ham)
File "python3.8/site-packages/netket/_vmc.py", line 197, in _get_mc_stats
_local_values(op, self._machine, sample, out=loc[i])
File "python3.8/site-packages/netket/operator/local_values.py", line 131, in local_values
_impl(op, machine, v, log_vals, out)
File "python3.8/site-packages/netket/operator/local_values.py", line 29, in _local_values_impl
log_val_primes = machine.log_val(v_primes)
ValueError: invalid batch size: 0; expected a positive number
Construction -
import netket as nk
### Setup
ops = ['IIIIII', 'ZIIIII', 'IIIZII', 'IIIIZI', 'IZIIII', 'IIZIII', 'IIIIIZ', 'ZZIIII', 'IZZIII', 'IIIZZI', 'ZIIIZZ', 'IZIZIZ', 'ZIIZII', 'IIZIZI', 'IIZZII', 'ZIIIIZ', 'IZIZII', 'IZIIIZ', 'IIIZIZ', 'IIIIZZ', 'ZIIIZI', 'ZZIZZI', 'IZZZZI', 'ZZIZII', 'ZZIIZI', 'ZIIZZI', 'IZZZII', 'IZZIZI', 'IIZZZI', 'IZIZZI']
w = [2.750, 0.1250, 0.2500, 0.2500, 0.5000, -0.1250, -1.000, 0.1250, 0.1250, 0.2500, 0.2500, 0.2500, 0.3750, 0.3750, -0.1250, -0.2500, -0.2500, -0.2500, -0.2500, -0.2500, -0.3750, 0.1250, 0.1250, -0.1250, -0.1250, -0.1250, -0.1250, -0.1250, -0.1250, -0.2500]
ha = nk.operator.PauliStrings(ops, weights=w)
g = nk.graph.Hypercube(length=6, n_dim=1, pbc=False)
hi = nk.hilbert.Spin(s=0.5, graph=g)
### RBM
ma = nk.machine.RbmSpin(alpha=2, hilbert=hi)
ma.init_random_parameters()
### Stochastic reconfiguration
sa = nk.sampler.MetropolisLocal(machine=ma)
op = nk.optimizer.AdaDelta()
gs = nk.variational.Vmc(hamiltonian=ha, sampler=sa, optimizer=op, n_samples=1000, diag_shift=0.01, use_iterative=True, method='Sr')
gs.run(out='RBM', n_iter=1000)
The code runs for a while, but then fails with the above error. The error also occurs with ExactSampler, irrespective of the optimizer used. However, the same construction with a FFNN works fine.
Linux Mint 19.3 Cinnamon 4.4.8 Kernel 4.15.0-20-generic python version - 3.8.5 netket version - 2.1.1