Repository: Qiskit/qiskit

Issue:
Cannot map a single qubit to a given device qubit that is not zero
<!-- ⚠️ 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?
It is not possible to map a single qubit circuit to a device qubit that is not zero.

```python

qr = QuantumRegister(1, 'qr')
qc = QuantumCircuit(qr)
qc.h(qr[0])

layout = Layout({(qr,0): 19})
backend = IBMQ.get_backend('ibmq_16_melbourne')
new_circ = transpile(qc, backend, initial_layout=layout)
new_circ.draw()
```

<img width="235" alt="Screen Shot 2019-03-28 at 11 18 08 AM" src="https://user-images.githubusercontent.com/1249193/55169462-34199680-514b-11e9-8760-64f5e32ed0af.png">

Note also that the layout used is not valid for the device, but no error is thrown.  I think all of this is due to this:

https://github.com/Qiskit/qiskit-terra/blob/ef46e442e4320500c847da617aadd5476bca4b70/qiskit/transpiler/transpiler.py#L190

that sets the coupling map to `None`, and therefore the transpiler skips the swap mapper that currently implements the mapping to device qubits.  Increasing the quantum register size to two or more gives a circuit with correct mapping, and which is the width of the device.




### Steps to reproduce the problem



### What is the expected behavior?



### Suggested solutions





Discussion:

Resolving patch:
diff --git a/qiskit/transpiler/transpiler.py b/qiskit/transpiler/transpiler.py
--- a/qiskit/transpiler/transpiler.py
+++ b/qiskit/transpiler/transpiler.py
@@ -179,12 +179,6 @@ def transpile_dag(dag, basis_gates=None, coupling_map=None,
     # TODO: `basis_gates` will be removed after we have the unroller pass.
     # TODO: `coupling_map`, `initial_layout`, `seed_mapper` removed after mapper pass.
 
-    # TODO: move this to the mapper pass
-
-    num_qubits = sum([qreg.size for qreg in dag.qregs.values()])
-    if num_qubits == 1:
-        coupling_map = None
-
     if basis_gates is None:
         basis_gates = ['u1', 'u2', 'u3', 'cx', 'id']
     if isinstance(basis_gates, str):


Test patch:
diff --git a/test/python/compiler/test_compiler.py b/test/python/compiler/test_compiler.py
--- a/test/python/compiler/test_compiler.py
+++ b/test/python/compiler/test_compiler.py
@@ -165,6 +165,25 @@ def test_parallel_compile(self):
         qobj = compile(qlist, backend=backend)
         self.assertEqual(len(qobj.experiments), 10)
 
+    def test_compile_single_qubit(self):
+        """ Compile a single-qubit circuit in a non-trivial layout
+        """
+        qr = QuantumRegister(1, 'qr')
+        circuit = QuantumCircuit(qr)
+        circuit.h(qr[0])
+        layout = {(qr, 0): 12}
+        cmap = [[1, 0], [1, 2], [2, 3], [4, 3], [4, 10], [5, 4], [5, 6], [5, 9], [6, 8], [7, 8],
+                [9, 8], [9, 10], [11, 3], [11, 10], [11, 12], [12, 2], [13, 1], [13, 12]]
+
+        qobj = compile(circuit, backend=None, coupling_map=cmap, basis_gates=['u2'],
+                       initial_layout=layout)
+
+        compiled_instruction = qobj.experiments[0].instructions[0]
+
+        self.assertEqual(compiled_instruction.name, 'u2')
+        self.assertEqual(compiled_instruction.qubits, [12])
+        self.assertEqual(str(compiled_instruction.params), str([0, 3.14159265358979]))
+
     def test_compile_pass_manager(self):
         """Test compile with and without an empty pass manager."""
         qr = QuantumRegister(2)