Repository: Qiskit/qiskit

Issue:
cannot load qasms containing delay
e.g.

```c
OPENQASM 2.0;
include "qelib1.inc";
qreg q[4];
creg meas[4];
delay(172) q[1];
u3(1.955526,-3.9994262,1.5396532) q[1];
```


Discussion:
Delay is not a standard instruction in QASM2. However, you could declare it as opaque.
```
OPENQASM 2.0;
include "qelib1.inc";

opaque delay(time) q;

qreg q[4];
creg meas[4];
delay(172) q[1];
u3(1.955526,-3.9994262,1.5396532) q[1];
```

Loading this as a circuit will result in a custom opaque gate, which I think we could map to our delay instruction:
```
circuit = QuantumCircuit.from_qasm_str(qasm)
circuit.draw(idle_wires=False)
```
```
     ┌────────────┐┌───────────────────────────┐
q_1: ┤ delay(172) ├┤ U3(1.9555,-3.9994,1.5397) ├
     └────────────┘└───────────────────────────┘
```

Notice that:
```
circuit.data[0]
```
```
<qiskit.circuit.gate.Gate at 0x12f5a9b50>
```

So, if I understand you correctly, the output of the last example should be:
```
Delay(duration=172[unit=dt])
```

Resolving patch:
diff --git a/qiskit/circuit/delay.py b/qiskit/circuit/delay.py
--- a/qiskit/circuit/delay.py
+++ b/qiskit/circuit/delay.py
@@ -72,7 +72,10 @@ def validate_parameter(self, parameter):
             return parameter
         elif isinstance(parameter, float):
             if self.unit == "dt":
-                raise CircuitError("Integer duration is expected for 'dt' unit.")
+                parameter_int = int(parameter)
+                if parameter != parameter_int:
+                    raise CircuitError("Integer duration is expected for 'dt' unit.")
+                return parameter_int
             return parameter
         elif isinstance(parameter, ParameterExpression):
             if len(parameter.parameters) > 0:
diff --git a/qiskit/converters/ast_to_dag.py b/qiskit/converters/ast_to_dag.py
--- a/qiskit/converters/ast_to_dag.py
+++ b/qiskit/converters/ast_to_dag.py
@@ -24,6 +24,7 @@
 from qiskit.circuit.measure import Measure
 from qiskit.circuit.reset import Reset
 from qiskit.circuit.barrier import Barrier
+from qiskit.circuit.delay import Delay
 from qiskit.circuit.library.standard_gates.x import CCXGate
 from qiskit.circuit.library.standard_gates.swap import CSwapGate
 from qiskit.circuit.library.standard_gates.x import CXGate
@@ -140,6 +141,7 @@ class AstInterpreter:
         "cu3": CU3Gate,
         "ccx": CCXGate,
         "cswap": CSwapGate,
+        "delay": Delay,
     }
 
     def __init__(self, dag):


Test patch:
diff --git a/test/python/circuit/test_circuit_load_from_qasm.py b/test/python/circuit/test_circuit_load_from_qasm.py
--- a/test/python/circuit/test_circuit_load_from_qasm.py
+++ b/test/python/circuit/test_circuit_load_from_qasm.py
@@ -474,6 +474,24 @@ def test_from_qasm_str_nested_custom_gate(self):
         expected.u(-0.5235987755982988, 6.283185307179586, 3.141592653589793, qr[0])
         self.assertEqualUnroll("u", circuit, expected)
 
+    def test_from_qasm_str_delay(self):
+        """Test delay instruction/opaque-gate
+        See: https://github.com/Qiskit/qiskit-terra/issues/6510
+        """
+        qasm_string = """OPENQASM 2.0;
+                         include "qelib1.inc";
+
+                         opaque delay(time) q;
+
+                         qreg q[1];
+                         delay(172) q[0];"""
+        circuit = QuantumCircuit.from_qasm_str(qasm_string)
+
+        qr = QuantumRegister(1, name="q")
+        expected = QuantumCircuit(qr, name="circuit")
+        expected.delay(172, qr[0])
+        self.assertEqualUnroll("u", circuit, expected)
+
     def assertEqualUnroll(self, basis, circuit, expected):
         """Compares the dags after unrolling to basis"""
         circuit_dag = circuit_to_dag(circuit)