Repository: Qiskit/qiskit

Issue:
pulse delay instruction cause error when np.int is given
<!-- ⚠️ 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 enhancement?

T1 experiment for example:
```python
delay_times = np.linspace(0, 200, 21, dtype=int)

for delay_time in delay_times:
    ...
    sched += Delay(delay_time, d0)
```

This program will cause an error:
```
AttributeError: 'numpy.int64' object has no attribute 'name'
```

np.int should be allowed for the `duration` of Delay instruction.


Discussion:
This is a bug introduced by #3750 and the accompanying support for backward compatibility.
@taalexander Is this as simple as casting `duration` in `class Delay` to an int, or are there deeper ramifications? If it's not too deep, I can take this on.
Other than adding a test to go along with your fix, I think its that simple 😄 .
One thing is that this would convert 3.5 to 3. Don't know if that's acceptable or not. The test for isinstance takes place in Instruction. I noticed that in the module Command that it imports numpy and uses `isinstance(duration, (int, np.integer))`. Is it acceptable to import numpy into Instruction and use this form of isinstance? Seems cleaner and more consistent to me.
This seems fine to me.
Thanks. Then I'm on it.

Resolving patch:
diff --git a/qiskit/pulse/instructions/instruction.py b/qiskit/pulse/instructions/instruction.py
--- a/qiskit/pulse/instructions/instruction.py
+++ b/qiskit/pulse/instructions/instruction.py
@@ -28,6 +28,7 @@
 from abc import ABC
 
 from typing import Tuple, List, Iterable, Callable, Optional, Union
+import numpy as np
 
 from ..channels import Channel
 from ..interfaces import ScheduleComponent
@@ -58,7 +59,7 @@ def __init__(self,
             name: Optional display name for this instruction.
         """
         self._command = None
-        if not isinstance(duration, int):
+        if not isinstance(duration, (int, np.integer)):
             warnings.warn("Commands have been deprecated. Use `qiskit.pulse.instructions` instead.",
                           DeprecationWarning)
             self._command = duration


Test patch:
diff --git a/test/python/pulse/test_instructions.py b/test/python/pulse/test_instructions.py
--- a/test/python/pulse/test_instructions.py
+++ b/test/python/pulse/test_instructions.py
@@ -14,6 +14,7 @@
 
 """Unit tests for pulse instructions."""
 
+import numpy as np
 from qiskit.pulse import DriveChannel, AcquireChannel, MemorySlot, pulse_lib
 from qiskit.pulse import Delay, Play, ShiftPhase, Snapshot, SetFrequency, Acquire
 from qiskit.pulse.configuration import Kernel, Discriminator
@@ -61,11 +62,17 @@ def test_delay(self):
         self.assertIsInstance(delay.id, int)
         self.assertEqual(delay.name, 'test_name')
         self.assertEqual(delay.duration, 10)
+        self.assertIsInstance(delay.duration, int)
         self.assertEqual(delay.operands, (10, DriveChannel(0)))
         self.assertEqual(delay, Delay(10, DriveChannel(0)))
         self.assertNotEqual(delay, Delay(11, DriveChannel(1)))
         self.assertEqual(repr(delay), "Delay(10, DriveChannel(0), name='test_name')")
 
+        # Test numpy int for duration
+        delay = Delay(np.int32(10), DriveChannel(0), name='test_name2')
+        self.assertEqual(delay.duration, 10)
+        self.assertIsInstance(delay.duration, np.integer)
+
 
 class TestSetFrequency(QiskitTestCase):
     """Set frequency tests."""