コード例 #1
0
ファイル: local_test.py プロジェクト: zeldredge/py-nqs
# Script to test the local NQS class I wrote against the normal class

n1 = nqs.Nqs("./Ground/Heisenberg1d_40_1_1.npz")  # A vanilla NQS instance

n1.W = 0.1 * np.random.random(n1.W.shape) + 0j  # Fill in with starting values
n1.a = 0.1 * np.random.random(n1.a.shape) + 0j
n1.b = 0.1 * np.random.random(n1.b.shape) + 0j

# To "localize" the above array, create a tridiagonal array and multiply elementwise
tridiag = np.diag(np.ones(40,dtype=complex)) + np.diag(np.ones(39), -1) + np.diag(np.ones(39), +1)
n1.W = tridiag * n1.W
n = n1.W.T

# Now we create the local NQS instance

n2 = nqs.NqsLocal(40, 1, 1)
n2.a = n1.a
n2.b = n1.b
indices = np.array([-1, 0, 1])
for i in range(40):
    n2.W[i][0] = n[i][(i+indices) % n1.nv]


# Now begin testing outputs
base_array = np.concatenate(
                (np.ones(int(20)), -1 * np.ones(int(20))))  # make an array of half 1, half -1
state = np.random.permutation(base_array)  # return a random permutation of the half 1, half-1 array

n2.init_lt(state)
n1.init_lt(state)
コード例 #2
0
                       '.npz')
    s = sampler.Sampler(wf,
                        observables.Sigmax(10, 1),
                        opname='transverse polarization')
    s.run(nruns)
    sxnonloc.append(10 * s.estav)
    err = distances.get_rdist(wf, nruns,
                              h)  #/distances.get_ddist(wf,h,.01,nruns)
    nonlocerr.append(err)
print("time elapsed: {:.2f}s".format(time.time() - start_time))

#1-local
sx1 = []
loc1err = []
print("1-local ANNQS")
wf = nqs.NqsLocal(10, 1, 1)
start_time = time.time()
for t in np.arange(0, nsteps, data_rate):
    if t % talk_rate == 0:
        print('t = {}'.format(t))
    wf.load_parameters('../Outputs/10SpinEvolve/evolution_1loc_' + str(t) +
                       '.npz')
    s = sampler.Sampler(wf,
                        observables.Sigmax(10, 1),
                        opname='transverse polarization')
    s.run(nruns)
    sx1.append(10 * s.estav)
    err = distances.get_rdist(wf, nruns,
                              h)  #/ distances.get_ddist(wf,h,.01,nruns)
    loc1err.append(err)
print("time elapsed: {:.2f}s".format(time.time() - start_time))
コード例 #3
0
ファイル: small_main.py プロジェクト: zeldredge/py-nqs
import nqs
import numpy as np
import sampler
import heisenberg1d
import ising1d
import time
import trainer

# Script to get and save local NQS solutions of the TFI h = 0.5 model

#we create the local NQS instance

wf = nqs.NqsLocal(40, 2, 1)
wf.W = 0.1 * np.random.random(wf.W.shape) + 0j  # Fill in with starting values
wf.a = 0.1 * np.random.random(wf.a.shape) + 0j
wf.b = 0.1 * np.random.random(wf.b.shape) + 0j

# Now begin testing outputs
base_array = np.concatenate(
                (np.ones(int(20)), -1 * np.ones(int(20))))  # make an array of half 1, half -1
state = np.random.permutation(base_array)  # return a random permutation of the half 1, half-1 array

wf.init_lt(state)

h = ising1d.Ising1d(40, 0.5)

def gamma_fun(p):
    return .01

t = trainer.TrainerLocal(h)
コード例 #4
0
ファイル: evolve_script.py プロジェクト: zeldredge/py-nqs
import numpy as np
import trainer
import ising1d
import nqs
import sampler
import evolver
import observables

nsteps = 400

### INITIALIZATION
wf = nqs.NqsLocal(10, 2, 1)  # Set up a translation-invariant neural network
wf.load_parameters(
    '../Outputs/10_Ising05_2loc_200.npz')  # Load this pre-trained ANNQS

## TIME EVOLVE
h = ising1d.Ising1d(10, 1.0)
evo = evolver.Evolver(h)
wf = evo.evolve(wf,
                .01,
                nsteps + 1,
                symmetry="local",
                file='../Outputs/10SpinEvolve/evolution_2loc_',
                print_freq=25,
                out_freq=1,
                batch_size=1000)

### INITIALIZATION
wf = nqs.NqsLocal(10, 1, 1)  # Set up a translation-invariant neural network
wf.load_parameters(
    '../Outputs/10_Ising05_1loc_200.npz')  # Load this pre-trained ANNQS
コード例 #5
0
ファイル: local_train.py プロジェクト: zeldredge/py-nqs
import trainer
import sampler
import numpy as np
import matplotlib.pyplot as plt
import time

start = time.time()
nruns = 1000
k = 2
gam = .01
nspins = 10
#h = heisenberg1d.Heisenberg1d(nspins,1)
h = ising1d.Ising1d(10, 0.5)
#h = fermionhop1d.FermionHop(nspins,1)

wf = nqs.NqsLocal(nspins, 1, k)  # A local NQS instance

wf.W = 0.1 * np.random.random(wf.W.shape) + 0j  # Fill in with starting values
wf.a = 0.1 * np.random.random(wf.a.shape) + 0j
wf.b = 0.1 * np.random.random(wf.b.shape) + 0j

base_array = np.concatenate(
    (np.ones(int(1)),
     -1 * np.ones(int(nspins - 1))))  # make an array of half 1, half -1
state = np.random.permutation(
    base_array)  # return a random permutation of the half 1, half-1 array
wf.init_lt(state)

s = sampler.Sampler(wf, h)
s.run(nruns)