prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Allow for np.integer as pulse duration
  <!-- ⚠️ 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?
  `duration` of pulse command should be python integer, but this limitation might degrade usability. It is better to allow for `np.integers` - e.g. when we prepare series of pulse commands with many durations with `np.arange`.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `qiskit/pulse/commands/pulse_decorators.py`
  Content:
  ```
  1 # -*- coding: utf-8 -*-
  2 
  3 # This code is part of Qiskit.
  4 #
  5 # (C) Copyright IBM 2017, 2019.
  6 #
  7 # This code is licensed under the Apache License, Version 2.0. You may
  8 # obtain a copy of this license in the LICENSE.txt file in the root directory
  9 # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
  10 #
  11 # Any modifications or derivative works of this code must retain this
  12 # copyright notice, and modified files need to carry a notice indicating
  13 # that they have been altered from the originals.
  14 
  15 # pylint: disable=missing-return-doc, missing-return-type-doc
  16 
  17 """
  18 Pulse decorators.
  19 """
  20 
  21 import functools
  22 from typing import Callable
  23 
  24 import numpy as np
  25 
  26 from qiskit.pulse.exceptions import PulseError
  27 
  28 from .sample_pulse import SamplePulse
  29 
  30 
  31 def functional_pulse(func: Callable):
  32     """A decorator for generating SamplePulse from python callable.
  33     Args:
  34         func: A function describing pulse envelope.
  35     Raises:
  36         PulseError: when invalid function is specified.
  37     """
  38     @functools.wraps(func)
  39     def to_pulse(duration, *args, name=None, **kwargs):
  40         """Return SamplePulse."""
  41         if isinstance(duration, int) and duration > 0:
  42             samples = func(duration, *args, **kwargs)
  43             samples = np.asarray(samples, dtype=np.complex128)
  44             return SamplePulse(samples=samples, name=name)
  45         raise PulseError('The first argument must be an integer value representing duration.')
  46 
  47     return to_pulse
  48
  ```
  
  Path: `qiskit/pulse/commands/command.py`
  Content:
  ```
  1 # -*- coding: utf-8 -*-
  2 
  3 # This code is part of Qiskit.
  4 #
  5 # (C) Copyright IBM 2017, 2019.
  6 #
  7 # This code is licensed under the Apache License, Version 2.0. You may
  8 # obtain a copy of this license in the LICENSE.txt file in the root directory
  9 # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
  10 #
  11 # Any modifications or derivative works of this code must retain this
  12 # copyright notice, and modified files need to carry a notice indicating
  13 # that they have been altered from the originals.
  14 
  15 """
  16 Base command.
  17 """
  18 import re
  19 
  20 from abc import ABCMeta, abstractmethod
  21 from typing import List, Optional
  22 
  23 from qiskit.pulse.exceptions import PulseError
  24 from qiskit.pulse.channels import Channel
  25 from qiskit.pulse.timeslots import TimeslotCollection
  26 
  27 from .instruction import Instruction
  28 
  29 
  30 class MetaCount(ABCMeta):
  31     """Meta class to count class instances."""
  32     def __new__(mcs, name, bases, namespace):
  33         new_cls = super(MetaCount, mcs).__new__(mcs, name, bases, namespace)
  34         new_cls.instances_counter = 0
  35         return new_cls
  36 
  37 
  38 class Command(metaclass=MetaCount):
  39     """Abstract command class."""
  40 
  41     # Counter for the number of instances in this class
  42     prefix = 'c'
  43 
  44     @abstractmethod
  45     def __init__(self, duration: int = None):
  46         """Create a new command.
  47 
  48         Args:
  49             duration: Duration of this command.
  50         Raises:
  51             PulseError: when duration is not number of points
  52         """
  53         if isinstance(duration, int):
  54             self._duration = duration
  55         else:
  56             raise PulseError('Pulse duration should be integer.')
  57 
  58         self._name = Command.create_name()
  59 
  60     @classmethod
  61     def create_name(cls, name: str = None) -> str:
  62         """Autogenerate names for pulse commands."""
  63         if name is None:
  64             try:
  65                 name = '%s%i' % (cls.prefix, cls.instances_counter)  # pylint: disable=E1101
  66             except TypeError:
  67                 raise PulseError("prefix and counter must be non-None when name is None.")
  68         else:
  69             try:
  70                 name = str(name)
  71             except Exception:
  72                 raise PulseError("The pulse command name should be castable to a string "
  73                                  "(or None for autogenerate a name).")
  74             name_format = re.compile('[a-zA-Z][a-zA-Z0-9_]*')
  75             if name_format.match(name) is None:
  76                 raise PulseError("%s is an invalid OpenPulse command name." % name)
  77 
  78         cls.instances_counter += 1  # pylint: disable=E1101
  79 
  80         return name
  81 
  82     @property
  83     def duration(self) -> int:
  84         """Duration of this command."""
  85         return self._duration
  86 
  87     @property
  88     def name(self) -> str:
  89         """Name of this command."""
  90         return self._name
  91 
  92     @abstractmethod
  93     def to_instruction(self, command, *channels: List[Channel],
  94                        timeslots: Optional[TimeslotCollection] = None,
  95                        name: Optional[str] = None) -> Instruction:
  96         """Create an instruction from command."""
  97         pass
  98 
  99     def __call__(self, *args, **kwargs):
  100         """Creates an Instruction obtained from call to `to_instruction` wrapped in a Schedule."""
  101         return self.to_instruction(*args, **kwargs)
  102 
  103     def __eq__(self, other: 'Command'):
  104         """Two Commands are the same if they are of the same type
  105         and have the same duration and name.
  106 
  107         Args:
  108             other: other Command
  109 
  110         Returns:
  111             bool: are self and other equal
  112         """
  113         if type(self) is type(other) and \
  114                 self._duration == other._duration and \
  115                 self._name == other._name:
  116             return True
  117         return False
  118 
  119     def __hash__(self):
  120         return hash((type(self), self._duration, self._name))
  121 
  122     def __repr__(self):
  123         return '%s(name=%s, duration=%d)' % (self.__class__.__name__,
  124                                              self._name, self._duration)
  125
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/qiskit/pulse/commands/command.py b/qiskit/pulse/commands/command.py
  --- a/qiskit/pulse/commands/command.py
  +++ b/qiskit/pulse/commands/command.py
  @@ -18,7 +18,8 @@
   import re
   
   from abc import ABCMeta, abstractmethod
  -from typing import List, Optional
  +from typing import List, Optional, Union
  +import numpy as np
   
   from qiskit.pulse.exceptions import PulseError
   from qiskit.pulse.channels import Channel
  @@ -42,7 +43,7 @@
       prefix = 'c'
   
       @abstractmethod
  -    def __init__(self, duration: int = None):
  +    def __init__(self, duration: Union[int, np.integer] = None):
           """Create a new command.
   
           Args:
  @@ -50,8 +51,8 @@
           Raises:
               PulseError: when duration is not number of points
           """
  -        if isinstance(duration, int):
  -            self._duration = duration
  +        if isinstance(duration, (int, np.integer)):
  +            self._duration = int(duration)
           else:
               raise PulseError('Pulse duration should be integer.')
   
  diff --git a/qiskit/pulse/commands/pulse_decorators.py b/qiskit/pulse/commands/pulse_decorators.py
  --- a/qiskit/pulse/commands/pulse_decorators.py
  +++ b/qiskit/pulse/commands/pulse_decorators.py
  @@ -38,7 +38,7 @@
       @functools.wraps(func)
       def to_pulse(duration, *args, name=None, **kwargs):
           """Return SamplePulse."""
  -        if isinstance(duration, int) and duration > 0:
  +        if isinstance(duration, (int, np.integer)) and duration > 0:
               samples = func(duration, *args, **kwargs)
               samples = np.asarray(samples, dtype=np.complex128)
               return SamplePulse(samples=samples, name=name)
  
verification_info: {"golden_diff": "diff --git a/qiskit/pulse/commands/command.py b/qiskit/pulse/commands/command.py\n--- a/qiskit/pulse/commands/command.py\n+++ b/qiskit/pulse/commands/command.py\n@@ -18,7 +18,8 @@\n import re\n \n from abc import ABCMeta, abstractmethod\n-from typing import List, Optional\n+from typing import List, Optional, Union\n+import numpy as np\n \n from qiskit.pulse.exceptions import PulseError\n from qiskit.pulse.channels import Channel\n@@ -42,7 +43,7 @@\n     prefix = 'c'\n \n     @abstractmethod\n-    def __init__(self, duration: int = None):\n+    def __init__(self, duration: Union[int, np.integer] = None):\n         \"\"\"Create a new command.\n \n         Args:\n@@ -50,8 +51,8 @@\n         Raises:\n             PulseError: when duration is not number of points\n         \"\"\"\n-        if isinstance(duration, int):\n-            self._duration = duration\n+        if isinstance(duration, (int, np.integer)):\n+            self._duration = int(duration)\n         else:\n             raise PulseError('Pulse duration should be integer.')\n \ndiff --git a/qiskit/pulse/commands/pulse_decorators.py b/qiskit/pulse/commands/pulse_decorators.py\n--- a/qiskit/pulse/commands/pulse_decorators.py\n+++ b/qiskit/pulse/commands/pulse_decorators.py\n@@ -38,7 +38,7 @@\n     @functools.wraps(func)\n     def to_pulse(duration, *args, name=None, **kwargs):\n         \"\"\"Return SamplePulse.\"\"\"\n-        if isinstance(duration, int) and duration > 0:\n+        if isinstance(duration, (int, np.integer)) and duration > 0:\n             samples = func(duration, *args, **kwargs)\n             samples = np.asarray(samples, dtype=np.complex128)\n             return SamplePulse(samples=samples, name=name)\n", "issue": "Allow for np.integer as pulse duration\n<!-- \u26a0\ufe0f If you do not respect this template, your issue will be closed -->\r\n<!-- \u26a0\ufe0f Make sure to browse the opened and closed issues to confirm this idea does not exist. -->\r\n\r\n### What is the expected enhancement?\r\n`duration` of pulse command should be python integer, but this limitation might degrade usability. It is better to allow for `np.integers` - e.g. when we prepare series of pulse commands with many durations with `np.arange`.\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\n# This code is part of Qiskit.\n#\n# (C) Copyright IBM 2017, 2019.\n#\n# This code is licensed under the Apache License, Version 2.0. You may\n# obtain a copy of this license in the LICENSE.txt file in the root directory\n# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.\n#\n# Any modifications or derivative works of this code must retain this\n# copyright notice, and modified files need to carry a notice indicating\n# that they have been altered from the originals.\n\n# pylint: disable=missing-return-doc, missing-return-type-doc\n\n\"\"\"\nPulse decorators.\n\"\"\"\n\nimport functools\nfrom typing import Callable\n\nimport numpy as np\n\nfrom qiskit.pulse.exceptions import PulseError\n\nfrom .sample_pulse import SamplePulse\n\n\ndef functional_pulse(func: Callable):\n    \"\"\"A decorator for generating SamplePulse from python callable.\n    Args:\n        func: A function describing pulse envelope.\n    Raises:\n        PulseError: when invalid function is specified.\n    \"\"\"\n    @functools.wraps(func)\n    def to_pulse(duration, *args, name=None, **kwargs):\n        \"\"\"Return SamplePulse.\"\"\"\n        if isinstance(duration, int) and duration > 0:\n            samples = func(duration, *args, **kwargs)\n            samples = np.asarray(samples, dtype=np.complex128)\n            return SamplePulse(samples=samples, name=name)\n        raise PulseError('The first argument must be an integer value representing duration.')\n\n    return to_pulse\n", "path": "qiskit/pulse/commands/pulse_decorators.py"}, {"content": "# -*- coding: utf-8 -*-\n\n# This code is part of Qiskit.\n#\n# (C) Copyright IBM 2017, 2019.\n#\n# This code is licensed under the Apache License, Version 2.0. You may\n# obtain a copy of this license in the LICENSE.txt file in the root directory\n# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.\n#\n# Any modifications or derivative works of this code must retain this\n# copyright notice, and modified files need to carry a notice indicating\n# that they have been altered from the originals.\n\n\"\"\"\nBase command.\n\"\"\"\nimport re\n\nfrom abc import ABCMeta, abstractmethod\nfrom typing import List, Optional\n\nfrom qiskit.pulse.exceptions import PulseError\nfrom qiskit.pulse.channels import Channel\nfrom qiskit.pulse.timeslots import TimeslotCollection\n\nfrom .instruction import Instruction\n\n\nclass MetaCount(ABCMeta):\n    \"\"\"Meta class to count class instances.\"\"\"\n    def __new__(mcs, name, bases, namespace):\n        new_cls = super(MetaCount, mcs).__new__(mcs, name, bases, namespace)\n        new_cls.instances_counter = 0\n        return new_cls\n\n\nclass Command(metaclass=MetaCount):\n    \"\"\"Abstract command class.\"\"\"\n\n    # Counter for the number of instances in this class\n    prefix = 'c'\n\n    @abstractmethod\n    def __init__(self, duration: int = None):\n        \"\"\"Create a new command.\n\n        Args:\n            duration: Duration of this command.\n        Raises:\n            PulseError: when duration is not number of points\n        \"\"\"\n        if isinstance(duration, int):\n            self._duration = duration\n        else:\n            raise PulseError('Pulse duration should be integer.')\n\n        self._name = Command.create_name()\n\n    @classmethod\n    def create_name(cls, name: str = None) -> str:\n        \"\"\"Autogenerate names for pulse commands.\"\"\"\n        if name is None:\n            try:\n                name = '%s%i' % (cls.prefix, cls.instances_counter)  # pylint: disable=E1101\n            except TypeError:\n                raise PulseError(\"prefix and counter must be non-None when name is None.\")\n        else:\n            try:\n                name = str(name)\n            except Exception:\n                raise PulseError(\"The pulse command name should be castable to a string \"\n                                 \"(or None for autogenerate a name).\")\n            name_format = re.compile('[a-zA-Z][a-zA-Z0-9_]*')\n            if name_format.match(name) is None:\n                raise PulseError(\"%s is an invalid OpenPulse command name.\" % name)\n\n        cls.instances_counter += 1  # pylint: disable=E1101\n\n        return name\n\n    @property\n    def duration(self) -> int:\n        \"\"\"Duration of this command.\"\"\"\n        return self._duration\n\n    @property\n    def name(self) -> str:\n        \"\"\"Name of this command.\"\"\"\n        return self._name\n\n    @abstractmethod\n    def to_instruction(self, command, *channels: List[Channel],\n                       timeslots: Optional[TimeslotCollection] = None,\n                       name: Optional[str] = None) -> Instruction:\n        \"\"\"Create an instruction from command.\"\"\"\n        pass\n\n    def __call__(self, *args, **kwargs):\n        \"\"\"Creates an Instruction obtained from call to `to_instruction` wrapped in a Schedule.\"\"\"\n        return self.to_instruction(*args, **kwargs)\n\n    def __eq__(self, other: 'Command'):\n        \"\"\"Two Commands are the same if they are of the same type\n        and have the same duration and name.\n\n        Args:\n            other: other Command\n\n        Returns:\n            bool: are self and other equal\n        \"\"\"\n        if type(self) is type(other) and \\\n                self._duration == other._duration and \\\n                self._name == other._name:\n            return True\n        return False\n\n    def __hash__(self):\n        return hash((type(self), self._duration, self._name))\n\n    def __repr__(self):\n        return '%s(name=%s, duration=%d)' % (self.__class__.__name__,\n                                             self._name, self._duration)\n", "path": "qiskit/pulse/commands/command.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\n# This code is part of Qiskit.\n#\n# (C) Copyright IBM 2017, 2019.\n#\n# This code is licensed under the Apache License, Version 2.0. You may\n# obtain a copy of this license in the LICENSE.txt file in the root directory\n# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.\n#\n# Any modifications or derivative works of this code must retain this\n# copyright notice, and modified files need to carry a notice indicating\n# that they have been altered from the originals.\n\n# pylint: disable=missing-return-doc, missing-return-type-doc\n\n\"\"\"\nPulse decorators.\n\"\"\"\n\nimport functools\nfrom typing import Callable\n\nimport numpy as np\n\nfrom qiskit.pulse.exceptions import PulseError\n\nfrom .sample_pulse import SamplePulse\n\n\ndef functional_pulse(func: Callable):\n    \"\"\"A decorator for generating SamplePulse from python callable.\n    Args:\n        func: A function describing pulse envelope.\n    Raises:\n        PulseError: when invalid function is specified.\n    \"\"\"\n    @functools.wraps(func)\n    def to_pulse(duration, *args, name=None, **kwargs):\n        \"\"\"Return SamplePulse.\"\"\"\n        if isinstance(duration, (int, np.integer)) and duration > 0:\n            samples = func(duration, *args, **kwargs)\n            samples = np.asarray(samples, dtype=np.complex128)\n            return SamplePulse(samples=samples, name=name)\n        raise PulseError('The first argument must be an integer value representing duration.')\n\n    return to_pulse\n", "path": "qiskit/pulse/commands/pulse_decorators.py"}, {"content": "# -*- coding: utf-8 -*-\n\n# This code is part of Qiskit.\n#\n# (C) Copyright IBM 2017, 2019.\n#\n# This code is licensed under the Apache License, Version 2.0. You may\n# obtain a copy of this license in the LICENSE.txt file in the root directory\n# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.\n#\n# Any modifications or derivative works of this code must retain this\n# copyright notice, and modified files need to carry a notice indicating\n# that they have been altered from the originals.\n\n\"\"\"\nBase command.\n\"\"\"\nimport re\n\nfrom abc import ABCMeta, abstractmethod\nfrom typing import List, Optional, Union\nimport numpy as np\n\nfrom qiskit.pulse.exceptions import PulseError\nfrom qiskit.pulse.channels import Channel\nfrom qiskit.pulse.timeslots import TimeslotCollection\n\nfrom .instruction import Instruction\n\n\nclass MetaCount(ABCMeta):\n    \"\"\"Meta class to count class instances.\"\"\"\n    def __new__(mcs, name, bases, namespace):\n        new_cls = super(MetaCount, mcs).__new__(mcs, name, bases, namespace)\n        new_cls.instances_counter = 0\n        return new_cls\n\n\nclass Command(metaclass=MetaCount):\n    \"\"\"Abstract command class.\"\"\"\n\n    # Counter for the number of instances in this class\n    prefix = 'c'\n\n    @abstractmethod\n    def __init__(self, duration: Union[int, np.integer] = None):\n        \"\"\"Create a new command.\n\n        Args:\n            duration: Duration of this command.\n        Raises:\n            PulseError: when duration is not number of points\n        \"\"\"\n        if isinstance(duration, (int, np.integer)):\n            self._duration = int(duration)\n        else:\n            raise PulseError('Pulse duration should be integer.')\n\n        self._name = Command.create_name()\n\n    @classmethod\n    def create_name(cls, name: str = None) -> str:\n        \"\"\"Autogenerate names for pulse commands.\"\"\"\n        if name is None:\n            try:\n                name = '%s%i' % (cls.prefix, cls.instances_counter)  # pylint: disable=E1101\n            except TypeError:\n                raise PulseError(\"prefix and counter must be non-None when name is None.\")\n        else:\n            try:\n                name = str(name)\n            except Exception:\n                raise PulseError(\"The pulse command name should be castable to a string \"\n                                 \"(or None for autogenerate a name).\")\n            name_format = re.compile('[a-zA-Z][a-zA-Z0-9_]*')\n            if name_format.match(name) is None:\n                raise PulseError(\"%s is an invalid OpenPulse command name.\" % name)\n\n        cls.instances_counter += 1  # pylint: disable=E1101\n\n        return name\n\n    @property\n    def duration(self) -> int:\n        \"\"\"Duration of this command.\"\"\"\n        return self._duration\n\n    @property\n    def name(self) -> str:\n        \"\"\"Name of this command.\"\"\"\n        return self._name\n\n    @abstractmethod\n    def to_instruction(self, command, *channels: List[Channel],\n                       timeslots: Optional[TimeslotCollection] = None,\n                       name: Optional[str] = None) -> Instruction:\n        \"\"\"Create an instruction from command.\"\"\"\n        pass\n\n    def __call__(self, *args, **kwargs):\n        \"\"\"Creates an Instruction obtained from call to `to_instruction` wrapped in a Schedule.\"\"\"\n        return self.to_instruction(*args, **kwargs)\n\n    def __eq__(self, other: 'Command'):\n        \"\"\"Two Commands are the same if they are of the same type\n        and have the same duration and name.\n\n        Args:\n            other: other Command\n\n        Returns:\n            bool: are self and other equal\n        \"\"\"\n        if type(self) is type(other) and \\\n                self._duration == other._duration and \\\n                self._name == other._name:\n            return True\n        return False\n\n    def __hash__(self):\n        return hash((type(self), self._duration, self._name))\n\n    def __repr__(self):\n        return '%s(name=%s, duration=%d)' % (self.__class__.__name__,\n                                             self._name, self._duration)\n", "path": "qiskit/pulse/commands/command.py"}]}