def get_gate(self, dt_frac, sites=None): """Get the unitary (exponentiated) gate for fraction of timestep ``dt_frac`` and sites ``sites``, cached. """ if sites not in self.H.special_sites: sites = None try: return self._U_ints[dt_frac, sites] except KeyError: U = qu.expm(-1.0j * self._dt * dt_frac * self.H(sites)) self._U_ints[dt_frac, sites] = U return U
def test_eye(self, sparse, herm): p = qu.expm(qu.eye(2, sparse=sparse), herm=herm) assert_allclose((p.A if sparse else p) / np.e, qu.eye(2)) if sparse: assert isinstance(p, sp.csr_matrix)
def test_zeros_dense(self, herm): p = qu.expm(np.zeros((2, 2), dtype=complex), herm=herm) assert_allclose(p, qu.eye(2))