Exemplo n.º 1
0
 def serialize(self, real=False):
     """serialize: return a vector with mps data in it"""
     vec = ct([a.reshape(-1) for a in self])
     if real:
         return ct([vec.real, vec.imag])
     else:
         return vec
Exemplo n.º 2
0
    def mps_OTOC(self, T, ops, dt=1e-2):
        """mps_OTOCs: -<[W(t), V(0)], [W(t), V(0)]>

        :param T: times
        :param ops: operators (V, W)
        """
        assert self.W is not None
        # want to use inverse free method since it's time symmetric
        V, W = ops
        mps_0, mpo = self.mps, self.W
        Ws = []
        psi_1 = mps_0  # |s>
        psi_2 = mps_0.copy().apply(V).left_canonicalise()  # V|s>
        n2_0 = psi_2.norm_
        T = ct([[0], T])
        for t1, t2 in zip(T, T[1:]):
            for _ in linspace(t1, t2, int((t2-t1)/dt)):
                psi_1 = self.invfree(psi_1, dt)
                psi_2 = self.invfree(psi_2, dt)
            psi_1_ = psi_1.copy().apply(W).left_canonicalise()  # WU|s>
            psi_2_ = psi_2.copy().apply(W).left_canonicalise()  # WUV|s>
            n1_1 = psi_1_.norm_
            n2_1 = psi_2_.norm_
            for _ in linspace(t1, t2, int((t2-t1)/dt)):
                psi_1_ = self.invfree(psi_1_, -dt)
                psi_2_ = self.invfree(psi_2_, -dt)
            psi_1_.apply(V).left_canonicalise()
            n1_0 = psi_1_.norm_
            psi_1[0] *= n1_0*n1_1
            psi_2[0] *= n2_0*n2_1
            Ws.append(psi_1_.overlap(psi_1_)+psi_2_.overlap(psi_2_) -
                      0.5*re(psi_1_.overlap(psi_2_)))

        return Ws
Exemplo n.º 3
0

# Solve for the basis elements and update the A and b arrays.
for i, xb in enumerate(XB):
    basis_element = A[i][xb]
    if basis_element != 1:
        A[i] = A[i] / basis_element
        b[0][i] /= basis_element

# Dual simplex method to find an optimal solution.
count = 2
z = np.array([list(z[0]) + [0]])  # Initialize solution to 0.

# Print initial tableau.
print('\n Tableau #1')
full_tableau = ct((z, ct((A, np.transpose(b)), axis=1)))
print('Basis: ', XB)
print(full_tableau)

# Solve.
infeasible = False
while not all(b[0] > 0):

    # Identify the element that leaves the basis.
    leaving = [i for i, y in enumerate(b[0] < 0) if y][0]

    # For the row that corresponds to the element that is leaving the
    # basis, identify the elements that are negative.
    col_idxs = [i for i, y in enumerate(A[leaving] < 0) if y]
    negatives = A[leaving][col_idxs]
Exemplo n.º 4
0
    def lyapunov(self, T, D=None, thresh=1e-5, conv_window=100,
                 just_max=False,
                 t_burn=2,
                 initial_basis='F2',
                 order='low',
                 k=0):
        self.has_run_lyapunov = True
        H = self.H
        has_mpo = self.W is not None
        if D is not None and t_burn != 0 and not hasattr(self, 'Q'):
            # if MPO supplied - just expand, canonicalise and use inverse free integrator
            # otherwise use dynamical expand: less numerically stable
            # if we already have a basis set - we must be resuming a run
            print('starting pre evolution ... ', end='', flush=True)

            if has_mpo:
                self.mps = self.mps.left_canonicalise().expand(D)
                self.invfreeint(
                    linspace(0, t_burn, int(50*t_burn)), order=order)
                self.burn_len = int(200*t_burn)
                self.mps = self.mps.left_canonicalise()
                self.mps_history = []
            else:
                self.mps = self.mps.grow(self.H, 0.1, D).right_canonicalise()
                self.rk4int(linspace(0, 1, 100))

            print('finished pre evolution')

        if hasattr(self, 'Q'):
            Q = self.Q
        elif initial_basis == 'F2':
            Q = self.mps.tangent_space_basis(H=H, type=initial_basis)
        elif initial_basis == 'eye' or initial_basis == 'rand':
            Q = kron(eye(2), self.mps.tangent_space_basis(
                H=H, type=initial_basis))
        else:
            Q = initial_basis
        Q_ = copy(Q)

        if just_max:
            # just evolve top vector, dont bother with QR
            q = Q[0]
        dt = T[1]-T[0]

        lys = []
        exps = [array([0])]

        lys_ = []
        exps_ = [array([0])]

        self.vs = []

        conv = []
        conv_ = []

        paired = []
        paired_ = []
        for n in tqdm(range(len(T))):
            J = self.mps.jac(H)
            if hasattr(self.mps, 'old_vL'):
                self.vs.append(self.mps.v)
            if just_max:
                q = expm_multiply(J*dt, q)
                lys.append(log(abs(norm(q))))
                q /= norm(q)
            else:
                M = expm_multiply(J*dt, Q)
                Q, R = qr(M)
                lys.append(log(abs(diag(R))))
                exps.append((exps[-1]*n+lys[-1])/(n+1))
                conv.append(np.mean(np.var(np.array(exps[-conv_window-1:])/dt, axis=0)))
                paired.append(norm(exps[-1]+exps[-1][::-1]))

                M_ = expm_multiply(-J.T*dt, Q_)
                Q_, R_ = qr(M_)
                lys_.append((lys[-1]+log(abs(diag(R_))))/2)
                exps_.append((exps_[-1]*n+lys_[-1])/(n+1))
                conv_.append(np.mean(np.var(np.array(exps_[-conv_window-1:])/dt, axis=0)))
                paired_.append(norm(exps_[-1]+exps_[-1][::-1]))

                if thresh is not None and conv[-1] < thresh:
                    break

            if has_mpo:
                vL = self.mps.new_vL

                if order == 'high':
                    self.mps = self.invfree4(self.mps, dt)
                elif order == 'low':
                    self.mps = self.invfree(self.mps, dt)

                self.mps.old_vL = vL
                self.vL = vL
            else:
                vL = self.mps.new_vL

                old_mps = self.mps.copy()
                self.mps = self.rk4(self.mps, dt, H).right_canonicalise()
                self.mps.match_gauge_to(old_mps)

                self.mps.old_vL = vL
                self.vL = vL

        if hasattr(self, 'lys'):
            self.lys = ct([self.lys, array(lys)])
            if hasattr(self, 'lys_'):
                self.lys_ = ct([self.lys_, array(lys_)])
        else:
            self.lys = array(lys)
            self.lys_ = array(lys_)

        if just_max:
            self.q = q
            self.exps = exps[k+1:n+2]/dt
            self.exps_ = exps_[k+1:n+2]/dt
            T = T[k:n+1]
        else:
            self.Q = Q
            self.exps = exps[k+1:n+2]/dt
            self.exps_ = exps_[k+1:n+2]/dt
            T = T[k:n+1]

        if hasattr(self, 'lys_'):
            return T, (self.exps, self.lys, conv, paired), (self.exps_, self.lys_, conv_, paired_)
        else:
            return T, (self.exps, self.lys, conv, paired)
Exemplo n.º 5
0
#------------------------------------------------------
import cv2
import skimage

img = cv2.imread(imgPath)
saltyImg = skimage.util.random_noise(img)
#------------------------------------------------------

#------------------------------------------------------
from cv2 import imread
from skimage.util import random_noise

img = imread(imgPath)
saltyImg = random_noise(img)
#------------------------------------------------------

#------------------------------------------------------
from skimage.util import random_noise as rn
import numpy as np

saltyImg = rn(img)
concateImg = np.concatenate((img, saltyImg), axis=1)
#------------------------------------------------------

#------------------------------------------------------
from numpy import concatenate as ct

concateImg = ct((img, saltyImg), axis=1)
#------------------------------------------------------
Exemplo n.º 6
0
 def store(self, filename):
     """store in file
     :param filename: filename to store in
     """
     save(filename, ct([array([self.d, self.D, self.period]), self.serialize()]))