def test_circuit_structure(): syc = FakeSycamoreGate() ops = cirq.decompose_cphase_into_two_fsim(cirq.CZ, fsim_gate=syc) num_interaction_moments = 0 for op in ops: assert len(op.qubits) in (0, 1, 2) if len(op.qubits) == 2: num_interaction_moments += 1 assert isinstance(op.gate, FakeSycamoreGate) assert num_interaction_moments == 2
def test_parameterized_gates(): t = sympy.Symbol('t') with pytest.raises(ValueError): cphase_gate = cirq.CZPowGate(exponent=t) fsim_gate = FakeSycamoreGate() cirq.decompose_cphase_into_two_fsim(cphase_gate, fsim_gate=fsim_gate) with pytest.raises(ValueError): cphase_gate = cirq.CZ fsim_gate = cirq.FSimGate(theta=t, phi=np.pi / 2) cirq.decompose_cphase_into_two_fsim(cphase_gate, fsim_gate=fsim_gate) with pytest.raises(ValueError): cphase_gate = cirq.CZ fsim_gate = cirq.FSimGate(theta=np.pi / 2, phi=t) cirq.decompose_cphase_into_two_fsim(cphase_gate, fsim_gate=fsim_gate)
def assert_decomposition_valid(cphase_gate, fsim_gate): u_expected = cirq.unitary(cphase_gate) ops = cirq.decompose_cphase_into_two_fsim(cphase_gate, fsim_gate=fsim_gate) u_actual = cirq.unitary(cirq.Circuit(ops)) assert np.allclose(u_actual, u_expected)
def test_invalid_qubits(): with pytest.raises(ValueError): cirq.decompose_cphase_into_two_fsim(cphase_gate=cirq.CZ, fsim_gate=FakeSycamoreGate(), qubits=cirq.LineQubit.range(3))
def test_invalid_fsim_gate(bad_fsim_gate): with pytest.raises(ValueError): cirq.decompose_cphase_into_two_fsim(cirq.CZ, fsim_gate=bad_fsim_gate)
def test_invalid_qubits(): with pytest.raises(ValueError): cirq.decompose_cphase_into_two_fsim(cphase_gate=cirq.CZ, fsim_gate=cirq.google.SYC, qubits=cirq.LineQubit.range(3))