Exemplo n.º 1
0
def test_unitary():
    U = UnitaryOperator('U')

    assert isinstance(U, UnitaryOperator)
    assert isinstance(U, Operator)

    assert U.inv() == Dagger(U)
    assert U*Dagger(U) == 1
    assert Dagger(U)*U == 1
    assert U.is_commutative is False
    assert Dagger(U).is_commutative is False
Exemplo n.º 2
0
 def _eval_args(cls, args):
     if len(args) != 2:
         raise QuantumError(
             'Insufficient/excessive arguments to Oracle.  Please ' +
             'supply the number of qubits and an unknown function.')
     sub_args = args[0],
     sub_args = UnitaryOperator._eval_args(sub_args)
     if not sub_args[0].is_Integer:
         raise TypeError('Integer expected, got: %r' % sub_args[0])
     if not callable(args[1]):
         raise TypeError('Callable expected, got: %r' % args[1])
     sub_args = UnitaryOperator._eval_args(tuple(range(args[0])))
     return (sub_args, args[1])
Exemplo n.º 3
0
 def _eval_args(cls, args):
     if len(args) != 2:
         raise QuantumError(
             'Insufficient/excessive arguments to Oracle.  Please ' +
                 'supply the number of qubits and an unknown function.'
         )
     sub_args = args[0],
     sub_args = UnitaryOperator._eval_args(sub_args)
     if not sub_args[0].is_Integer:
         raise TypeError('Integer expected, got: %r' % sub_args[0])
     if not callable(args[1]):
         raise TypeError('Callable expected, got: %r' % args[1])
     sub_args = UnitaryOperator._eval_args(tuple(range(args[0])))
     return (sub_args, args[1])
Exemplo n.º 4
0
Arquivo: gate.py Projeto: yangle/sympy
 def _eval_args(cls, args):
     # _eval_args has the right logic for the controls argument.
     controls = args[0]
     gate = args[1]
     if not is_sequence(controls):
         controls = (controls,)
     controls = UnitaryOperator._eval_args(controls)
     _validate_targets_controls(chain(controls,gate.targets))
     return (Tuple(*controls), gate)
Exemplo n.º 5
0
 def _eval_args(cls, args):
     if len(args) != 1:
         raise QuantumError(
             'Insufficient/excessive arguments to W gate.  Please ' +
             'supply the number of qubits to operate on.')
     args = UnitaryOperator._eval_args(args)
     if not args[0].is_Integer:
         raise TypeError('Integer expected, got: %r' % args[0])
     return args
Exemplo n.º 6
0
 def _eval_args(cls, args):
     # _eval_args has the right logic for the controls argument.
     controls = args[0]
     gate = args[1]
     if not is_sequence(controls):
         controls = (controls,)
     controls = UnitaryOperator._eval_args(controls)
     _validate_targets_controls(chain(controls, gate.targets))
     return (Tuple(*controls), gate)
Exemplo n.º 7
0
Arquivo: gate.py Projeto: fxkr/sympy
 def _eval_args(cls, args):
     # _eval_args has the right logic for the controls argument.
     controls = args[0]
     gate = args[1]
     if not ordered_iter(controls, include=Tuple):
         controls = (controls,)
     controls = UnitaryOperator._eval_args(controls)
     _validate_targets_controls(chain(controls,gate.targets))
     return (controls, gate)
Exemplo n.º 8
0
 def _eval_args(cls, args):
     # _eval_args has the right logic for the controls argument.
     controls = args[0]
     gate = args[1]
     if not ordered_iter(controls):
         controls = (controls, )
     controls = UnitaryOperator._eval_args(controls)
     _validate_targets_controls(chain(controls, gate.targets))
     return (controls, gate)
Exemplo n.º 9
0
 def _eval_args(cls, args):
     if len(args) != 1:
         raise QuantumError(
             'Insufficient/excessive arguments to W gate.  Please ' +
             'supply the number of qubits to operate on.'
         )
     args = UnitaryOperator._eval_args(args)
     if not args[0].is_Integer:
         raise TypeError('Integer expected, got: %r' % args[0])
     return args
Exemplo n.º 10
0
    def _eval_args(cls, args):
        if len(args) != 2:
            raise QuantumError(
                'Insufficient/excessive arguments to Oracle.  Please ' +
                'supply the number of qubits and an unknown function.')
        sub_args = (args[0], )
        sub_args = UnitaryOperator._eval_args(sub_args)
        if not sub_args[0].is_Integer:
            raise TypeError('Integer expected, got: %r' % sub_args[0])

        function = args[1]
        if not isinstance(function, OracleGateFunction):
            function = OracleGateFunction(function)

        return (sub_args[0], function)
Exemplo n.º 11
0
    def _eval_args(cls, args):
        # TODO: args[1] is not a subclass of Basic
        if len(args) != 2:
            raise QuantumError(
                "Insufficient/excessive arguments to Oracle.  Please "
                + "supply the number of qubits and an unknown function."
            )
        sub_args = (args[0],)
        sub_args = UnitaryOperator._eval_args(sub_args)
        if not sub_args[0].is_Integer:
            raise TypeError("Integer expected, got: %r" % sub_args[0])

        if not callable(args[1]):
            raise TypeError("Callable expected, got: %r" % args[1])
        return (sub_args[0], args[1])
def non_commutative_sympify(expr_string, status, boolean):
    if "^" in expr_string:
        expr_string = expr_string.replace("^", "**")

    if "Ad" in expr_string:
        expr_string = expr_string.replace("Ad", "Dagger")

    fixed_string = ""
    if 'Dagger' in expr_string:
        fixed_string = expr_string.replace("Dagger", "sin")
    else:
        fixed_string = expr_string
    temp_evaluated_expr = parse_expr(fixed_string, evaluate=False)
    if status == '0':
        status1 = False
    elif status == '1':
        status1 = True

    new_locals = {
        sym.name: Symbol(sym.name, commutative=status1)
        for sym in temp_evaluated_expr.atoms(Symbol)
    }

    #new_locals = {}
    #for sym in temp_evaluated_expr.atoms(Symbol):
    #       new_locals.update({sym.name:Operator(sym.name)})

    #{'C': C, 'E': E, 'I': I, 'N': N, 'O': O, 'Q': Q, 'S': S}

    new_locals.update({'U': UnitaryOperator('U')})
    new_locals.update({'c': Symbol('c', commutative=True)})
    new_locals.update({'r': Symbol('r', commutative=True)})
    new_locals.update({'t': Symbol('t', commutative=True)})
    new_locals.update({'W': UnitaryOperator('W')})
    new_locals.update({'V': UnitaryOperator('V')})
    new_locals.update({'u': UnitaryOperator('u')})
    new_locals.update({'w': UnitaryOperator('w')})
    new_locals.update({'v': UnitaryOperator('v')})
    new_locals.update({'H': HermitianOperator('H')})
    new_locals.update({'A': HermitianOperator('A')})
    new_locals.update({'T': HermitianOperator('T')})
    new_locals.update({'C': Operator('C')})
    new_locals.update({'Dagger': Dagger})

    return sympify(expr_string, locals=new_locals, evaluate=boolean)
Exemplo n.º 13
0
Arquivo: gate.py Projeto: yangle/sympy
 def _eval_args(cls, args):
     args = Tuple(*UnitaryOperator._eval_args(args))
     _validate_targets_controls(args)
     return args
Exemplo n.º 14
0
def test_sympy__physics__quantum__operator__UnitaryOperator():
    from sympy.physics.quantum.operator import UnitaryOperator
    assert _test_args(UnitaryOperator('U'))
Exemplo n.º 15
0
 def _eval_args(cls, args):
     args = Tuple(*UnitaryOperator._eval_args(args))
     _validate_targets_controls(args)
     return args