Example #1
0
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
Example #2
0
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)
Example #3
0
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)
Example #4
0
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))
Example #5
0
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)
Example #6
0
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))