Repository: Qiskit/qiskit

Issue:
Bug in mapping?
<!--- Provide a general summary of the issue in the Title above -->
Measurement results differ in compiling with/without coupling_map.

## Expected Behavior
<!--- If you're describing a bug, tell us what should happen -->
<!--- If you're suggesting a change/improvement, tell us how it should work -->
With this QASM (`coupling_map=None`), expected measurement results are {'1001', '0001'}
```
OPENQASM 2.0;
include "qelib1.inc";
qreg q[4];
creg c[4];
// -X-.-----
// -Y-+-S-.-
// -Z-.-T-+-
// ---+-H---
x q[0];
y q[1];
z q[2];
cx q[0], q[1];
cx q[2], q[3];
s q[1];
t q[2];
h q[3];
cx q[1], q[2];
measure q[0] -> c[0];
measure q[1] -> c[1];
measure q[2] -> c[2];
measure q[3] -> c[3];
```

## Current Behavior
<!--- If describing a bug, tell us what happens instead of the expected behavior -->
<!--- If suggesting a change/improvement, explain the difference from current behavior -->
{'0000', '1000'} are obtained with `coupling_map = {0: [2], 1: [2], 2: [3], 3: []}`

## Steps to Reproduce (for bugs)
<!--- Provide a link to a live example, or an unambiguous set of steps to -->
<!--- reproduce this bug. Include code to reproduce, if relevant -->
```
        qp = QuantumProgram()
        qp.load_qasm_file('qasm_above.qasm', name='test2')
        coupling_map = {0: [2], 1: [2], 2: [3], 3: []}
        result1 = qp.execute(["test2"], backend="local_qasm_simulator", coupling_map=coupling_map)
        print(result1.get_counts("test2"))
        result2 = qp.execute(["test2"], backend="local_qasm_simulator", coupling_map=None)
        print(result2.get_counts("test2"))
```



Discussion:
I cannot assign myself this issue. But I would like to have a shot to see if I can fix it... just FYI
The attached patch fixes this issue.

If the first layer is trivial, it should not be ignored. Fixes #81
[mapping.patch.zip](https://github.com/QISKit/qiskit-sdk-py/files/1354150/mapping.patch.zip)



Resolving patch:
diff --git a/qiskit/_openquantumcompiler.py b/qiskit/_openquantumcompiler.py
--- a/qiskit/_openquantumcompiler.py
+++ b/qiskit/_openquantumcompiler.py
@@ -37,7 +37,7 @@ def compile(qasm_circuit, basis_gates='u1,u2,u3,cx,id', coupling_map=None,
         initial_layout (dict): A mapping of qubit to qubit::
 
                               {
-                                ("q", strart(int)): ("q", final(int)),
+                                ("q", start(int)): ("q", final(int)),
                                 ...
                               }
                               eg.
diff --git a/qiskit/mapper/_mapping.py b/qiskit/mapper/_mapping.py
--- a/qiskit/mapper/_mapping.py
+++ b/qiskit/mapper/_mapping.py
@@ -332,8 +332,8 @@ def swap_mapper(circuit_graph, coupling_graph,
     # Schedule the input circuit
     layerlist = circuit_graph.layers()
     logger.debug("schedule:")
-    for i in range(len(layerlist)):
-        logger.debug("    %d: %s", i, layerlist[i]["partition"])
+    for i,v in enumerate(layerlist):
+        logger.debug("    %d: %s", (i, v["partition"]))
 
     if initial_layout is not None:
         # Check the input layout
@@ -372,13 +372,6 @@ def swap_mapper(circuit_graph, coupling_graph,
         logger.debug("swap_mapper: success_flag=%s,best_d=%s,trivial_flag=%s",
                      success_flag, str(best_d), trivial_flag)
 
-        # If this layer is only single-qubit gates,
-        # and we have yet to see multi-qubit gates,
-        # continue to the next iteration
-        if trivial_flag and first_layer:
-            logger.debug("swap_mapper: skip to next layer")
-            continue
-
         # If this fails, try one gate at a time in this layer
         if not success_flag:
             logger.debug("swap_mapper: failed, layer %d, "


Test patch: