Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _setup_vmc():
g = nk.graph.Hypercube(length=8, n_dim=1)
hi = nk.hilbert.Spin(s=0.5, graph=g)
ma = nk.machine.RbmSpin(hilbert=hi, alpha=1)
ma.init_random_parameters(seed=SEED, sigma=0.01)
ha = nk.operator.Ising(hi, h=1.0)
sa = nk.sampler.MetropolisLocal(machine=ma)
sa.seed(SEED)
op = nk.optimizer.Sgd(learning_rate=0.1)
vmc = nk.variational.Vmc(
hamiltonian=ha, sampler=sa, optimizer=op, n_samples=500, diag_shift=0.01
)
# Add custom observable
X = [[0, 1], [1, 0]]
sx = nk.operator.LocalOperator(hi, [X] * 8, [[i] for i in range(8)])
vmc.add_observable(sx, "SigmaX")
# Notice that the Transverse-Field Ising model as defined here has sign problem
L = 20
site_operator = [sigmax]
bond_operator = [mszsz]
# Hypercube
g = nk.graph.Hypercube(length=L, n_dim=1, pbc=True)
# Custom Hilbert Space
hi = nk.hilbert.Spin(s=0.5, graph=g)
# Graph Operator
op = nk.operator.GraphOperator(hi, siteops=site_operator, bondops=bond_operator)
# Restricted Boltzmann Machine
ma = nk.machine.RbmSpin(hilbert=hi, alpha=1)
ma.init_random_parameters(seed=1234, sigma=0.01)
# Local Metropolis Sampling
sa = nk.sampler.MetropolisLocal(machine=ma)
# Optimizer
opt = nk.optimizer.AdaMax()
# Stochastic reconfiguration
gs = nk.variational.Vmc(
hamiltonian=op,
sampler=sa,
optimizer=opt,
n_samples=1000,
diag_shift=0.1,
method="Gd",
# See the License for the specific language governing permissions and
# limitations under the License.
import netket as nk
from ed import load_ed_data
import matplotlib.pyplot as plt
import numpy as np
L = 10
# Load the Hilbert space info and data
hi, training_samples, training_targets = load_ed_data(L)
# Machine
ma = nk.machine.RbmSpin(hilbert=hi, alpha=1)
ma.init_random_parameters(seed=1234, sigma=0.01)
# Optimizer
op = nk.optimizer.AdaDelta()
spvsd = nk.supervised.Supervised(
machine=ma,
optimizer=op,
batch_size=400,
samples=training_samples,
targets=training_targets,
)
n_iter = 1000
import netket as nk
import networkx as nx
import numpy as np
import scipy.sparse as sparse
# Constructing a 1d lattice
g = nk.graph.Hypercube(length=4, n_dim=1)
# Hilbert space of spins from given graph
hi = nk.hilbert.Spin(s=0.5, graph=g)
# Hamiltonian
ha = nk.operator.Ising(h=1.0, hilbert=hi)
# Machine
ma = nk.machine.RbmSpin(hilbert=hi, alpha=1)
ma.init_random_parameters(seed=1234, sigma=0.1)
ma.save("test.wf")
ma.parameters = np.zeros(ma.n_par)
ma.load("test.wf")
print(ma.parameters)
# See the License for the specific language governing permissions and
# limitations under the License.
import netket as nk
# 1D Periodic Lattice
g = nk.graph.Hypercube(length=12, n_dim=1, pbc=True)
# Boson Hilbert Space
hi = nk.hilbert.Boson(graph=g, n_max=3, n_bosons=12)
# Bose Hubbard Hamiltonian
ha = nk.operator.BoseHubbard(U=4.0, hilbert=hi)
# Jastrow Machine with Symmetry
ma = nk.machine.JastrowSymm(hilbert=hi)
ma.init_random_parameters(seed=1234, sigma=0.01)
# Sampler
sa = nk.sampler.MetropolisHamiltonian(machine=ma, hamiltonian=ha)
# Stochastic gradient descent optimization
op = nk.optimizer.Sgd(learning_rate=0.1)
# Variational Monte Carlo
vmc = nk.gs.Vmc(
hamiltonian=ha,
sampler=sa,
optimizer=op,
n_samples=10000,
niter_opt=4000,
diag_shift=5e-3,
import netket as nk
import numpy as np
from mpi4py import MPI
from load_MNIST import load_training
# Load the Hilbert space info and data
num_images = 1000
hi, training_samples, training_targets = load_training(num_images)
for i in range(num_images):
training_targets[i] = np.log(training_targets[i] + 1)
# Machine
ma = nk.machine.RbmMultiVal(hilbert=hi, alpha=10)
## Layers
#L = 28*28
#layers = (
# nk.layer.FullyConnected(input_size=L, output_size=100),
# nk.layer.Relu(input_size=100),
# nk.layer.FullyConnected(input_size=100, output_size=10),
#)
#
#ma = nk.machine.FFNN(hilbert=hi, layers=layers)
ma.init_random_parameters(seed=1234, sigma=0.001)
# Sampler
sa = nk.sampler.MetropolisLocal(machine=ma)
import netket as nk
import sys
SEED = 3141592
# Constructing a 1d lattice
g = nk.graph.Hypercube(length=20, n_dim=1)
# Hilbert space of spins from given graph
hi = nk.hilbert.Spin(s=0.5, graph=g)
# Hamiltonian
ha = nk.operator.Ising(h=1.0, hilbert=hi)
# Machine
ma = nk.machine.RbmSpin(hilbert=hi, alpha=1)
ma.init_random_parameters(seed=SEED, sigma=0.01)
# Sampler
sa = nk.sampler.MetropolisLocal(machine=ma)
sa.seed(SEED)
# Optimizer
op = nk.optimizer.Sgd(learning_rate=0.01)
# Variational Monte Carlo
vmc = nk.variational.Vmc(
hamiltonian=ha,
sampler=sa,
optimizer=op,
n_samples=1000,
diag_shift=0.0,
# See the License for the specific language governing permissions and
# limitations under the License.
import netket as nk
# 1D Lattice
g = nk.graph.Hypercube(length=20, n_dim=1, pbc=True)
# Hilbert space of spins on the graph
hi = nk.hilbert.Spin(s=0.5, graph=g)
# Ising spin hamiltonian
ha = nk.operator.Ising(h=1.0, hilbert=hi)
# Jastrow Machine
ma = nk.machine.Jastrow(hilbert=hi)
ma.init_random_parameters(seed=1234, sigma=0.01)
# Metropolis Local Sampling
sa = nk.sampler.MetropolisLocal(machine=ma)
# Optimizer
op = nk.optimizer.Sgd(learning_rate=0.1)
# Stochastic reconfiguration
gs = nk.variational.Vmc(
hamiltonian=ha,
sampler=sa,
optimizer=op,
n_samples=1000,
diag_shift=0.1,
method="Sr",
ha = nk.operator.Heisenberg(hilbert=hi)
# Layers
layers = (
nk.layer.ConvolutionalHypercube(
length=L, n_dim=1, input_channels=1, output_channels=4, kernel_length=4
),
nk.layer.Lncosh(input_size=4 * L),
nk.layer.ConvolutionalHypercube(
length=4 * L, n_dim=1, input_channels=1, output_channels=2, kernel_length=4
),
nk.layer.Lncosh(input_size=4 * 2 * L),
)
# FFNN Machine
ma = nk.machine.FFNN(hi, layers)
ma.init_random_parameters(seed=1234, sigma=0.1)
# Sampler
sa = nk.sampler.MetropolisHamiltonian(machine=ma, hamiltonian=ha)
# Optimizer
op = nk.optimizer.Sgd(learning_rate=0.01)
# Variational Monte Carlo
gs = nk.variational.Vmc(
hamiltonian=ha, sampler=sa, optimizer=op, n_samples=1000, diag_shift=0.01
)
gs.run(output_prefix="ffnn_test", n_iter=300, save_params_every=10)
# See the License for the specific language governing permissions and
# limitations under the License.
import netket as nk
# 2D Lattice
g = nk.graph.Hypercube(length=5, n_dim=2, pbc=True)
# Hilbert space of spins on the graph
hi = nk.hilbert.Spin(s=0.5, graph=g)
# Ising spin hamiltonian at the critical point
ha = nk.operator.Ising(h=3.0, hilbert=hi)
# RBM Spin Machine
ma = nk.machine.RbmSpin(alpha=1, hilbert=hi)
ma.init_random_parameters(seed=1234, sigma=0.01)
# Metropolis Local Sampling
sa = nk.sampler.MetropolisLocal(machine=ma)
# Optimizer
op = nk.optimizer.Sgd(learning_rate=0.1)
# Stochastic reconfiguration
gs = nk.variational.Vmc(
hamiltonian=ha,
sampler=sa,
optimizer=op,
n_samples=1000,
diag_shift=0.1,
method="Sr",