def from_matrix(u: np.ndarray) -> PhasedFSimGate | None:
        """Contruct a PhasedFSimGate from unitary.

        Args:
            u: A unitary matrix representing a PhasedFSimGate.

        Returns:
            - Either PhasedFSimGate with the given unitary or None if
                the matrix is not unitary or if doesn't represent a PhasedFSimGate.
        """

        gamma = np.angle(u[1, 1] * u[2, 2] - u[1, 2] * u[2, 1]) / -2
        phi = -np.angle(u[3, 3]) - 2 * gamma
        phased_cos_theta_2 = u[1, 1] * u[2, 2]
        if phased_cos_theta_2 == 0:
            # The zeta phase is multiplied with cos(theta),
            # so if cos(theta) is zero then any value is possible.
            zeta = 0
        else:
            zeta = np.angle(u[2, 2] / u[1, 1]) / 2

        phased_sin_theta_2 = u[1, 2] * u[2, 1]
        if phased_sin_theta_2 == 0:
            # The chi phase is multiplied with sin(theta),
            # so if sin(theta) is zero then any value is possible.
            chi = 0
        else:
            chi = np.angle(u[1, 2] / u[2, 1]) / 2

        theta = np.angle(
            np.exp(1j * (gamma + zeta)) * u[1, 1] - np.exp(1j * (gamma - chi)) * u[1, 2]
        )

        gate = PhasedFSimGate(theta=theta, phi=phi, chi=chi, zeta=zeta, gamma=gamma)
        if np.allclose(u, protocols.unitary(gate)):
            return gate
        return None
Contruct a PhasedFSimGate from unitary.

        Args:
            u: A unitary matrix representing a PhasedFSimGate.

        Returns:
            - Either PhasedFSimGate with the given unitary or None if
                the matrix is not unitary or if doesn't represent a PhasedFSimGate.
        
cirq-core/cirq/ops/fsim_gate.py