def rotated_surface_code_memory_z_cycle(
    data_qubits: set[cirq.Qid],
    z_measure_qubits: set[cirq.Qid],
    x_measure_qubits: set[cirq.Qid],
    z_order: Sequence[tuple[int, int]],
    x_order: Sequence[tuple[int, int]],
) -> cirq.Circuit:
    """Constructs a circuit for a single round of rotated memory Z surface code.

    Args:
        data_qubits: data qubits for the surface code patch.
        z_measure_qubits: measure qubits to measure Z stabilizers for surface code patch.
        x_measure_qubits: measure qubits to measure X stabilizers for surface code patch.
        z_order: Specifies the order in which the 2/4 data qubit neighbours of a Z measure qubit
            should be processed.
        x_order: Specifies the order in which the 2/4 data qubit neighbours of a X measure qubit
            should be processed.

    Returns:
        A `cirq.Circuit` for a single round of rotated memory Z surface code cycle.
    """

    circuit = cirq.Circuit()
    circuit += cirq.Moment([cirq.H(q) for q in x_measure_qubits])
    for k in range(4):
        op_list = []
        for measure_qubits, add, is_x in [
            [x_measure_qubits, x_order[k], True],
            [z_measure_qubits, z_order[k], False],
        ]:
            for q_meas in measure_qubits:
                q_data = q_meas + add
                if q_data in data_qubits:
                    op_list.append(cirq.CNOT(q_meas, q_data) if is_x else cirq.CNOT(q_data, q_meas))
        circuit += cirq.Moment(op_list)
    circuit += cirq.Moment([cirq.H(q) for q in x_measure_qubits])
    circuit += cirq.Moment(cirq.measure_each(*x_measure_qubits, *z_measure_qubits))
    return circuit
Constructs a circuit for a single round of rotated memory Z surface code.

    Args:
        data_qubits: data qubits for the surface code patch.
        z_measure_qubits: measure qubits to measure Z stabilizers for surface code patch.
        x_measure_qubits: measure qubits to measure X stabilizers for surface code patch.
        z_order: Specifies the order in which the 2/4 data qubit neighbours of a Z measure qubit
            should be processed.
        x_order: Specifies the order in which the 2/4 data qubit neighbours of a X measure qubit
            should be processed.

    Returns:
        A `cirq.Circuit` for a single round of rotated memory Z surface code cycle.
    
benchmarks/circuit_construction.py