Repository: Qiskit/qiskit

Issue:
Large number of depreciation warnings
<!-- ⚠️ If you do not respect this template, your issue will be closed -->
<!-- ⚠️ Make sure to browse the opened and closed issues -->

### Information

- **Qiskit Terra version**: master
- **Python version**:
- **Operating system**:

### What is the current behavior?
Simply calling `transpiled_circ = transpile(qc, backend)` gives me:

```python
/opt/miniconda3/lib/python3.7/site-packages/qiskit_terra-0.14.0-py3.7-macosx-10.9-x86_64.egg/qiskit/transpiler/passes/routing/stochastic_swap.py:272: DeprecationWarning:

edge_map arg as a dictionary is deprecated. Use qubits and clbits args to specify a list of self edges to compose onto.

/opt/miniconda3/lib/python3.7/site-packages/qiskit_terra-0.14.0-py3.7-macosx-10.9-x86_64.egg/qiskit/transpiler/passes/routing/stochastic_swap.py:383: DeprecationWarning:

edge_map arg as a dictionary is deprecated. Use qubits and clbits args to specify a list of self edges to compose onto.

/opt/miniconda3/lib/python3.7/site-packages/qiskit_terra-0.14.0-py3.7-macosx-10.9-x86_64.egg/qiskit/transpiler/passes/routing/stochastic_swap.py:272: DeprecationWarning:

edge_map arg as a dictionary is deprecated. Use qubits and clbits args to specify a list of self edges to compose onto.

/opt/miniconda3/lib/python3.7/site-packages/qiskit_terra-0.14.0-py3.7-macosx-10.9-x86_64.egg/qiskit/transpiler/passes/routing/stochastic_swap.py:383: DeprecationWarning:

edge_map arg as a dictionary is deprecated. Use qubits and clbits args to specify a list of self edges to compose onto.

/opt/miniconda3/lib/python3.7/site-packages/qiskit_terra-0.14.0-py3.7-macosx-10.9-x86_64.egg/qiskit/transpiler/passes/routing/stochastic_swap.py:272: DeprecationWarning:

edge_map arg as a dictionary is deprecated. Use qubits and clbits args to specify a list of self edges to compose onto.

/opt/miniconda3/lib/python3.7/site-packages/qiskit_terra-0.14.0-py3.7-macosx-10.9-x86_64.egg/qiskit/transpiler/passes/routing/stochastic_swap.py:383: DeprecationWarning:

edge_map arg as a dictionary is deprecated. Use qubits and clbits args to specify a list of self edges to compose onto.

/opt/miniconda3/lib/python3.7/site-packages/qiskit_terra-0.14.0-py3.7-macosx-10.9-x86_64.egg/qiskit/transpiler/passes/routing/stochastic_swap.py:272: DeprecationWarning:

edge_map arg as a dictionary is deprecated. Use qubits and clbits args to specify a list of self edges to compose onto.

/opt/miniconda3/lib/python3.7/site-packages/qiskit_terra-0.14.0-py3.7-macosx-10.9-x86_64.egg/qiskit/transpiler/passes/routing/stochastic_swap.py:383: DeprecationWarning:

edge_map arg as a dictionary is deprecated. Use qubits and clbits args to specify a list of self edges to compose onto.

/opt/miniconda3/lib/python3.7/site-packages/qiskit_terra-0.14.0-py3.7-macosx-10.9-x86_64.egg/qiskit/transpiler/passes/routing/stochastic_swap.py:272: DeprecationWarning:

edge_map arg as a dictionary is deprecated. Use qubits and clbits args to specify a list of self edges to compose onto.

/opt/miniconda3/lib/python3.7/site-packages/qiskit_terra-0.14.0-py3.7-macosx-10.9-x86_64.egg/qiskit/transpiler/passes/routing/stochastic_swap.py:383: DeprecationWarning:

edge_map arg as a dictionary is deprecated. Use qubits and clbits args to specify a list of self edges to compose onto.

/opt/miniconda3/lib/python3.7/site-packages/qiskit_terra-0.14.0-py3.7-macosx-10.9-x86_64.egg/qiskit/transpiler/passes/routing/stochastic_swap.py:272: DeprecationWarning:

edge_map arg as a dictionary is deprecated. Use qubits and clbits args to specify a list of self edges to compose onto.

/opt/miniconda3/lib/python3.7/site-packages/qiskit_terra-0.14.0-py3.7-macosx-10.9-x86_64.egg/qiskit/transpiler/passes/routing/stochastic_swap.py:383: DeprecationWarning:

edge_map arg as a dictionary is deprecated. Use qubits and clbits args to specify a list of self edges to compose onto.


### Steps to reproduce the problem



### What is the expected behavior?



### Suggested solutions





Discussion:
Yeah, I've noticed this now too we should fix this prior to the 0.14.0 release. Either remove the deprecation or update the usage in terra to not use the deprecated input for `compose()` in any of the passes

Resolving patch:
diff --git a/qiskit/transpiler/layout.py b/qiskit/transpiler/layout.py
--- a/qiskit/transpiler/layout.py
+++ b/qiskit/transpiler/layout.py
@@ -19,6 +19,8 @@
 Virtual (qu)bits are tuples, e.g. `(QuantumRegister(3, 'qr'), 2)` or simply `qr[2]`.
 Physical (qu)bits are integers.
 """
+import warnings
+
 from qiskit.circuit.quantumregister import Qubit
 from qiskit.transpiler.exceptions import LayoutError
 from qiskit.converters import isinstanceint
@@ -219,8 +221,13 @@ def combine_into_edge_map(self, another_layout):
         Returns:
             dict: A "edge map".
         Raises:
-            LayoutError: another_layout can be bigger than self, but not smaller. Otherwise, raises.
+            LayoutError: another_layout can be bigger than self, but not smaller.
+                Otherwise, raises.
         """
+        warnings.warn('combine_into_edge_map is deprecated as of 0.14.0 and '
+                      'will be removed in a future release. Instead '
+                      'reorder_bits() should be used', DeprecationWarning,
+                      stacklevel=2)
         edge_map = dict()
 
         for virtual, physical in self.get_virtual_bits().items():
@@ -231,6 +238,26 @@ def combine_into_edge_map(self, another_layout):
 
         return edge_map
 
+    def reorder_bits(self, bits):
+        """Given an ordered list of bits, reorder them according to this layout.
+
+        The list of bits must exactly match the virtual bits in this layout.
+
+        Args:
+            bits (list[Bit]): the bits to reorder.
+
+        Returns:
+            List: ordered bits.
+        """
+        order = [0] * len(bits)
+
+        # the i-th bit is now sitting in position j
+        for i, v in enumerate(bits):
+            j = self[v]
+            order[i] = j
+
+        return order
+
     @staticmethod
     def generate_trivial_layout(*regs):
         """Creates a trivial ("one-to-one") Layout with the registers in `regs`.
diff --git a/qiskit/transpiler/passes/routing/basic_swap.py b/qiskit/transpiler/passes/routing/basic_swap.py
--- a/qiskit/transpiler/passes/routing/basic_swap.py
+++ b/qiskit/transpiler/passes/routing/basic_swap.py
@@ -92,14 +92,14 @@ def run(self, dag):
                                                         cargs=[])
 
                     # layer insertion
-                    edge_map = current_layout.combine_into_edge_map(trivial_layout)
-                    new_dag.compose(swap_layer, edge_map)
+                    order = current_layout.reorder_bits(new_dag.qubits())
+                    new_dag.compose(swap_layer, qubits=order)
 
                     # update current_layout
                     for swap in range(len(path) - 2):
                         current_layout.swap(path[swap], path[swap + 1])
 
-            edge_map = current_layout.combine_into_edge_map(trivial_layout)
-            new_dag.compose(subdag, edge_map)
+            order = current_layout.reorder_bits(new_dag.qubits())
+            new_dag.compose(subdag, qubits=order)
 
         return new_dag
diff --git a/qiskit/transpiler/passes/routing/stochastic_swap.py b/qiskit/transpiler/passes/routing/stochastic_swap.py
--- a/qiskit/transpiler/passes/routing/stochastic_swap.py
+++ b/qiskit/transpiler/passes/routing/stochastic_swap.py
@@ -260,16 +260,13 @@ def _layer_update(self, i, best_layout, best_depth,
             dagcircuit_output.compose(best_circuit)
         else:
             logger.debug("layer_update: there are no swaps in this layer")
-        # Make qubit edge map and extend by classical bits
-        edge_map = layout.combine_into_edge_map(self.trivial_layout)
-        for bit in dagcircuit_output.clbits():
-            edge_map[bit] = bit
         # Output this layer
         layer_circuit = layer_list[i]["graph"]
         for creg in layer_circuit.cregs.values():
             dagcircuit_output.add_creg(creg)
 
-        dagcircuit_output.compose(layer_circuit, edge_map)
+        order = layout.reorder_bits(dagcircuit_output.qubits())
+        dagcircuit_output.compose(layer_circuit, qubits=order)
 
         return dagcircuit_output
 
@@ -311,14 +308,6 @@ def _mapper(self, circuit_graph, coupling_graph, trials=20):
         for creg in circuit_graph.cregs.values():
             dagcircuit_output.add_creg(creg)
 
-        # Make a trivial wire mapping between the subcircuits
-        # returned by _layer_update and the circuit we build
-        identity_wire_map = {}
-        for qubit in circuit_graph.qubits():
-            identity_wire_map[qubit] = qubit
-        for bit in circuit_graph.clbits():
-            identity_wire_map[bit] = bit
-
         logger.debug("trivial_layout = %s", layout)
 
         # Iterate over layers
@@ -366,8 +355,7 @@ def _mapper(self, circuit_graph, coupling_graph, trials=20):
                                            best_layout,
                                            best_depth,
                                            best_circuit,
-                                           serial_layerlist),
-                        identity_wire_map)
+                                           serial_layerlist))
 
             else:
                 # Update the record of qubit positions for each iteration
@@ -379,15 +367,12 @@ def _mapper(self, circuit_graph, coupling_graph, trials=20):
                                        best_layout,
                                        best_depth,
                                        best_circuit,
-                                       layerlist),
-                    identity_wire_map)
+                                       layerlist))
 
         # This is the final edgemap. We might use it to correctly replace
         # any measurements that needed to be removed earlier.
         logger.debug("mapper: self.trivial_layout = %s", self.trivial_layout)
         logger.debug("mapper: layout = %s", layout)
-        last_edgemap = layout.combine_into_edge_map(self.trivial_layout)
-        logger.debug("mapper: last_edgemap = %s", last_edgemap)
 
         return dagcircuit_output
 


Test patch: