Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 6
0
 def test_identity(self):
     b = BosonOperator('')
     q = get_quad_operator(b)
     self.assertTrue(q == QuadOperator.identity())
Ejemplo n.º 7
0
 def test_zero(self):
     b = BosonOperator()
     q = get_quad_operator(b)
     self.assertTrue(q == QuadOperator.zero())
Ejemplo n.º 8
0
 def test_invalid_op(self):
     op = QuadOperator()
     with self.assertRaises(TypeError):
         _ = get_quad_operator(op)