def test_addterms(self): ssys = SpinSystem(['mu', 'e']) t1 = ssys.add_linear_term(0, [1, 0, 1]) self.assertEqual(t1.label, 'Single') self.assertEqual(t1.operator, ssys.operator({0: 'x'}) + ssys.operator({0: 'z'})) t2 = ssys.add_bilinear_term(0, 1, np.eye(3)) self.assertEqual(t2.label, 'Double') self.assertEqual(t2.operator, ssys.operator({0: 'x', 1: 'x'}) + ssys.operator({0: 'y', 1: 'y'}) + ssys.operator({0: 'z', 1: 'z'})) H = ssys.hamiltonian self.assertTrue(np.all(np.isclose(H.matrix, np.array([[0.75, 0, 0.5, 0.0], [0, 0.25, 0.5, 0.5], [0.5, 0.5, -0.75, 0], [0.0, 0.5, 0, -0.25]])))) ssys.add_dissipative_term(ssys.operator({0: 'x'}), 1.0) self.assertTrue(ssys.is_dissipative)
def test_lindbladian(self): ssys = SpinSystem(['mu']) ssys.add_linear_term(0, [0, 0, 1]) H = ssys.hamiltonian L = ssys.lindbladian L0 = -1.0j*SuperOperator.commutator(ssys.operator({0: 'z'})) self.assertTrue(np.all(np.isclose(L.matrix, L0.matrix))) sx = ssys.operator({0: 'x'}) d = 2.0 ssys.add_dissipative_term(sx, d) L1 = L0 + d*(SuperOperator.bracket(sx) - 0.5*SuperOperator.anticommutator(sx*sx)) L = ssys.lindbladian self.assertTrue(np.all(np.isclose(L.matrix, L1.matrix)))