コード例 #1
0
ファイル: proj_study.py プロジェクト: retallickj/qca-embed
    def ichaFields(self):
        '''estimate the fields by assuming the ground state is known'''

        # construct Hamiltonian
        if self.use3D:
            Hs = self.constructIsing3D(self.opt['theta'])
        else:
            theta = .5*np.pi*np.ones(self.N)
            Hs = self.constructIsing2D(theta)

        # find ground state
        evals, evecs = solve_sparse(Hs, k=1)
        grnd = evecs[:,0].reshape([-1,])

        # compute expectation values
        expect_x = lambda n: np.sum(grnd.conj()*core.pauli_x(n, self.N)*grnd)
        expect_z = lambda n: np.sum(grnd.conj()*core.pauli_z(n, self.N)*grnd)

        Ex = np.array([expect_x(n).real for n in range(1, self.N+1)])
        Ez = np.array([expect_z(n).real for n in range(1, self.N+1)])

        nx = -self.gam
        nz = self.h + .5*np.dot(self.J, Ez)

        theta = np.arctan2(nz, nx)
        return theta
コード例 #2
0
ファイル: spectrum.py プロジェクト: whigg/qca-embed
    def run_rp(self, gset, caching, cache_dir):
        '''Compute the spectrum using the old RP-Solver'''

        print('\nRunning Old RP-Solver method...')
        t = time()

        if caching:
            cache_dir = CACHE if cache_dir is None else cache_dir
        else:
            cache_dir = None

        # find initial modes
        print('Finding initial modes...'),
        e_vals, e_vac, modes = rp_solve(self.h,
                                        self.J,
                                        gam=gset,
                                        verbose=False,
                                        cache_dir=cache_dir)

        print('{0:.2f} sec'.format(time() - t))

        print('Number of included modes: {0}'.format(len(modes)))

        # pre-compute sparse Hamiltonian components
        print('Pre-computing sparse Hamiltonian components...'),
        t = time()
        Hx = build_comp_H([self.h], [self.J], [], 1., [modes])
        diag = Hx.diagonal()
        Hx.setdiag([0] * diag.size)
        print('{0:.2f} sec'.format(time() - t))

        spectrum = []

        print('number of modes: {0}'.format(len(modes)))
        print('Estimating spectrum sweep...')

        for i, (gamma, ep) in enumerate(zip(self.gammas, self.eps)):
            sys.stdout.write('\r{0:.2f}%'.format(i * 100. / self.nsteps))
            sys.stdout.flush()
            Hs = Hx * gamma
            Hs.setdiag(ep * diag)
            e_vals, e_vecs = solve_sparse(Hs, more=True)
            spectrum.append(e_vals)
        print('...done')

        return spectrum
コード例 #3
0
ファイル: spectrum.py プロジェクト: retallickj/qca-embed
    def run_rp(self, gset, caching, cache_dir):
        '''Compute the spectrum using the old RP-Solver'''

        print('\nRunning Old RP-Solver method...')
        t = time()

        if caching:
            cache_dir = CACHE if cache_dir is None else cache_dir
        else:
            cache_dir = None

        # find initial modes
        print('Finding initial modes...'),
        e_vals, e_vac, modes = rp_solve(self.h, self.J, gam=gset,
                                        verbose=False, cache_dir=cache_dir)

        print('{0:.2f} sec'.format(time()-t))

        print('Number of included modes: {0}'.format(len(modes)))

        # pre-compute sparse Hamiltonian components
        print('Pre-computing sparse Hamiltonian components...'),
        t = time()
        Hx = build_comp_H([self.h], [self.J], [], 1., [modes])
        diag = Hx.diagonal()
        Hx.setdiag([0]*diag.size)
        print('{0:.2f} sec'.format(time()-t))

        spectrum = []

        print('number of modes: {0}'.format(len(modes)))
        print('Estimating spectrum sweep...')

        for i, (gamma, ep) in enumerate(zip(self.gammas, self.eps)):
            sys.stdout.write('\r{0:.2f}%'.format(i*100./self.nsteps))
            sys.stdout.flush()
            Hs = Hx*gamma
            Hs.setdiag(ep*diag)
            e_vals, e_vecs = solve_sparse(Hs, more=True)
            spectrum.append(e_vals)
        print('...done')

        return spectrum
コード例 #4
0
ファイル: proj_study.py プロジェクト: retallickj/qca-embed
def optimalProj(Hs, W):
    '''find the optimal projection operators for a given sparse rep.
    Hamiltonian for the problem instance weights: 0 <= <n|P|n> <= W[n] <= 1'''

    # diagonalize the Hamilonian
    e_vals, e_vecs = solve_sparse(Hs, k=len(W))

    # for each eigenvector, sort indices by vector amplitudes
    inds = set()
    P = [0]*len(W)

    amps = np.absolute(e_vecs)

    for i, w in enumerate(W):

        # get sorted indices
        amp = amps[:,i]
        sinds = np.argsort(amp)[::-1]

        # add in sorted indices until P >= w
        n = 0
        while P[i]<w and n < len(sinds):
            if sinds[n] not in inds:
                inds.add(sinds[n])
                for m in range(len(P)):
                    P[m] += amps[sinds[n],m]**2
            n += 1

    # compute energy errors
    # inds = sorted(inds)
    # Hs = Hs.tocsc()[:,inds]
    # Hs = Hs.tocsr()[inds,:]
    # new_e_vals, new_e_vecs = solve_sparse(Hs, k=len(W))
    #
    # n = min(len(W), len(new_e_vals), len(e_vals))
    # delta = [new_e_vals[i] - e_vals[i] for i in range(n)]

    return sorted(inds)