def test_invalid_cphase_exponents(theta, phi): fsim_gate = cirq.FSimGate(theta=theta, phi=phi) valid_exponent_intervals = cirq.compute_cphase_exponents_for_fsim_decomposition(fsim_gate) invalid_exponent_intervals = complement_intervals(valid_exponent_intervals) assert invalid_exponent_intervals for min_exponent, max_exponent in invalid_exponent_intervals: margin = 1e-8 min_exponent += margin max_exponent -= margin assert min_exponent < max_exponent for exponent in np.linspace(min_exponent, max_exponent, 3): with pytest.raises(ValueError): cphase_gate = cirq.CZPowGate(exponent=exponent) assert_decomposition_valid(cphase_gate, fsim_gate=fsim_gate)
def test_valid_cphase_exponents(theta, phi): fsim_gate = cirq.FSimGate(theta=theta, phi=phi) valid_exponent_intervals = cirq.compute_cphase_exponents_for_fsim_decomposition(fsim_gate) assert valid_exponent_intervals for min_exponent, max_exponent in valid_exponent_intervals: margin = 1e-8 min_exponent += margin max_exponent -= margin assert min_exponent < max_exponent for exponent in np.linspace(min_exponent, max_exponent, 3): for d in (-2, 0, 4): cphase_gate = cirq.CZPowGate(exponent=exponent + d) assert_decomposition_valid(cphase_gate, fsim_gate=fsim_gate) cphase_gate = cirq.CZPowGate(exponent=-exponent + d) assert_decomposition_valid(cphase_gate, fsim_gate=fsim_gate)
def test_symbols(): with pytest.raises(ValueError, match='Symbolic arguments'): cirq.compute_cphase_exponents_for_fsim_decomposition( cirq.FSimGate(theta=sympy.Symbol('t'), phi=sympy.Symbol('phi')))