Пример #1
0
    def test_commutes_identity(self):
        com = commutator(FermionOperator.identity(),
                         FermionOperator('2^ 3', 2.3))
        self.assertEqual(com, FermionOperator.zero())

        com = commutator(BosonOperator.identity(), BosonOperator('2^ 3', 2.3))
        self.assertTrue(com == BosonOperator.zero())

        com = commutator(QuadOperator.identity(), QuadOperator('q2 p3', 2.3))
        self.assertTrue(com == QuadOperator.zero())
Пример #2
0
    def test_commutes_no_intersection(self):
        com = commutator(FermionOperator('2^ 3'), FermionOperator('4^ 5^ 3'))
        com = normal_ordered(com)
        self.assertEqual(com, FermionOperator.zero())

        com = commutator(BosonOperator('2^ 3'), BosonOperator('4^ 5^ 3'))
        com = normal_ordered(com)
        self.assertTrue(com == BosonOperator.zero())

        com = commutator(QuadOperator('q2 p3'), QuadOperator('q4 q5 p3'))
        com = normal_ordered(com)
        self.assertTrue(com == QuadOperator.zero())
Пример #3
0
 def test_weyl_empty(self):
     res = weyl_polynomial_quantization('')
     self.assertTrue(res == QuadOperator.zero())
Пример #4
0
 def test_zero(self):
     b = BosonOperator()
     q = get_quad_operator(b)
     self.assertTrue(q == QuadOperator.zero())
Пример #5
0
def weyl_polynomial_quantization(polynomial):
    r""" Apply the Weyl quantization to a phase space polynomial.

    The Weyl quantization is performed by applying McCoy's formula
    directly to a polynomial term of the form q^m p^n:

    q^m p^n ->
        (1/ 2^n) sum_{r=0}^{n} Binomial(n, r) \hat{q}^r \hat{p}^m q^{n-r}

    where q and p are phase space variables, and \hat{q} and \hat{p}
    are quadrature operators.

    The input is provided in the form of a string, for example

    .. code-block:: python

        weyl_polynomial_quantization('q0^2 p0^3 q1^3')

    where 'q' or 'p' is the phase space quadrature variable, the integer
    directly following is the mode it is with respect to, and '^2' is the
    polynomial power.

    Args:
        polynomial (str): polynomial function of q and p of the form
            'qi^m pj^n ...' where i,j are the modes, and m, n the powers.

    Returns:
        QuadOperator: the Weyl quantization of the phase space function.

    Warning:
        The runtime of this method is exponential in the maximum locality
        of the original operator.
    """
    # construct the equivalent QuadOperator
    poly = dict()

    if polynomial:
        for term in polynomial.split():
            if '^' in term:
                op, pwr = term.split('^')
                pwr = int(pwr)
            else:
                op = term
                pwr = 1

            mode = int(op[1:])

            if mode not in poly:
                poly[mode] = [0, 0]

            if op[0] == 'q':
                poly[mode][0] += pwr
            elif op[0] == 'p':
                poly[mode][1] += pwr

        # replace {q_i^m p_i^n} -> S({q_i^m p_i^n})
        operator = QuadOperator('')
        for mode, (m, n) in poly.items():
            qtmp = QuadOperator()
            qtmp.terms = mccoy(mode, 'q', 'p', m, n)
            operator *= qtmp
    else:
        operator = QuadOperator.zero()

    return operator