示例#1
0
def test_equivalent_to_builtin_mul():
    test_vals = [
        0,
        1,
        1j,
        -2.5,
        Neither(),
        MulReturnsNotImplemented(),
        RMulReturnsNotImplemented(),
        MulReturnsFive(),
        RMulReturnsSix(),
        MulSevenRMulEight(),
    ]

    for a in test_vals:
        for b in test_vals:
            if type(a) == type(b) == RMulReturnsSix:
                # Python doesn't do __rmul__ if __mul__ failed and
                # type(a) == type(b). But we do.
                continue

            c = cirq.mul(a, b, default=None)
            if c is None:
                with pytest.raises(TypeError):
                    _ = a * b
                with pytest.raises(TypeError):
                    _ = cirq.mul(a, b)
            else:
                assert c == a * b
示例#2
0
 def __pow__(self, exponent: Union[float, sympy.Symbol]) -> 'GoodGate':
     new_exponent = cirq.mul(self.exponent, exponent, NotImplemented)
     if new_exponent is NotImplemented:
         # coverage: ignore
         return NotImplemented
     return GoodGate(phase_exponent=self.phase_exponent,
                     exponent=new_exponent)
示例#3
0
 def __pow__(self, power):
     new_exponent = cirq.mul(self.exponent, power, NotImplemented)
     if new_exponent is NotImplemented:
         # coverage: ignore
         return NotImplemented
     return PhaseGradientGate(num_qubits=self._num_qubits,
                              exponent=new_exponent)
示例#4
0
 def __pow__(self, power) -> 'FSimGate':
     return RBS(cirq.mul(self.theta, power))
示例#5
0
 def __pow__(self, power) -> 'FSimGate':
     return FSimGate(cirq.mul(self.theta, power), cirq.mul(self.phi, power))
示例#6
0
def test_symbol_special_case():
    x = sympy.Symbol('x')
    assert cirq.mul(x, 1.0) is x
    assert cirq.mul(1.0, x) is x
示例#7
0
def test_symbol_special_case():
    x = sympy.Symbol('x')
    assert cirq.mul(x, 1.0) is x
    assert cirq.mul(1.0, x) is x
    assert str(cirq.mul(-1.0, x)) == '-x'
    assert str(cirq.mul(x, -1.0)) == '-x'