
    ph7                        S r SSKJr  SSKJr  SSKJrJrJrJ	r	  Sr
SrSrSrSrS	rS
rSrSrSrSrSrSrSrSrSrSr\S-  S-   \S-  -   S-   rSrSrS\S-  -   r\S-  S-   r\ " \!" S5      5      / SQ-   r"S r#S4S jr$S r%\S-   \-   r&S  r'S! r(S5S# jr)S6S$ jr*S% r+S6S& jr,S6S' jr-S( r.S6S) jr/S* r0S7S+ jr1S, r2S- r3S8S. jr4S/ r5S0 r6S6S1 jr7S2 r8S3 r9g")9zI
Helper functions for formatting pretty representations of PyPhi models.
    )Fraction)chain   )	Directionconfig	constantsutils   u   φu   Φu   αu   ┌u   ┐u   └u   ┘u   ─u   │u   ═u   ━u   ╍u   ╴z/ /u   ➤u   ∅u   ✕u   ◀u   ▶   )r       @      c                 "  ^  [         R                  [        [        4;   a  T R	                  5       $ [         R                  [
        L a?  SR                  T R                  R                  SR                  U 4S jU 5       5      5      $ [        S5      e)aZ  Construct a repr string.

If `config.REPR_VERBOSITY` is ``1`` or ``2``, this function calls the
object's __str__ method. Although this breaks the convention that __repr__
should return a string which can reconstruct the object, readable reprs are
invaluable since the Python interpreter calls `repr` to represent all
objects in the shell. Since PyPhi is often used in the interpreter we want
to have meaningful and useful representations.

Args:
    self (obj): The object in question
    attrs (Iterable[str]): Attributes to include in the repr

Returns:
    str: the ``repr``esentation of the object
z{}({}), c              3   Z   >#    U  H   nUS -   [        [        TU5      5      -   v   M"     g7f)=N)reprgetattr).0attrselfs     J/home/james-whalen/.local/lib/python3.13/site-packages/pyphi/models/fmt.py	<genexpr>make_repr.<locals>.<genexpr>I   s-      )"'$ Sj4d(;#<<"'s   (+z)Invalid value for `config.REPR_VERBOSITY`)r   REPR_VERBOSITYMEDIUMHIGH__str__LOWformat	__class____name__join
ValueError)r   attrss   ` r   	make_reprr&   /   sv    ( .||~			#	%NN##II )"') )* 	*
 @
AA    c                 l    [        U 5      n X-  nUSU-   R                  U R                  S5      5      -   $ )a  Indent a string.

Prepends whitespace to every line in the passed string. (Lines are
separated by newline characters.)

Args:
    lines (str): The string to indent.

Keyword Args:
    amount (int): The number of columns to indent by.
    char (str): The character to to use as the indentation.

Returns:
    str: The indented string.

Example:
    >>> print(indent('line1\nline2', char='*'))
    **line1
    **line2

)strr#   split)linesamountcharpaddings       r   indentr0   O   s7    * JEmGdWn**5;;t+<===r'   c                 f    [        U 5      R                  S5      nSR                  S U 5       5      $ )zzAdd a margin to both ends of each line in the string.

Example:
    >>> margin('line1\nline2')
    '  line1  \n  line2  '
r)   c              3   D   #    U  H  nS R                  U5      v   M     g7f)z  {}  N)r    r   ls     r   r   margin.<locals>.<genexpr>q   s     7AX__Q''s    )r*   r+   r#   )textr,   s     r   marginr7   i   s+     IOOD!E997777r'   z {line:<{width}} c                 :   U R                  S5      n[        S U 5       5      n[        [        SU-   -  -   [        -   n[
        [        SU-   -  -   [        -   nU Vs/ s H  n[        R                  XRS9PM     nnUS-   SR                  U5      -   S-   U-   $ s  snf )u   Wrap a chunk of text in a box.

Example:
    >>> print(box('line1\nline2'))
    ┌───────┐
    │ line1 │
    │ line2 │
    └───────┘
r)   c              3   8   #    U  H  n[        U5      v   M     g 7fNlenr3   s     r   r   box.<locals>.<genexpr>        &1A   r   )linewidth)
r+   maxTOP_LEFT_CORNERHORIZONTAL_BARTOP_RIGHT_CORNERBOTTOM_LEFT_CORNERBOTTOM_RIGHT_CORNERLINES_FORMAT_STRr    r#   )r6   r,   rA   top_bar
bottom_barr@   s         r   boxrK   w   s     JJtE&&&E1u9!== G$~U'CC%&J JOO$$$$<EOT>DIIe,,t3j@@ Ps   Bc                    [        U R                  S5      5      n[        UR                  S5      5      n[        [        U5      [        U5      -
  5      n[        U5      [        U5      :  a  S[        US   5      -  nX5/U-  -  nO1[        U5      [        U5      :  a  S[        US   5      -  nX%/U-  -  nSR	                  S [        X#5       5       5      S-   $ )zPut two boxes next to each other.

Assumes that all lines in the boxes are the same width.

Example:
    >>> left = 'A \nC '
    >>> right = 'B\nD'
    >>> print(side_by_side(left, right))
    A B
    C D
    <BLANKLINE>
r)    r   c              3   .   #    U  H  u  pX-   v   M     g 7fr:    )r   abs      r   r   side_by_side.<locals>.<genexpr>   s     D'CtqQU'Cs   )listr+   absr<   r#   zip)leftright
left_linesright_linesdifffills         r   side_by_sider\      s     djj&'Ju{{4()K s:[!112D
:[))SQ((v}$	[	C
O	+SA''ftm#
99Ds:'CDDtKKr'   Nc                    [        UR                  S5      5      n[        S U 5       5      nU(       a  U R                  U5      S-   n OU R	                  U5      S-   n U(       a
  XU-  -   S-   n U(       a
  X&-  S-   U -   n X-   $ )ziCenter a head over a block of text.

The width of the text is the width of the longest line of the text.
r)   c              3   8   #    U  H  n[        U5      v   M     g 7fr:   r;   r3   s     r   r   header.<locals>.<genexpr>   r>   r?   )rS   r+   rB   centerljust)headr6   	over_char
under_charr`   r,   rA   s          r   headerre      s    
 D!"E&&&E {{5!D(zz% 4' 5((4/  4'$.;r'   c                 \    Uc  [        [        [        U 5      5      $ UR                  U 5      $ )z0Get the labels for a tuple of mechanism indices.)tuplemapr*   indices2labelsindicesnode_labelss     r   labelsrm      s+    Sg&''%%g..r'   c                 
   SR                  U 5      n[        R                  (       d  U$ [        U 5      nUR	                  S5      n[        X#-
  5      [        R                  :  a  UR                  [        ;   a  [        U5      $ U$ )zpFormat a number.

It will be printed as a fraction if the denominator isn't too big and as a
decimal otherwise.
z{:n}r   )r    r   PRINT_FRACTIONSr   limit_denominatorrT   r   EPSILONdenominatorNICE_DENOMINATORSr*   )p	formattedfractionnices       r   
fmt_numberrx      sv     a I!!{H%%c*D(/*Y->->>&&*;; 	D	 r'   c                 B    SSR                  [        X5      5      -   S-   $ )zFormat a mechanism or purview.[r   ])r#   rm   rj   s     r   fmt_mechanismr|      s     6'7883>>r'   c                    ^ U4S jnU" U R                   5      nU" U R                  5      n[        S[        U5      [        U5      5      n[        U-  nSR                  X6XES9$ )uS   Format a |Part|.

The returned string looks like::

    0,1
    ───
     ∅
c                 T   > U (       a  SR                  [        U T5      5      $ [        $ )N,)r#   rm   	EMPTY_SET)xrl   s    r   nodesfmt_part.<locals>.nodes   s     34sxxq+./C)Cr'      z+{numer:^{width}}
{divider}
{denom:^{width}})numerdividerdenomrA   )	mechanismpurviewrB   r<   rD   r    )partrl   r   r   r   rA   r   s    `     r   fmt_partr      sb    D $..!E$,,E3u:s5z*Eu$G	 f5fD	Er'   c                 x   U (       d  gU  Vs/ s H'  n[        XR                  5      R                  S5      PM)     nnSSR                  [        5      S4nSnU/[        U5      S-
  -  U/-   n[        R                  " [        X%5      5      nSR                  [        R                  " [        U6 5      5      $ s  snf )u   Format a |Bipartition|.

The returned string looks like::

    0,1    ∅
    ─── ✕ ───
     2    0,1

Args:
    partition (Bipartition): The partition in question.

Returns:
    str: A human-readable string representation of the partition.
 r)   z   z {} )r)   r)   r   r
   )
r   rl   r+   r    MULTIPLYr<   r   from_iterablerU   r#   )	partitionr   partstimesbreaksbetweenelementss          r   fmt_partitionr      s      #$" d11288>" 
 $ ]]8$E FgUa(F83G ""3u#67H 775&&sH~677$s   .B7c                     U (       d  gUc  SnSR                  S U  5       5      S-   nSR                  U[        U 5      [        U 5      S:X  a  SOS5      n[        X[        [        5      $ )	z Format a |CauseEffectStructure|.z()
Cause-effect structurer)   c              3   8   #    U  H  n[        U5      v   M     g 7fr:   )r7   )r   r   s     r   r   fmt_ces.<locals>.<genexpr>&  s     .AqAr?   z{} ({} concept{})r
   r   s)r#   r    r<   re   HEADER_BAR_1)ctitleconceptss      r   fmt_cesr     sc    }(yy.A..5H&&s1vSVq[rc3E %<>>r'   c                 v   S n[        SU" U R                  5      5      n[        SU" U R                  5      5      n[        X#5      n[	        U R
                  U R                  5      nSR                  U[        [        U R                  5      5      n[        R                  [        L n[        Xd[        [        US9$ )zFormat a |Concept|.c           
      N    [        [        [        U R                  SSS9SS95      $ )NFT)verbosemipr
   )r-   )rK   r0   fmt_riaria)r   s    r   fmt_cause_or_effect(fmt_concept.<locals>.fmt_cause_or_effect0  s!    6'!%%DA!LMMr'   MICMIEz Concept: Mechanism = {}, {} = {}r`   )re   causeeffectr\   r|   r   rl   r    	SMALL_PHIrx   phir   r   r   HEADER_BAR_2)conceptr   r   r   cer   r   r`   s           r   fmt_conceptr   -  s    N 5-gmm<=EE.w~~>?F	e	$Bg//1D1DEI.559j57E ""d*F%\<GGr'   c                    U(       aK  SR                  [        U R                  U R                  5      5      nSR                  U R                  5      nOSnSn[
        R                  [        L a  SR                  U(       a  SOS[        [        U R                  5      5      5      nSR                  [        [        U R                  5      5      5      nSR                  [        [        U R                  5      5      5      nOSnSnSnS	R                  [        U[        U R                  U R                  5      U[!        U R"                  5      UUUS
9$ )z,Format a |RepertoireIrreducibilityAnalysis|.zMechanism: {}
z
Direction: {}r   z
{}:
{}MIP	Partitionz
Repertoire:
{}z
Partitioned repertoire:
{}zl{SMALL_PHI} = {phi}
{mechanism}Purview = {purview}{direction}{partition}{repertoire}{partitioned_repertoire})r   r   r   	directionr   r   
repertoirepartitioned_repertoire)r    r|   r   rl   r   r   r   r   r0   r   r   fmt_repertoirer   r   r   r   rx   r   )r   r   r   r   r   r   r   r   s           r   r   r   A  s    %,,#--9;	%,,S]];			$&&U{=/02	 )//>#..124
!@!G!G>#"<"<=>"@ 	
!#	# %+F!#++s?377#!#9 %+ %;;r'   c                     SR                  [        U R                  U R                  5      [        [        U R
                  U R                  5      S9$ )zFormat a |Cut|.z$Cut {from_nodes} {symbol} {to_nodes})
from_nodessymbolto_nodes)r    r|   r   rl   
CUT_SYMBOLr   cuts    r   fmt_cutr   k  sA    188 As||S__= 9 ? ?r'   c                 N    SR                  U R                  U R                  5      $ )zFormat a |KCut|.z
KCut {}
{})r    r   r   r   s    r   fmt_kcutr   s  s    s}}==r'   c                 v   U(       a;  SR                  [        U R                  S5      [        U R                  S5      S9nSnOSnSnSR                  [        [        U R                  5      S	9n[        [        U R                  5      X#S
9n[        [        U R                  5      X#S
9n[        [        XBUS
95      $ )z(Format a |SystemIrreducibilityAnalysis|.z{ces}{partitioned_ces}r   z"Partitioned cause-effect structure)cespartitioned_cesTr   Fz1System irreducibility analysis: {BIG_PHI} = {phi})BIG_PHIr   r   )r    r   r   r   r   rx   r   re   r*   	subsystemr   rK   )siar   bodycenter_headerr   s        r   fmt_siar   x  s    
  &GG,. !(''8!:	 !' !; 	 ?FFZ0 G 2E #cmm$dAD#cgg,;Dve-899r'   c                    U c  gU R                  5       n / nSnSR                  SU R                  US9nUR                  U5        [        R
                  " U R                  5       HG  nSR                  S U 5       5      nUR                  SR                  XR[        X   5      5      5        MI     [        S U 5       5      nUR                  S	[        US	-   -  5        [        S
R                  U5      5      $ )zFormat a repertoire.r   z    z{S:^{s_width}}{space}Pr({S})S)r   s_widthspacec              3   8   #    U  H  n[        U5      v   M     g 7fr:   )r*   )r   is     r   r   !fmt_repertoire.<locals>.<genexpr>  s     2EqCFFEr?   z	{0}{1}{2}c              3   8   #    U  H  n[        U5      v   M     g 7fr:   r;   )r   r@   s     r   r   r     s     ,edD		er?   r
   r)   )squeezer    ndimappendr	   
all_statesr#   rx   rB   insertDOTTED_HEADERrK   )rr,   r   rb   state	state_strrA   s          r   r   r     s     	y			AE E)00
qvvU 1 ,D	LL !!!&&)GG2E22	[''	(218(<> 	? *
 ,e,,E	LLMUQY/0tyy  r'   c           	         [         R                  [        U R                  U R                  5      [
        [        U R                  U R                  5      4[         R                  [        U R                  U R                  5      [        [        U R                  U R                  5      40U R                     nSR                  U5      nSR                  [        [        U R                  S5      US9$ )z-Format an AcRepertoireIrreducibilityAnalysis.rM   z{ALPHA} = {alpha}  {causality}   )ALPHAalpha	causality)r   CAUSEr|   r   rl   
ARROW_LEFTr   EFFECTARROW_RIGHTr   r#   r    r   roundr   )r   r   s     r   
fmt_ac_riar     s     	-S__E$'sGI 	=H&(cooFH	 
mmI #I+22CIIq! 3  r'   c                 T   Uc  U R                   R                  nSR                  U[        U 5      [        U 5      S:X  a  SOS5      nSnUS-  nUSR	                  S U R
                   5       5      -  nUS-  nUSR	                  S	 U R                   5       5      -  nS[        XS
S9-   $ )z'Format an Account or a DirectedAccount.z{} ({} causal link{})r
   r   r   zIrreducible effects
r)   c              3   8   #    U  H  n[        U5      v   M     g 7fr:   r   r   ms     r   r   fmt_account.<locals>.<genexpr>  s     I-Hjmm-Hr?   z
Irreducible causes
c              3   8   #    U  H  n[        U5      v   M     g 7fr:   r   r   s     r   r   r     s     H-Gjmm-Gr?   *rd   )r!   r"   r    r<   r#   irreducible_effectsirreducible_causesre   )accountr   r   s      r   fmt_accountr     s    }!!**#**s7|3w<1#4R#?E D##DDIIIW-H-HIIID$$DDIIHW-G-GHHHD&555r'   c           
          SR                  [        [        U R                  S5      U [	        U R
                  S5      [	        U R                  S5      S9n[        [        SU[        S95      $ )z(Format a AcSystemIrreducibilityAnalysis.z{ALPHA} = {alpha}
direction: {ac_sia.direction}
transition: {ac_sia.transition}
before state: {ac_sia.before_state}
after state: {ac_sia.after_state}
cut:
{ac_sia.cut}
{account}
{partitioned_account}r   AccountzPartitioned Account)r   r   ac_siar   partitioned_accountAcSystemIrreducibilityAnalysisr   )
r    r   r   r   r   r   r   rK   re   rD   )r   r   s     r   
fmt_ac_siar     sw    	  !'a(	+ +**,A!C !' !D 	" v6!/1 2 2r'   c                     SR                  [        U R                  U R                  5      [        [        U R
                  U R                  5      5      $ )zFormat a |Transition|.zTransition({} {} {}))r    r|   cause_indicesrl   r   effect_indices)ts    r   fmt_transitionr    s>    !((aooq}}5a&&68 8r'   )r   rM   )NNTr:   )TF)T):__doc__	fractionsr   	itertoolsr   r   r   r   r   r	   r   r   r   r   r   r   rC   rE   rF   rG   rD   VERTICAL_SIDEr   r   HEADER_BAR_3r   LINEr   r   r   r   r   rS   rangers   r&   r0   r7   rH   rK   r\   re   rm   rx   r|   r   r   r   r   r   r   r   r   r   r   r   r   r  rO   r'   r   <module>r	     sS  
   2 2
 
	
	
 	   Qh&1H<
	)
Qh)59o(99 
B@>48 !#66F A.L82/(?
E28D?H(';T?>
:2!8$6"208r'   