コード例 #1
0
ファイル: test_calc.py プロジェクト: zeta1999/quimb
 def test_mutinf_interleave(self):
     p = qu.dop(qu.singlet() & qu.singlet())
     ixy = qu.mutual_information(p, [2] * 4, sysa=(0, 2))
     assert_allclose(ixy, 4)
コード例 #2
0
 def test_types(self, k1, k2):
     td1 = trace_distance(k1, k2)
     td2 = trace_distance(dop(k1), k2)
     td3 = trace_distance(k1, dop(k2))
     td4 = trace_distance(dop(k1), dop(k2))
     assert_allclose([td1] * 3, [td2, td3, td4])
コード例 #3
0
ファイル: test_calc.py プロジェクト: zizai/quimb
 def test_types(self, k1, k2):
     td1 = qu.trace_distance(k1, k2)
     td2 = qu.trace_distance(qu.dop(k1), k2)
     td3 = qu.trace_distance(k1, qu.dop(k2))
     td4 = qu.trace_distance(qu.dop(k1), qu.dop(k2))
     assert_allclose([td1] * 3, [td2, td3, td4])
コード例 #4
0
    def test_evo_timedep_adiabatic_with_callbacks(self, dop, linop,
                                                  num_callbacks):
        # tests time dependent Evolution via an adiabatic sweep with:
        #   a) no callbacks
        #   b) 1 callback that accesses the time-dependent Hamiltonian
        #   c) 2 callbacks where one access the Hamiltonian and one doesn't

        if num_callbacks > 0 and (dop or linop):
            # should implement this at some point
            return
        L = 6
        T = 20

        H1 = qu.ham_mbl(L, dh=1.0, seed=4, sparse=True)
        gs1 = qu.groundstate(H1)
        H2 = qu.ham_mbl(L, dh=1.0, seed=5, sparse=True)
        gs2 = qu.groundstate(H2)

        if linop:
            import scipy.sparse.linalg as spla

            H1 = spla.aslinearoperator(H1)
            H2 = spla.aslinearoperator(H2)

        # make sure two ground states are different
        assert qu.fidelity(gs1, gs2) < 0.5

        # linearly interpolate from one ham to the other
        def ham(t):
            return (1 - t / T) * H1 + (t / T) * H2

        if linop:
            assert isinstance(ham(0.3), spla.LinearOperator)

        if dop:
            p0 = qu.dop(gs1)
        else:
            p0 = gs1

        if num_callbacks == 0:
            evo = qu.Evolution(p0, ham, progbar=True)
        else:

            def gs_overlap(t, pt, H):
                evals, evecs = eigs_scipy(H(t), k=1, which='SA')
                return np.abs(qu.dot(pt.T, qu.qu(evecs[:, 0])))**2

            if num_callbacks == 1:
                compute = gs_overlap
            if num_callbacks == 2:

                def norm(t, pt):
                    return qu.dot(pt.T, pt)

                compute = {'norm': norm, 'gs_overlap': gs_overlap}
            evo = qu.Evolution(p0, ham, compute=compute, progbar=True)
        evo.update_to(T)

        # final state should now overlap much more with second hamiltonian GS
        assert qu.fidelity(evo.pt, gs1) < 0.5
        assert qu.fidelity(evo.pt, gs2) > 0.99

        if num_callbacks == 1:
            gs_overlap_results = evo.results
            # check that we stayed in the ground state the whole time
            assert ((np.array(gs_overlap_results) - 1.0) < 1e-3).all()

        if num_callbacks == 2:
            norm_results = evo.results['norm']
            gs_overlap_results = evo.results['gs_overlap']
            # check that we stayed normalized the whole time
            assert ((np.array(norm_results) - 1.0) < 1e-3).all()
            # check that we stayed in the ground state the whole time
            assert ((np.array(gs_overlap_results) - 1.0) < 1e-3).all()