
    z	i-                         S r SSKrSSKJr  SSKJr  SSKJr  SSKJ	r
  SSKJr  \
R                  R                   " S S	\5      5       rg)
a  A pass for choosing a Layout of a circuit onto a Coupling graph, as a
Constraint Satisfaction Problem. It tries to find a solution that fully
satisfy the circuit, i.e. no further swap is needed. If no solution is
found, no ``property_set['layout']`` is set.
    N)Layout)AnalysisPass)TranspilerError)	optionals)Targetc                   >   ^  \ rS rSrSr    SU 4S jjrS rSrU =r$ )	CSPLayout   z;If possible, chooses a Layout as a CSP, using backtracking.c                    > [         TU ]  5         [        U[        5      (       a&  Xl        U R                  R                  5       U l        OSU l        Xl        X l        X@l        XPl	        X0l
        g)a[  If possible, chooses a Layout as a CSP, using backtracking.

If not possible, does not set the layout property. In all the cases,
the property `CSPLayout_stop_reason` will be added with one of the
following values:

* solution found: If a perfect layout was found.
* nonexistent solution: If no perfect layout was found and every combination was checked.
* call limit reached: If no perfect layout was found and the call limit was reached.
* time limit reached: If no perfect layout was found and the time limit was reached.

Args:
    coupling_map (Union[CouplingMap, Target]): Directed graph representing a coupling map.
    strict_direction (bool): If True, considers the direction of the coupling map.
                             Default is False.
    seed (int): Sets the seed of the PRNG.
    call_limit (int): Amount of times that
        ``constraint.RecursiveBacktrackingSolver.recursiveBacktracking`` will be called.
        None means no call limit. Default: 1000.
    time_limit (int): Amount of seconds that the pass will try to find a solution.
        None means no time limit. Default: 10 seconds.
N)super__init__
isinstancer   targetbuild_coupling_mapcoupling_mapstrict_direction
call_limit
time_limitseed)selfr   r   r   r   r   	__class__s         d/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/transpiler/passes/layout/csp_layout.pyr   CSPLayout.__init__   sY    < 	lF++&K $ > > @DDK , 0$$	    c           	        ^ U R                   R                  5       (       d  [        S5      eUR                  n[	        5       nSSKJnJnJn  SSK	J
n  UR                  5        HN  nUR                  UR                  UR                  S   5      UR                  UR                  S   5      45        MP     [	        U R                   R                  5       5      mU R                   c  U R"                  c  U" 5       n	OU" U R"                  U R                   S9n	[%        ['        [)        U5      5      5      n
[%        U R                   R*                  5      n[,        R.                  " U R0                  5      R3                  U5        U" U	5      nUR5                  X5        UR7                  U" 5       5        U R8                  (       a  U4S jnOU4S	 jnU H  nUR7                  XS   US   /5        M     UR;                  5       nUcf  S
n[=        X5      (       aS  U	R>                  b  U	R>                  U R                   :  a  SnOU	R@                  b  U	R@                  U R"                  :  a  SnOSn[C        URE                  5        VVs0 s H  u  nnUUU   _M     snn5      U RF                  S'   URH                  RK                  5        H!  nU RF                  S   RM                  U5        M#     UU RF                  S'   gs  snnf )zrun the layout methodzSCoupling Map is disjoint, this pass can't be used with a disconnected coupling map.r   )ProblemAllDifferentConstraintRecursiveBacktrackingSolver)CustomSolver   N)r   r   c                    > X4T;   $ N controlr   edgess     r   
constraint!CSPLayout.run.<locals>.constraintj   s    (E11r   c                 *   > X4T;   =(       d    X4T;   $ r"   r#   r$   s     r   r'   r(   o   s    (E1Of5F%5OOr   znonexistent solutionztime limit reachedzcall limit reachedzsolution foundlayoutCSPLayout_stop_reason)'r   is_connectedr   qubitssetr'   r   r   r   2qiskit.transpiler.passes.layout._csp_custom_solverr   two_qubit_opsaddindexqargs	get_edgesr   r   listrangelenphysical_qubitsrandomRandomr   shuffleaddVariablesaddConstraintr   getSolutionr   time_currentcall_currentr   itemsproperty_setqregsvaluesadd_register)r   dagr-   cxsr   r   r   r   gatesolver	variablesvariable_domainsproblemr'   pairsolutionstop_reasonkvregr&   s                       @r   runCSPLayout.runJ   ss     --//!  e[[S%%'DGGV\\$**Q-0&,,tzz!}2MNO (D%%//12??"t'>02F!T__YFs6{+,	 1 1 A ABdii (()9:&/Y9467  2
P D!!*AwQ.@A  &&(0K&//&&2v7J7Jdoo7]"6K((49L9LPTP_P_9_"6K*K*08>>K[1\K[41a!VAY,K[1\*]Dh'yy'')!!(+88= * 6A12	 2]s   K8
)r   r   r   r   r   r   )FNi  
   )	__name__
__module____qualname____firstlineno____doc__r   rS   __static_attributes____classcell__)r   s   @r   r	   r	      s&    E
 )V:A :Ar   r	   )rZ   r9   qiskit.transpiler.layoutr   qiskit.transpiler.basepassesr   qiskit.transpiler.exceptionsr   qiskit.utilsr   
_optionalsqiskit.transpiler.targetr   HAS_CONSTRAINTrequire_in_instancer	   r#   r   r   <module>re      sK   
  + 5 8 0 + ..hA hA /hAr   