def test_chop_inplace_dop(self): a = qu.qu([1, 0.1], 'dop') qu.chop(a, tol=0.11, inplace=True) assert_allclose(a, qu.qu([1, 0], 'dop')) a = qu.qu([1, 0.1], 'dop', sparse=True) qu.chop(a, tol=0.11, inplace=True) b = qu.qu([1, 0.0], 'dop', sparse=True) assert ((a != b).nnz == 0)
def test_chop_inplace(self): a = qu.qu([-1j, 0.1 + 0.2j]) qu.chop(a, tol=0.11, inplace=True) assert_allclose(a, qu.qu([-1j, 0.2j])) # Sparse a = qu.qu([-1j, 0.1 + 0.2j], sparse=True) qu.chop(a, tol=0.11, inplace=True) b = qu.qu([-1j, 0.2j], sparse=True) assert ((a != b).nnz == 0)
def test_chop_copy(self): a = qu.qu([-1j, 0.1 + 0.2j]) b = qu.chop(a, tol=0.11, inplace=False) assert_allclose(a, qu.qu([-1j, 0.1 + 0.2j])) assert_allclose(b, qu.qu([-1j, 0.2j])) # Sparse a = qu.qu([-1j, 0.1 + 0.2j], sparse=True) b = qu.chop(a, tol=0.11, inplace=False) ao = qu.qu([-1j, 0.1 + 0.2j], sparse=True) bo = qu.qu([-1j, 0.2j], sparse=True) assert ((a != ao).nnz == 0) assert ((b != bo).nnz == 0)
def test_thermal_state_hot(self): full = rand_herm(2**4) rhoth = chop(thermal_state(full, 0.0)) assert_allclose(rhoth, eye(2**4) / 2**4)
def test_rand_uni(self): u = rand_uni(3) assert u.shape == (3, 3) assert type(u) == np.matrix assert_allclose(eye(3), chop(u @ u.H, inplace=False)) assert_allclose(eye(3), chop(u.H @ u, inplace=False))