Repository: Qiskit/qiskit

Issue:
Need a Qobj2Circuits method
<!-- ⚠️ If you do not respect this template, your issue will be closed -->
<!-- ⚠️ Make sure to browse the opened and closed issues to confirm this idea does not exist. -->

### What is the expected behavior?
There is a need to be able to reconstruct a QuantumCircuit (or list of QuantumCircuits) from a compiled Qobj. This is to be able to inspect the circuit after it has been compiled. We need a wrapper method for this.

Currently this is doable by this long nested call:
```python
circuits = [load_qasm_string(exp.header.compiled_circuit_qasm) for exp in qobj.experiments]
```


Discussion:
@ajavadia I'm assuming here you mean construct a QuantumCircuit object from a Qobj but not using the qasm embedded in the header right? Since that's not guaranteed to be there.
@mtreinish Yes, you are right. But I wouldn't mind creating this function in the easy way now (using `compiled_circuit_qasm`), then refining it later to not rely on that. All Qobjs we currently create have this field right? 
The function should probably go in the wrapper, similar to `load_qasm_string`.

Resolving patch:
diff --git a/qiskit/wrapper/__init__.py b/qiskit/wrapper/__init__.py
--- a/qiskit/wrapper/__init__.py
+++ b/qiskit/wrapper/__init__.py
@@ -18,4 +18,4 @@
 from ._wrapper import (available_backends, local_backends, remote_backends,
                        get_backend, compile, execute, register, unregister,
                        registered_providers, load_qasm_string, load_qasm_file,
-                       least_busy, store_credentials)
+                       least_busy, store_credentials, qobj_to_circuits)
diff --git a/qiskit/wrapper/_wrapper.py b/qiskit/wrapper/_wrapper.py
--- a/qiskit/wrapper/_wrapper.py
+++ b/qiskit/wrapper/_wrapper.py
@@ -364,3 +364,24 @@ def load_qasm_file(qasm_file, name=None,
         QISKitError: if the file cannot be read.
     """
     return circuit_from_qasm_file(qasm_file, name, basis_gates)
+
+
+def qobj_to_circuits(qobj):
+    """Return a list of QuantumCircuit object(s) from a qobj
+
+    Args:
+        qobj (Qobj): The Qobj object to convert to QuantumCircuits
+    Returns:
+        list: A list of QuantumCircuit objects from the qobj
+
+    """
+    if qobj.experiments:
+        circuits = []
+        for x in qobj.experiments:
+            if hasattr(x.header, 'compiled_circuit_qasm'):
+                circuits.append(
+                    load_qasm_string(x.header.compiled_circuit_qasm))
+        return circuits
+    # TODO(mtreinish): add support for converting a qobj if the qasm isn't
+    # embedded in the header
+    return None


Test patch:
diff --git a/test/python/test_wrapper.py b/test/python/test_wrapper.py
--- a/test/python/test_wrapper.py
+++ b/test/python/test_wrapper.py
@@ -11,10 +11,12 @@
 import logging
 import unittest
 
+from qiskit import compile as qcompile
 import qiskit.wrapper
 from qiskit import QISKitError
 from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
 from qiskit.backends.ibmq import IBMQProvider
+from qiskit.qobj import Qobj
 from qiskit.wrapper import registered_providers, execute
 from ._mockutils import DummyProvider
 from .common import QiskitTestCase, requires_qe_access
@@ -141,6 +143,34 @@ def test_local_execute_and_get_ran_qasm(self):
                 result = execute(self.circuit, 'local_qasm_simulator').result()
                 self.assertIsNotNone(result.get_ran_qasm(self.circuit.name))
 
+    def test_qobj_to_circuits_single(self):
+        """Check that qobj_to_circuits's result matches the qobj ini."""
+        backend = 'local_qasm_simulator'
+        qobj_in = qcompile(self.circuit, backend, skip_transpiler=True)
+        out_circuit = qiskit.wrapper.qobj_to_circuits(qobj_in)
+        self.assertEqual(out_circuit[0].qasm(), self.circuit.qasm())
+
+    def test_qobj_to_circuits_multiple(self):
+        """Check that qobj_to_circuits's result with multiple circuits"""
+        backend = 'local_qasm_simulator'
+        qreg1 = QuantumRegister(2)
+        qreg2 = QuantumRegister(3)
+        creg1 = ClassicalRegister(2)
+        creg2 = ClassicalRegister(2)
+        circuit_b = QuantumCircuit(qreg1, qreg2, creg1, creg2)
+        circuit_b.x(qreg1)
+        circuit_b.h(qreg2)
+        circuit_b.measure(qreg1, creg1)
+        circuit_b.measure(qreg2[0], creg2[1])
+        qobj = qcompile([self.circuit, circuit_b], backend, skip_transpiler=True)
+        qasm_list = [x.qasm() for x in qiskit.wrapper.qobj_to_circuits(qobj)]
+        self.assertEqual(qasm_list, [self.circuit.qasm(), circuit_b.qasm()])
+
+    def test_qobj_to_circuits_with_qobj_no_qasm(self):
+        """Verify that qobj_to_circuits returns None without QASM."""
+        qobj = Qobj('abc123', {}, {}, {})
+        self.assertIsNone(qiskit.wrapper.qobj_to_circuits(qobj))
+
 
 if __name__ == '__main__':
     unittest.main(verbosity=2)