Custom Machines

In addition to Built-in machines NetKet can be extended with user-defined custom machines.

At variance with custom Graphs, Hamiltonians, and Observables providing a new machine requires some coding in C++.

Specifically, your machine must be derived from the base abstract class in Machines/abstract_machine.hpp, which provides prototypes for the pure virtual methods to be implemented. All the key methods in there are commented with the requirements each method should fulfill.

Example

For example, if you wanted to use a fully-visible Boltzmann machine (a.k.a. Jastrow wave-function) in NetKet, one of the key methods that you would need to implement is the one computing the logarithm of the wave-function for a given visible vector. Assuming that the wave-function takes the form:

then you would have to implement the method:

T LogVal(const VectorXd & v){
   T logpsi=0;

   for(int i=0;i<v.size();i++){
     for(int j=i+1;j<v.size();j++){
       logpsi+=W(i,j)*v(i)*v(j);
     }
   }
   return logpsi;
}

Summing up

The steps to be followed are then:

  1. Write your own machine, say Machines/new_machine.hpp taking care of implementing all the methods prototyped in Machines/abstract_machine.hpp
  2. Include its declaration in Machines/machine.hpp
  3. Add it to Machines/machine.hpp to make use of the JSON input infrastructure

In future releases of NetKet, we plan to provide more automatic ways of defining custom machines. Any suggestion on how to implement this (or, better, motivated people to implement this functionality) are more than welcome!