def coarse_graining(network, state, internal_indices):
    """Find the maximal coarse-graining of a micro-system.

    Args:
        network (Network): The network in question.
        state (tuple[int]): The state of the network.
        internal_indices (tuple[int]): Nodes in the micro-system.

    Returns:
        tuple[int, CoarseGrain]: The phi-value of the maximal |CoarseGrain|.
    """
    max_phi = float('-inf')
    max_coarse_grain = CoarseGrain((), ())

    for coarse_grain in all_coarse_grains(internal_indices):
        try:
            subsystem = MacroSubsystem(network, state, internal_indices,
                                       coarse_grain=coarse_grain)
        except ConditionallyDependentError:
            continue

        phi = compute.phi(subsystem)
        if (phi - max_phi) > constants.EPSILON:
            max_phi = phi
            max_coarse_grain = coarse_grain

    return (max_phi, max_coarse_grain)
Find the maximal coarse-graining of a micro-system.

    Args:
        network (Network): The network in question.
        state (tuple[int]): The state of the network.
        internal_indices (tuple[int]): Nodes in the micro-system.

    Returns:
        tuple[int, CoarseGrain]: The phi-value of the maximal |CoarseGrain|.