Ejemplo n.º 1
0
import nqs
import trainer
import sampler
import numpy as np
import matplotlib.pyplot as plt
import time
import fermionhop1d

start = time.time()
nruns = 5000
nspins = 40
nsteps = 501
alpha = 2
m = True

wf = nqs.NqsTI(nspins, alpha)  # A translation invariant NQS instance

wf.Wreduced = 0.1 * np.random.uniform(
    -1, 1, wf.Wreduced.shape) + 0j  # Fill in with starting values
if type(wf.a) == int:
    wf.a = 0.1 * np.random.uniform(-1, 1) + 0j
else:
    wf.a = 0.1 * np.random.uniform(-1, 1) * np.ones(wf.a.shape) + 0j
wf.breduced = 0.1 * np.random.uniform(-1, 1, wf.breduced.shape) + 0j

#wf.load_parameters('../Outputs/'+str(nspins)+'_alpha='+str(alpha)+'_Ising10_ti_100.npz')

h = ising1d.Ising1d(nspins, 1.0)
#h = heisenberg1d.Heisenberg1d(10,1)
#h = xyz.XYZ(10,(-1,-1,0))
#h = fermionhop1d.FermionHop(nspins,-2)
Ejemplo n.º 2
0
import ising1d

#Script to generate the data -- sigmax(t) for all our time-evolved wave functions
nsteps = 400
data_rate = 5
nruns = 1000
talk_rate = 25
h = ising1d.Ising1d(10, 1.0)

## Now that we have all the wavefunctions generated, find the <sigma(x)> at each one

#Fully connected translation-invariant
print("Fully connected ANNQS")
sxnonloc = []
nonlocerr = []
wf = nqs.NqsTI(10, 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_ti_' + str(t) +
                       '.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))
Ejemplo n.º 3
0
    '../Outputs/10_Ising05_1loc_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_1loc_',
                print_freq=25,
                out_freq=1,
                batch_size=1000)

### INITIALIZATION
wf = nqs.NqsTI(10, 1)  # Set up a translation-invariant neural network
wf.load_parameters(
    '../Outputs/10_Ising05_ti_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="ti",
                file='../Outputs/10SpinEvolve/evolution_ti_',
                print_freq=25,
                out_freq=1,
                batch_size=1000)
Ejemplo n.º 4
0
import nqs
import numpy as np
import sampler
import heisenberg1d
import time
from scipy.linalg import hankel

n1 = nqs.Nqs(40,1)
n1 = n1.load_parameters("./Outputs/evolution_ti_0.npz")  # a full, normal nqs without translation invariance
n2 = nqs.NqsTI(n1.nv, 1)  # A translation invariant NQS instance with alpha = 2

# Now check whether nqs is TI
wti = np.all(np.isclose(n1.W, hankel(n1.W[:][0], n1.W[-1])))
ati = np.all(np.isclose(n1.a, n1.a[0]))
bti = np.all(np.isclose(n1.b, n1.b[0]))

if wti and ati and bti:
    print("Vanilla NQS is TI: confirmed")

else:
    raise ValueError("Vanilla NQS is NOT TI!")

# If NQS is TI, let's continue by constructing the TI version
n2.W[0] = n1.W[0]
n2.W[1] = np.zeros(n1.W[0].shape)
n2.a = n1.a[0]
n2.b = np.array([n1.b[0], 0])

# 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
Ejemplo n.º 5
0
import nqs
import numpy as np
import sampler
import heisenberg1d
import ising1d
import time
import trainer
import matplotlib.pyplot as plt

density = 1
k = 10
n1 = nqs.NqsTI(40, density)  # A translation invariant NQS instance with alpha = 1
n2 = nqs.NqsLocalTI(40, density, k) # A local TI NQS instance with same alpha

# Randomize the TI case
n1.W = 0.1*np.random.random(n1.W.shape) + 0j
n1.a = 0.1*np.random.uniform(0) + 0j
n1.b = 0.1*np.random.random(n1.b.shape) + 0j


# Now we localize the TI NQS instance by creating the array (1, 1, 0, 0.... 1) and multiplying elementwise
localizer = np.zeros(40)
localizer[0:n2.k] = 1
localizer[-n2.k:] = 1
n1.W *= localizer

# Now feed all the TI parameters to local TI NQS
n2.a = n1.a
n2.b = n1.b
for a in range(density):
    n2.Wloc[a] = n1.W[a][np.arange(-n2.k,n2.k+1)]
Ejemplo n.º 6
0
import matplotlib.pyplot as plt


def log_to_fit(l, delta, gamma):
    return (1 - delta / 2) * np.log(l) + gamma


dlist = []
glist = []

nspins = 40
training_step = 500
nsamples = 50000
alpha = 2

annqs = nqs.NqsTI(nspins, alpha)
annqs.load_parameters('../Outputs/' + str(nspins) + '_alpha=' + str(alpha) +
                      '_Ising10_ti_' + str(training_step) + '.npz')
h = ising1d.Ising1d(nspins, 1.0)

s = sampler.Sampler(annqs, h, quiet=False)
s.run(nsamples)

states = np.zeros((nsamples, nspins))

for i in range(nsamples):
    for j in range(nspins):
        s.move()
    states[i] = s.state

data = np.zeros(nspins)
Ejemplo n.º 7
0
import nqs
import numpy as np
import sampler
import heisenberg1d
import time
import trainer

# Script to test the symmetric NQS class I wrote against the class that is hardcoded translation invariant

n1 = nqs.NqsTI(40, 1)  # A translation invariant NQS instance

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

shift_group = np.array(
    [np.roll(np.identity(40), i, axis=1) for i in range(40)])

n2 = nqs.NqsSymmetric(40, 1, shift_group)
n2.W = np.copy(n1.W)
n2.a = np.array([n1.a])
n2.b = np.copy(n1.b)

# 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)