
    ph<                         S r SSKrSSKJrJrJrJr  SSKJr  SSK	J
r
  SSKJr  SS	K	Jr  \R                  " \5      rS
 rS rS r " S S\5      rS r " S S\5      rS rS rS rg)z3
Functions for computing network-level properties.
    N   )config
exceptionsutilsvalidate)	_null_sia)	Subsystem   )	MapReducesiac              #      #    [         R                  " U 5        [        R                  " USSS9 H  n [	        XU5      v   M     g! [
        R                   a     M.  f = f7f)z1A generator over all subsystems in a valid state.T)nonemptyreverseN)r   
is_networkr   powersetr	   r   StateUnreachableError)networkindicesstatesubsets       O/home/james-whalen/.local/lib/python3.13/site-packages/pyphi/compute/network.py_reachable_subsystemsr      sX       ..4F	GF33 G // 		s(   0A!AA!AA!AA!c                 .    [        X R                  U5      $ )a  Return a generator of all **possible** subsystems of a network.

.. note::
    Does not return subsystems that are in an impossible state (after
    conditioning the subsystem TPM on the state of the other nodes).

Args:
    network (Network): The |Network| of interest.
    state (tuple[int]): The state of the network (a binary tuple).

Yields:
    Subsystem: A |Subsystem| for each subset of nodes in the network,
    excluding subsystems that would be in an impossible state.
)r   node_indicesr   r   s     r   
subsystemsr   "   s     !*>*>FF    c                 .    [        X R                  U5      $ )a  Return a generator of subsystems of a network that could be a complex.

This is the just powerset of the nodes that have at least one input and
output (nodes with no inputs or no outputs cannot be part of a main
complex, because they do not have a causal link with the rest of the
subsystem in the previous or next timestep, respectively).

.. note::
    Does not return subsystems that are in an impossible state (after
    conditioning the subsystem TPM on the state of the other nodes).

Args:
    network (Network): The |Network| of interest.
    state (tuple[int]): The state of the network (a binary tuple).

Yields:
    Subsystem: The next subsystem that could be a complex.
)r   causally_significant_nodesr   s     r   possible_complexesr!   4   s    & !33U< <r   c                   8    \ rS rSrSrSrS r\S 5       rS r	Sr
g)	FindAllComplexesK   z-Computation engine for finding all complexes.zFinding complexesc                     / $ N )selfs    r   empty_resultFindAllComplexes.empty_resultQ   s    	r   c                     [        U 5      $ r&   r   )	subsystems    r   computeFindAllComplexes.computeT   s    9~r   c                 (    UR                  U5        U$ r&   )appendr(   new_siasiass      r   process_resultFindAllComplexes.process_resultX   s    Gr   r'   N)__name__
__module____qualname____firstlineno____doc__descriptionr)   staticmethodr-   r4   __static_attributes__r'   r   r   r#   r#   K   s*    7 &K  r   r#   c                 h    [        [        X5      5      nUR                  [        R                  5      $ )a  Return a generator for all complexes of the network.

.. note::
    Includes reducible, zero-|big_phi| complexes (which are not, strictly
    speaking, complexes at all).

Args:
    network (Network): The |Network| of interest.
    state (tuple[int]): The state of the network (a binary tuple).

Yields:
    SystemIrreducibilityAnalysis: A |SIA| for each |Subsystem| of the
    |Network|.
)r#   r   runr   PARALLEL_COMPLEX_EVALUATIONr   r   engines      r   all_complexesrC   ]   s(     j89F::f8899r   c                       \ rS rSrSrS rSrg)FindIrreducibleComplexesp   zBComputation engine for finding irreducible complexes of a network.c                 H    UR                   S:  a  UR                  U5        U$ )Nr   )phir0   r1   s      r   r4   'FindIrreducibleComplexes.process_results   s    ;;?KK r   r'   N)r6   r7   r8   r9   r:   r4   r=   r'   r   r   rE   rE   p   s
    Lr   rE   c                 h    [        [        X5      5      nUR                  [        R                  5      $ )a/  Return all irreducible complexes of the network.

Args:
    network (Network): The |Network| of interest.
    state (tuple[int]): The state of the network (a binary tuple).

Yields:
    SystemIrreducibilityAnalysis: A |SIA| for each |Subsystem| of the
    |Network|, excluding those with |big_phi = 0|.
)rE   r!   r?   r   r@   rA   s      r   	complexesrK   y   s)     &&8&HIF::f8899r   c                     [         R                  S5        [        X5      nU(       a  [        U5      nO[	        XS5      n[        U5      n[         R                  S5        U$ )a  Return the major complex of the network.

Args:
    network (Network): The |Network| of interest.
    state (tuple[int]): The state of the network (a binary tuple).

Returns:
    SystemIrreducibilityAnalysis: The |SIA| for the |Subsystem| with
    maximal |big_phi|.
zCalculating major complex...r'   z#Finished calculating major complex.)loginforK   maxr	   r   )r   r   resultempty_subsystems       r   major_complexrR      sO     HH+,w&FV#GB7?+HH23Mr   c                 .  ^ / n[        5       m[        [        [        X5      5      5       Hf  n[	        U4S jUR
                  R                   5       5      (       a  M3  UR                  U5        T[        UR
                  R                  5      -  mMh     U$ )a3  Return a list of maximal non-overlapping complexes.

Args:
    network (Network): The |Network| of interest.
    state (tuple[int]): The state of the network (a binary tuple).

Returns:
    list[SystemIrreducibilityAnalysis]: A list of |SIA| for non-overlapping
    complexes with maximal |big_phi| values.
c              3   ,   >#    U  H	  oT;   v   M     g 7fr&   r'   ).0ncovered_nodess     r   	<genexpr>condensed.<locals>.<genexpr>   s     H/G!%/Gs   )setreversedsortedrK   anyr,   r   r0   )r   r   rP   crW   s       @r   	condensedr_      sq     FEMfYw678Hq{{/G/GHHHMM!)C0H0H,IIM 9
 Mr   )r:   logging r   r   r   r   modelsr   r,   r	   parallelr   r   	getLoggerr6   rM   r   r   r!   r#   rC   rE   rK   rR   r_   r'   r   r   <module>re      sp   
  2 2  !   !
G$<.y $:&/ :2r   