Пример #1
0
 def test_progbar_update_to_integrate(self, capsys):
     ham = ham_heis(2, cyclic=False)
     p0 = up() & down()
     sim = Evolution(p0, ham, method='integrate', progbar=True)
     sim.update_to(100)
     # check something as been printed
     _, err = capsys.readouterr()
     assert err and "%" in err
Пример #2
0
 def test_evo_ham_dense_ket_solve(self, ham_rcr_psi, sparse, presolve):
     ham, trc, p0, tm, pm = ham_rcr_psi
     ham = qu(ham, sparse=sparse)
     if presolve:
         l, v = eigh(ham)
         sim = Evolution(p0, (l, v))
         assert sim._solved
     else:
         sim = Evolution(p0, ham, method='solve')
     sim.update_to(tm)
     assert_allclose(sim.pt, pm)
     assert expec(sim.pt, p0) < 1.0
     sim.update_to(trc)
     assert_allclose(sim.pt, p0)
     assert isinstance(sim.pt, qarray)
     assert sim.t == trc
Пример #3
0
    def test_evo_ham(self, ham_rcr_psi, sparse, dop, method):
        ham, trc, p0, tm, pm = ham_rcr_psi
        if dop:
            if method == 'expm':
                # XXX: not implemented
                return
            p0 = p0 @ p0.H
            pm = pm @ pm.H

        if method == 'bad':
            with raises(ValueError):
                Evolution(p0, ham, method=method)
            return

        ham = qu(ham, sparse=sparse)
        sim = Evolution(p0, ham, method=method)
        sim.update_to(tm)
        assert_allclose(sim.pt, pm, rtol=1e-4, atol=1e-6)
        assert expec(sim.pt, p0) < 1.0
        sim.update_to(trc)
        assert_allclose(sim.pt, p0, rtol=1e-4, atol=1e-6)
        assert isinstance(sim.pt, qarray)
        assert sim.t == trc