
    z	i                     H    S r SSKJr  SSKJr  SSKJr  SSKJr  S r	S	S jr
g)
z2Helper function for converting a circuit to a gate    )AnnotatedOperation)Gate)QuantumRegister)QiskitErrorc                     [        U [        5      (       a  g[        U [        5      (       a  [        U R                  5      $ g)z+Checks whether op can be converted to Gate.TF)
isinstancer   r   _check_is_gatebase_op)ops    [/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/converters/circuit_to_gate.pyr	   r	      s2    "d	B*	+	+bjj))    Nc           	      l  ^ SSK Jn  U R                  (       a  [        S5      eU R                  (       a  [        S5      eU R
                   H@  n[        UR                  5      (       a  M  [        SUR                  R                   S35      e   Uc  U R                   Vs0 s H  ofU_M     nnOU R                  U5      nUR                  5       U R                  :w  a  [        SU R                   S	U 35      e[        U R                  U R                  / UR                  5       QUS
9nSUl        U R!                  USS9n	Ub  UR#                  X5        U" UR                  U	R$                  S9n
UR                  S:  a'  ['        UR                  S5      nU
R)                  U5        [+        U R,                  5       VVs0 s H  u  pUWU   _M     snnmU	R
                   H>  nU
R/                  UR1                  [3        U4S jUR,                   5       5      S95        M@     Xl        U$ s  snf s  snnf )a  Build a :class:`.Gate` object from a :class:`.QuantumCircuit`.

The gate is anonymous (not tied to a named quantum register),
and so can be inserted into another circuit. The gate will
have the same string name as the circuit.

Args:
    circuit (QuantumCircuit): the input circuit.
    parameter_map (dict): For parameterized circuits, a mapping from
       parameters in the circuit to parameters to be used in the gate.
       If None, existing circuit parameters will also parameterize the
       Gate.
    equivalence_library (EquivalenceLibrary): Optional equivalence library
       where the converted gate will be registered.
    label (str): Optional gate label.

Raises:
    QiskitError: if circuit is non-unitary or if
        parameter_map is not compatible with circuit

Return:
    Gate: a Gate equivalent to the action of the
    input circuit. Upon decomposition, this gate will
    yield the components comprising the original circuit.
r   )QuantumCircuitz8Circuit with classical bits cannot be converted to gate.zGcircuits with realtime classical variables cannot be converted to gatesz9One or more instructions cannot be converted to a gate. "z" is not a gate instructionNzEparameter_map should map all circuit parameters. Circuit parameters: z, parameter_map: )name
num_qubitsparamslabelF)inplace)r   global_phaseqc              3   .   >#    U  H
  nTU   v   M     g 7f)N ).0y	qubit_maps     r   	<genexpr>"circuit_to_gate.<locals>.<genexpr>i   s     3]J\QIaLJ\s   )qubits)qiskit.circuit.quantumcircuitr   clbitsr   num_varsdatar	   	operationr   
parameters_unroll_param_dictkeysr   r   values	conditionassign_parametersadd_equivalencer   r   add_register	enumerater   _appendreplacetuple
definition)circuitparameter_mapequivalence_libraryr   r   instructionpparameter_dictgatetargetqcr   idxbitr   s                 @r   circuit_to_gater<      s   6 =~~TUUcdd||k3344(227788SU  $ (/(:(:;(:1Q$(:; 33MB 2 22##*#5#5"66GGWY
 	

 \\%%)&&()	D DN&&~u&EF&++D9	TYYV5H5H	IBDOOS1
-6w~~-FG-Faf-FGI
 {{


;&&e3]+J\J\3].]&^_ #OKG <6 Hs   !H+?H0)NNN)__doc__"qiskit.circuit.annotated_operationr   qiskit.circuit.gater   qiskit.circuitr   qiskit.exceptionsr   r	   r<   r   r   r   <module>rB      s!    9 A $ * )Mr   