qiskit/transpiler/passes/mapping/full_ancilla_allocation.py
def run(self, dag):
        """
        Extend the layout with new (physical qubit, virtual qubit) pairs.

        The dag signals which virtual qubits are already in the circuit.
        This pass will allocate new virtual qubits such that no collision occurs
        (i.e. Layout bijectivity is preserved)

        The coupling_map and layout together determine which physical qubits are free.

        Args:
            dag (DAGCircuit): circuit to analyze

        Returns:
            DAGCircuit: returns the same dag circuit, unmodified

        Raises:
            TranspilerError: If there is not layout in the property set or not set at init time.
        """
        self.layout = self.layout or self.property_set.get('layout')

        if self.layout is None:
            raise TranspilerError("FullAncilla pass requires property_set[\"layout\"] or"
                                  " \"layout\" parameter to run")

        layout_physical_qubits = self.layout.get_physical_bits().keys()
        coupling_physical_qubits = self.coupling_map.physical_qubits
        idle_physical_qubits = [q for q in coupling_physical_qubits
                                if q not in layout_physical_qubits]

        if idle_physical_qubits:
            if self.ancilla_name in dag.qregs:
                save_prefix = QuantumRegister.prefix
                QuantumRegister.prefix = self.ancilla_name
                qreg = QuantumRegister(len(idle_physical_qubits))
                QuantumRegister.prefix = save_prefix
            else:
                qreg = QuantumRegister(len(idle_physical_qubits), name=self.ancilla_name)

        for idx, idle_q in enumerate(idle_physical_qubits):
            self.property_set['layout'][idle_q] = qreg[idx]

        return dag
def run(self, dag):
        """
        Extend the layout with new (physical qubit, virtual qubit) pairs.

        The dag signals which virtual qubits are already in the circuit.
        This pass will allocate new virtual qubits such that no collision occurs
        (i.e. Layout bijectivity is preserved)

        The coupling_map and layout together determine which physical qubits are free.

        Args:
            dag (DAGCircuit): circuit to analyze

        Returns:
            DAGCircuit: returns the same dag circuit, unmodified

        Raises:
            TranspilerError: If there is not layout in the property set or not set at init time.
        """
        self.layout = self.layout or self.property_set.get('layout')

        if self.layout is None:
            raise TranspilerError("FullAncilla pass requires property_set[\"layout\"] or"
                                  " \"layout\" parameter to run")

        layout_physical_qubits = self.layout.get_physical_bits().keys()
        coupling_physical_qubits = self.coupling_map.physical_qubits
        idle_physical_qubits = [q for q in coupling_physical_qubits
                                if q not in layout_physical_qubits]

        if idle_physical_qubits:
            if self.ancilla_name in dag.qregs:
                save_prefix = QuantumRegister.prefix
                QuantumRegister.prefix = self.ancilla_name
                qreg = QuantumRegister(len(idle_physical_qubits))
                QuantumRegister.prefix = save_prefix
            else:
                qreg = QuantumRegister(len(idle_physical_qubits), name=self.ancilla_name)

        for idx, idle_q in enumerate(idle_physical_qubits):
            self.property_set['layout'][idle_q] = qreg[idx]

        return dag
Extend the layout with new (physical qubit, virtual qubit) pairs.

        The dag signals which virtual qubits are already in the circuit.
        This pass will allocate new virtual qubits such that no collision occurs
        (i.e. Layout bijectivity is preserved)

        The coupling_map and layout together determine which physical qubits are free.

        Args:
            dag (DAGCircuit): circuit to analyze

        Returns:
            DAGCircuit: returns the same dag circuit, unmodified

        Raises:
            TranspilerError: If there is not layout in the property set or not set at init time.