Example #1
0
 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)
Example #2
0
 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)
Example #3
0
 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)
Example #4
0
 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)
Example #5
0
 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)
Example #6
0
 def test_identity(self):
     b = BosonOperator('')
     q = get_quad_operator(b)
     self.assertTrue(q == QuadOperator.identity())
Example #7
0
 def test_zero(self):
     b = BosonOperator()
     q = get_quad_operator(b)
     self.assertTrue(q == QuadOperator.zero())
Example #8
0
 def test_invalid_op(self):
     op = QuadOperator()
     with self.assertRaises(TypeError):
         _ = get_quad_operator(op)