def test_spin_half(self): Sx = qu.spin_operator('x', 1 / 2) assert_allclose(Sx, [[0.0, 0.5], [0.5, 0.0]]) Sy = qu.spin_operator('y', 1 / 2) assert_allclose(Sy, [[0.0, -0.5j], [0.5j, 0.0]]) Sz = qu.spin_operator('z', 1 / 2) assert_allclose(Sz, [[0.5, 0.0], [0.0, -0.5]]) Sp = qu.spin_operator('+', 1 / 2) assert_allclose(Sp, [[0.0, 1.0], [0.0, 0.0]]) Sm = qu.spin_operator('-', 1 / 2) assert_allclose(Sm, [[0.0, 0.0], [1.0, 0.0]])
def test_insert_operator(self): p = MPS_rand_state(3, 7, tags='KET') q = p.H.retag({'KET': 'BRA'}) qp = q & p sz = qu.spin_operator('z').real qp.insert_operator(sz, ('KET', 'I1'), ('BRA', 'I1'), tags='SZ', inplace=True) assert 'SZ' in qp.tags assert len(qp.tensors) == 7 x1 = qp ^ all x2 = qu.expec(p.to_dense(), qu.ikron(sz, [2, 2, 2], inds=1)) assert x1 == pytest.approx(x2)
def test_1d_vector_methods(self): X = qu.spin_operator('X', sparse=True) mera = qt.MERA.rand(16) meraX = mera.gate(X.A, 7, inplace=False) assert mera is not meraX x1 = mera.H @ meraX md = mera.to_dense() mdX = qu.ikron(X, [2] * 16, 7) @ md x2 = md.H @ mdX # check against dense assert x1 == pytest.approx(x2) # check 'outside lightcone' unaffected assert mera.select(3).H @ meraX.select(3) == pytest.approx(1.0) # check only need 'lightcone' to compute local assert mera.select(7).H @ meraX.select(7) == pytest.approx(x2)
def test_spin_high(self, label, S): D = int(2 * S + 1) op = qu.spin_operator(label, S) assert_allclose(qu.eigvalsh(op), np.linspace(-S, S, D), atol=1e-13)