def test_p_squared(self): b = self.hbar * (-BosonOperator('1^ 1^') - BosonOperator('1 1') + BosonOperator('') + 2 * BosonOperator('1^ 1')) / 2 q = normal_ordered(get_quad_operator(b, hbar=self.hbar), hbar=self.hbar) expected = QuadOperator('p1 p1') self.assertTrue(q == expected)
def test_two_mode(self): b = BosonOperator('0^ 2') q = get_quad_operator(b, hbar=self.hbar) expected = QuadOperator('q0') - 1j * QuadOperator('p0') expected *= (QuadOperator('q2') + 1j * QuadOperator('p2')) expected /= 2 * self.hbar self.assertTrue(q == expected)
def test_q_squared(self): b = self.hbar * (BosonOperator('0^ 0^') + BosonOperator('0 0') + BosonOperator('') + 2 * BosonOperator('0^ 0')) / 2 q = normal_ordered(get_quad_operator(b, hbar=self.hbar), hbar=self.hbar) expected = QuadOperator('q0 q0') self.assertTrue(q == expected)
def test_two_term(self): b = BosonOperator('0^ 0') + BosonOperator('0 0^') q = get_quad_operator(b, hbar=self.hbar) expected = (QuadOperator('q0') - 1j*QuadOperator('p0')) \ * (QuadOperator('q0') + 1j*QuadOperator('p0')) \ + (QuadOperator('q0') + 1j*QuadOperator('p0')) \ * (QuadOperator('q0') - 1j*QuadOperator('p0')) expected /= 2 * self.hbar self.assertTrue(q == expected)
def test_annihilation(self): b = BosonOperator('0') q = get_quad_operator(b, hbar=self.hbar) expected = QuadOperator('q0') + 1j * QuadOperator('p0') expected /= numpy.sqrt(2 * self.hbar) self.assertTrue(q == expected)
def test_identity(self): b = BosonOperator('') q = get_quad_operator(b) self.assertTrue(q == QuadOperator.identity())
def test_zero(self): b = BosonOperator() q = get_quad_operator(b) self.assertTrue(q == QuadOperator.zero())
def test_invalid_op(self): op = QuadOperator() with self.assertRaises(TypeError): _ = get_quad_operator(op)