Skip to content

NetKet version 2.0

Vicentini Filippo requested to merge github/fork/gcarleo/v2.0 into v2.0

Created by: gcarleo

Summary

This is a work-in-progress PR for NetKet version 2.0, also functioning as a way to gather some discussion [see end of this document to give your feedback] .

Major changes

  1. NetKet now fully exposes its internal types and classes, thus becoming a full-fledged python library built on a monolithic c++ core
  2. Python Bindings are provided using pybind11, thus fully addressing issue #8 (closed)
  3. As a result of this transformation, JSON input is not accepted anymore and the netket executable will not exist anymore
  4. Unit tests check c++ classes without relying on JSON input, unit tests on python classes are done similarly

Reasons behind these changes

  1. The most common current usage pattern of NetKet is not to write directly the JSON file, but use the python scripts we have in the Tutorials/ folder. That's why moving to a (much more usable and flexible) python library is a desirable goal, which shouldn't have a dramatic impact on the current usage pattern.
  2. With a full-fledged python library it is also much easier to submit multiple jobs with different parameters, and have more flexibility on the output
  3. There is a substantial overhead for maintaining the JSON support. Supporting all the possible ways of putting together the NetKet classes, in a consistent way, does not scale well given the increasing size of this project.
  4. It will be easier to interface to a whole spectrum of Python-only libraries
  5. New generations of students (unfortunately) are not very familiar with c++, and strive to have a pure Python library

Compiling and Examples

It is possible to compile NetKet and install the python library just doing

pip3 install netket/  

This will automatically call CMake, and also register the python library.

At the moment, this PR provides bindings for the great majority of NetKet classes.

In Tutorials/PyNetKet there is an example usage. For example one can run a full ground-state optimization like this:

from __future__ import print_function
import netket as nk
from mpi4py import MPI

#Constructing a 1d lattice
g=nk.Hypercube(L=20,ndim=1)

# Hilbert space of spins from given graph
hi=nk.Spin(S=0.5,graph=g)

#Hamiltonian
ha=nk.Ising(h=1.0,hilbert=hi)

#Machine
ma=nk.RbmSpin(hilbert=hi,alpha=1)
ma.InitRandomPars(seed=1234,sigma=0.01)

#Sampler
sa=nk.MetropolisLocal(machine=ma)

#Optimizer
op=nk.Sgd(learning_rate=0.1)

#Variational Monte Carlo
gs=nk.Vmc(hamiltonian=ha,sampler=sa,
          optimizer=op,nsamples=1000,
          niter_opt=300,output_file='test',
          diag_shift=0.1)
gs.Run()

Still to do (help/suggestions welcome)

  • Provide bindings for ImaginaryTimePropagation, TimeEvolutionDriver etc. We need to define a convenient container class for those. This is needed in order to nicely handle observables, for example as done in VariationalMonteCarlo through the method AddObservable

  • New unit tests are needed, since JSON input is not supported anymore. We need tests for both the c++ internal classes and the python libraries.

  • Provide a better installer

  • Update documentation

  • Update python tutorials

  • Remove classes and methods marked with TODO remove

Other remarks

  • Version 2.0 removes all "glue" classes, such as Graph,Hamiltonian etc. The corresponding abstract interfaces remain, with little changes.

  • We introduce the concept of Operator, which generalizes Hamiltonian,Observable etc. Hamiltonian and Observable disappear.

  • We introduce a LocalOperator, and all associated overloaded operations, for example

hi=nk.Spin(S=0.5,graph=g)
X=[[0,1],[1,0]]
o=nk.LocalOperator(hi,X,[0])*(nk.LocalOperator(hi,X,[1]))

defines a quantum operator X(0)*X(1), automatically performing the tensor product. Other operations such as product times a scalar and addition of local operators are also supported.

  • Do we need to rethink the way we write the output results? Now results are written to a text file, as it used to be, in JSON format. Given the python support, we could decide to support more output formats.

Action required for FEEDBACK

Please comment/ provide your opinion about these changes, and if you believe they would improve/deteriorate your current/expected usage pattern. We welcome comments both from developers and regular users.

Merge request reports