
    ph                         S r SSKrSSKJrJr  SSKJr  / SQrS r " S	 S
\R                  \R                  5      r
 " S S\R                  5      rS rSS jrg)zSubsystem-level objects.    N   )cmpfmt   )utils)phicespartitioned_ces	subsystemcut_subsystemc                 D    [        U R                  5      U R                  4$ N)len	mechanism)concepts    P/home/james-whalen/.local/lib/python3.13/site-packages/pyphi/models/subsystem.py_concept_sort_keyr      s    !!"G$5$566    c                       \ rS rSrSrSS jrS rS rS rS r	S	 r
\R                  S
 5       rS rS rS r\S 5       r\S 5       r\S 5       rSrg)CauseEffectStructure   zA collection of concepts.Nc                 T    [        [        U[        S95      U l        X l        X0l        g )N)key)tuplesortedr   conceptsr   time)selfr   r   r   s       r   __init__CauseEffectStructure.__init__   s     fX3DEF"	r   c                 ,    [        U R                  5      $ r   )r   r   r   s    r   __len__CauseEffectStructure.__len__   s    4==!!r   c                 ,    [        U R                  5      $ r   )iterr   r"   s    r   __iter__CauseEffectStructure.__iter__    s    DMM""r   c                      U R                   U   $ r   r   )r   is     r   __getitem__ CauseEffectStructure.__getitem__#   s    }}Qr   c                 4    [         R                  " U / SQ5      $ Nr   r   r   )r   	make_reprr"   s    r   __repr__CauseEffectStructure.__repr__&   s    }}T#DEEr   c                 .    [         R                  " U 5      $ r   )r   fmt_cesr"   s    r   __str__CauseEffectStructure.__str__)   s    {{4  r   c                 4    U R                   UR                   :H  $ r   r*   r   others     r   __eq__CauseEffectStructure.__eq__,   s    }}..r   c                 D    [        U R                  U R                  45      $ r   )hashr   r   r"   s    r   __hash__CauseEffectStructure.__hash__0   s    T]]DNN344r   c                     U R                   /$ r   r*   r"   s    r   order_byCauseEffectStructure.order_by3   s    r   c                 J    U R                   U R                  U R                  S.$ r/   r0   r"   s    r   to_jsonCauseEffectStructure.to_json6   s      MM		# 	#r   c                 D    U  Vs/ s H  oR                   PM     sn$ s  snf )zThe mechanism of each concept.)r   r   r   s     r   
mechanismsCauseEffectStructure.mechanisms:   s      266g!!666   c                 D    U  Vs/ s H  oR                   PM     sn$ s  snf )z'The |small_phi| values of each concept.)r   rH   s     r   phisCauseEffectStructure.phis?   s     ,0044000rK   c                    ^ U R                   R                  R                  m[        U4S jU R                   5       5      $ )z&The labeled mechanism of each concept.c              3   F   >#    U  H  n[        T" U5      5      v   M     g 7fr   )list).0r   labels     r   	<genexpr>:CauseEffectStructure.labeled_mechanisms.<locals>.<genexpr>H   s     M_	T%	*++_s   !)r   node_labelsindices2labelsr   rI   )r   rS   s    @r   labeled_mechanisms'CauseEffectStructure.labeled_mechanismsD   s/     **99MT__MMMr   r0   ) NN)__name__
__module____qualname____firstlineno____doc__r   r#   r'   r,   r2   r6   r   sametyper;   r?   rB   rE   propertyrI   rM   rX   __static_attributes__rZ   r   r   r   r      s    #"# F! 	\\/ /5# 7 7 1 1 N Nr   r   c                       \ rS rSrSr  SS jrS rSS jrSS jr\	S 5       r
\	S	 5       r\	S
 5       rS/rS rS rS rS rS r\S 5       rSrg)SystemIrreducibilityAnalysisK   a4  An analysis of system irreducibility (|big_phi|).

Contains the |big_phi| value of the |Subsystem|, the cause-effect
structure, and all the intermediate results obtained in the course of
computing them.

These can be compared with the built-in Python comparison operators (``<``,
``>``, etc.). First, |big_phi| values are compared. Then, if these are
equal up to |PRECISION|, the one with the larger subsystem is greater.

Attributes:
    phi (float): The |big_phi| value for the subsystem when taken against
        this analysis, *i.e.* the difference between the cause-effect
        structure and the partitioned cause-effect structure for this
        analysis.
    ces (CauseEffectStructure): The cause-effect structure of
        the whole subsystem.
    partitioned_ces (CauseEffectStructure): The cause-effect structure when
        the subsystem is cut.
    subsystem (Subsystem): The subsystem this analysis was calculated for.
    cut_subsystem (Subsystem): The subsystem with the minimal cut applied.
    time (float): The number of seconds it took to calculate.
Nc                 L    Xl         X l        X0l        X@l        XPl        X`l        g r   )r   r	   r
   r   r   r   )r   r   r	   r
   r   r   r   s          r   r   %SystemIrreducibilityAnalysis.__init__d   s"    ."*	r   c                 8    [         R                  " U [        5      $ r   )r   r1   _sia_attributesr"   s    r   r2   %SystemIrreducibilityAnalysis.__repr__m   s    }}T?33r   c                 *    [         R                  " XS9$ )Nr	   )r   fmt_siar   r	   s     r   r6   $SystemIrreducibilityAnalysis.__str__p   s    {{4))r   c                 4    [        U R                  US95        g)zWPrint this |SystemIrreducibilityAnalysis|, optionally without
cause-effect structures.
rl   N)printr6   rn   s     r   rq   "SystemIrreducibilityAnalysis.prints   s     	dllsl#$r   c                 .    U R                   R                  $ )z3The number of seconds it took to calculate the CES.)r	   r   r"   s    r   small_phi_time+SystemIrreducibilityAnalysis.small_phi_timey   s     xx}}r   c                 .    U R                   R                  $ )zIThe unidirectional cut that makes the least difference to the
subsystem.
)r   cutr"   s    r   rw    SystemIrreducibilityAnalysis.cut~   s    
 !!%%%r   c                 .    U R                   R                  $ )z%The network the subsystem belongs to.)r   networkr"   s    r   rz   $SystemIrreducibilityAnalysis.network   s     ~~%%%r   rz   c                 n    U R                   [        U R                  5      U R                  R                  /$ r   )r   r   r   node_indicesr"   s    r   rB   %SystemIrreducibilityAnalysis.order_by   s&    #dnn-t~~/J/JKKr   c                 8    [         R                  " X[        5      $ r   )r   
general_eqri   r9   s     r   r;   #SystemIrreducibilityAnalysis.__eq__   s    ~~d?;;r   c                 N    [         R                  " U R                  S5      (       + $ )zFA |SystemIrreducibilityAnalysis| is ``True`` if it has
|big_phi > 0|.
r   )r   eqr   r"   s    r   __bool__%SystemIrreducibilityAnalysis.__bool__   s     88DHHa(((r   c                     [        U R                  U R                  U R                  U R                  U R
                  45      $ r   )r>   r   r	   r
   r   r   r"   s    r   r?   %SystemIrreducibilityAnalysis.__hash__   s:    TXXXX))^^''	) * 	*r   c                 X    [         SS/-    Vs0 s H  nU[        X5      _M     sn$ s  snf )z*Return a JSON-serializable representation.r   rt   )ri   getattr)r   attrs     r   rE   $SystemIrreducibilityAnalysis.to_json   s>     (63C*DD
D '$%%D
 	
 
s   'c                     US	 U " S0 UD6$ )Nrt   rZ   rZ   )clsdcts     r   	from_json&SystemIrreducibilityAnalysis.from_json   s     !zSzr   )r	   r   r
   r   r   r   )NNNNNN)T)r[   r\   r]   r^   r_   r   r2   r6   rq   ra   rt   rw   rz   unorderable_unless_eqrB   r;   r   r?   rE   classmethodr   rb   rZ   r   r   rd   rd   K   s    0 <@:>4*%   & & & & 'KL<)*
  r   rd   c                 (    [        SU S9nSUl        U$ )zReturn an empty CES.rZ   )r           )r   r   )r   r	   s     r   	_null_cesr      s    
rY
7CCHJr   c           	      @    [        U U U[        U 5      [        U 5      S9$ )zReturn a |SystemIrreducibilityAnalysis| with zero |big_phi| and empty
cause-effect structures.

This is the analysis result for a reducible subsystem.
)r   r   r   r	   r
   )rd   r   )r   r   s     r   	_null_siar      s+     ()6?,/,5i,@8A)8L	N Nr   )r   )r_   collections r   r   r   ri   r   	OrderableSequencer   rd   r   r   rZ   r   r   <module>r      sX   
    $74N3==+*>*> 4Nn^3== ^B
Nr   