
    z	i%                     b    S r SSKrSSKJr  SSKJr  \R                  " \5      r " S S\5      r	g)zETranslates gates to a target basis using a given equivalence library.    N)TransformationPass)base_runc                   6   ^  \ rS rSrSrSU 4S jjrS rSrU =r$ )BasisTranslator   a]  Translates gates to a target basis by searching for a set of translations
from a given EquivalenceLibrary.

This pass operates in several steps:

* Determine the source basis from the input circuit.
* Perform a Dijkstra search over basis sets, starting from the device's
  target_basis new gates are being generated using the rules from the provided
  EquivalenceLibrary and the search stops if all gates in the source basis have
  been generated.
* The found path, as a set of rules from the EquivalenceLibrary, is composed
  into a set of gate replacement rules.
* The composed replacement rules are applied in-place to each op node which
  is not already in the target_basis.

If the target keyword argument is specified and that
:class:`~qiskit.transpiler.Target` objects contains operations
which are non-global (i.e. they are defined only for a subset of qubits),
as calculated by :meth:`~qiskit.transpiler.Target.get_non_global_operation_names`,
this pass will attempt to match the output translation to those constraints.
For 1 qubit operations this is straightforward, the pass will perform a
search using the union of the set of global operations with the set of operations
defined solely on that qubit. For multi-qubit gates this is a bit more involved,
while the behavior is initially similar to the single qubit case, just using all
the qubits the operation is run on (where order is not significant) isn't sufficient.
We also need to consider any potential local qubits defined on subsets of the
quantum arguments for the multi-qubit operation. This means the target used for the
search of a non-global multi-qubit gate is the union of global operations, non-global
multi-qubit gates sharing the same qubits, and any non-global gates defined on
any subset of the qubits used.


.. note::

    In the case of non-global operations it is possible for a single
    execution of this pass to output an incomplete translation if any
    non-global gates are defined on qubits that are a subset of a larger
    multi-qubit gate. For example, if you have a ``u`` gate only defined on
    qubit 0 and an ``x`` gate only on qubit 1 it is possible when
    translating a 2 qubit operation on qubit 0 and 1 that the output might
    have ``u`` on qubit 1 and ``x`` on qubit 0. Typically running this pass
    a second time will correct these issues.

.. _translation_errors:

Translation Errors
------------------

This pass will error if there is no path to translate an input gate to
the specified basis. However, during a typical/default preset passmanager
this pass gets run multiple times at different stages of the compilation
pipeline. This means that potentially the input gates that are getting
translated were not in the input circuit to :func:`~.transpile` as they
were generated by an intermediate transform in the circuit.

When this error occurs it typically means that either the target basis
is not universal or there are additional equivalence rules needed in the
:class:`~.EquivalenceLibrary` instance being used by the
:class:`~.BasisTranslator` pass. You can refer to
:ref:`custom_basis_gates` for details on adding custom equivalence rules.
c                    > [         TU ]  5         Xl        X l        Ub  [	        UR
                  5      S:  a  UOSU l        X@l        g)a  Initialize a BasisTranslator instance.

Args:
    equivalence_library (EquivalenceLibrary): The equivalence library
        which will be used by the BasisTranslator pass. (Instructions in
        this library will not be unrolled by this pass.)
    target_basis (list[str]): Target basis names to unroll to, e.g. ``['u3', 'cx']``.
    target (Target): The backend compilation target
    min_qubits (int): The minimum number of qubits for operations in the input
        dag to translate.
Nr   )super__init__
_equiv_lib_target_basislenoperation_names_target_min_qubits)selfequivalence_librarytarget_basistarget
min_qubits	__class__s        i/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/transpiler/passes/basis/basis_translator.pyr
   BasisTranslator.__init__W   sE     	-) "(!3F<R<R8SVW8Wv]a%    c           	          [        UU R                  U R                  U R                  U R                  c  SO[        U R                  5      5      nUc  U$ U$ )zTranslate an input DAGCircuit to the target basis.

Args:
    dag (DAGCircuit): input dag

Raises:
    TranspilerError: if the target basis cannot be reached

Returns:
    DAGCircuit: translated circuit.
N)r   r   r   r   r   set)r   dagouts      r   runBasisTranslator.runk   sT     OOLL&&.DC8J8J4K
 ks*s*r   )r   r   r   r   )Nr   )	__name__
__module____qualname____firstlineno____doc__r
   r   __static_attributes____classcell__)r   s   @r   r   r      s    <|&(+ +r   r   )
r$   loggingqiskit.transpiler.basepassesr   #qiskit._accelerate.basis_translatorr   	getLoggerr    loggerr    r   r   <module>r-      s3    L  ; 8			8	$i+( i+r   