def test_zztheta():
    zz = np.kron(cirq.unitary(cirq.Z), cirq.unitary(cirq.Z))
    qubits = cirq.LineQubit.range(2)
    for theta in np.linspace(0, 2 * np.pi, 10):
        expected_unitary = scipy.linalg.expm(-1j * theta * zz)
        circuit = cirq.Circuit(cgoc.rzz(theta, qubits[0], qubits[1]))
        actual_unitary = cirq.unitary(circuit)
        cirq.testing.assert_allclose_up_to_global_phase(actual_unitary, expected_unitary, atol=1e-7)
def test_zztheta_zzpow():
    qubits = cirq.LineQubit.range(2)
    for theta in np.linspace(0, 2 * np.pi, 10):
        syc_circuit = cirq.Circuit(cgoc.rzz(theta, qubits[0], qubits[1]))
        cirq_circuit = cirq.Circuit([
            cirq.ZZPowGate(exponent=2 * theta / np.pi,
                           global_shift=-0.5).on(*qubits)
        ])
        cirq.testing.assert_allclose_up_to_global_phase(
            cirq.unitary(cirq_circuit), cirq.unitary(syc_circuit), atol=1e-7)
예제 #3
0
def zz_as_syc(theta: float, q0: cirq.Qid, q1: cirq.Qid) -> cirq.Circuit:
    """Return an Exp[i theta ZZ] circuit with two SYC gates."""
    swz = cirq.Circuit(rzz(theta, q0, q1))
    _SingleQubitGates().optimize_circuit(swz)
    cirq.DropEmptyMoments().optimize_circuit(swz)
    return swz