Repository: Qiskit/qiskit

Issue:
Empty circuits from transpiler fail qobj validation
<!-- ⚠️ 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?
The compiler removes all the gates from this circuit and leaves an empty circuit that fails validation.

```
qr = QuantumRegister(2, 'qr')
circuit = QuantumCircuit(qr)
circuit.h(qr[0])
circuit.h(qr[0])
circuit.cx(qr[0], qr[1])
circuit.cx(qr[0], qr[1])
circuit.cx(qr[0], qr[1])
circuit.cx(qr[0], qr[1])

coupling_map = [[0, 1]]
basis_gates = ['u1', 'u2', 'u3', 'cx', 'id']

backend = BasicAer.get_backend('qasm_simulator')

qobj = compile(circuit, backend=backend, coupling_map=coupling_map, basis_gates=basis_gates)
```

```
ModelValidationError: {'instructions': ['Shorter than minimum length 1.']}
```
### Steps to reproduce the problem



### What is the expected behavior?
I believe that a valid circuit returned by the transpiler, in this case an empty circuit, should result in a valid qobj.

### Suggested solutions





Discussion:
What would you suggest the fix is here? The transpiler is able to optimize that circuit away to include 0 elements. It looks like the validation model for qobj enforces at least 1 element:  https://github.com/Qiskit/qiskit-terra/blob/master/qiskit/qobj/models/qasm.py#L53 (man was that irritating to find) for the instructions in the circuit (it's also in a few other places which we should remove at the same time for consistency, but that line is the only one blocking your use case). If we just remove that condition it should work fine. I don't anything in the qobj spec actually says there need to be any items in instructions, just that the element is there.
I would remove the restriction. 

Resolving patch:
diff --git a/qiskit/qobj/models/base.py b/qiskit/qobj/models/base.py
--- a/qiskit/qobj/models/base.py
+++ b/qiskit/qobj/models/base.py
@@ -7,7 +7,7 @@
 
 """The generic qobj models."""
 
-from marshmallow.validate import Length, Range
+from marshmallow.validate import Range
 
 from qiskit.validation import BaseSchema, bind_schema, BaseModel
 from qiskit.validation.fields import String, Nested, Integer
@@ -34,8 +34,7 @@ class QobjExperimentSchema(BaseSchema):
     """Base Schema for QobjExperiment."""
 
     # Required properties.
-    instructions = Nested(QobjInstructionSchema, required=True, many=True,
-                          validate=Length(min=1))
+    instructions = Nested(QobjInstructionSchema, required=True, many=True)
 
     # Optional properties.
     header = Nested(QobjExperimentHeaderSchema)
diff --git a/qiskit/qobj/models/qasm.py b/qiskit/qobj/models/qasm.py
--- a/qiskit/qobj/models/qasm.py
+++ b/qiskit/qobj/models/qasm.py
@@ -49,8 +49,7 @@ class QasmQobjExperimentSchema(QobjExperimentSchema):
     """Schema for QasmQobjExperiment."""
 
     # Required properties.
-    instructions = Nested(QasmQobjInstructionSchema, required=True, many=True,
-                          validate=Length(min=1))
+    instructions = Nested(QasmQobjInstructionSchema, required=True, many=True)
 
     # Optional properties.
     config = Nested(QasmQobjExperimentConfigSchema)


Test patch: