Repository: Qiskit/qiskit

Issue:
QuantumCircuit constructor fails if n_qubits is np.int64
<!-- ⚠️ 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?

```
Python 3.5.6 |Anaconda, Inc.| (default, Aug 26 2018, 16:30:03)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> import qiskit as qk
>>> n = np.int64(12)
>>> qr = qk.QuantumRegister(n)
>>> qc = qk.QuantumCircuit(n)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/kevin.krsulichibm.com/q/qiskit-terra/qiskit/circuit/quantumcircuit.py", line 157, in __init__
    self.add_register(*regs)
  File "/Users/kevin.krsulichibm.com/q/qiskit-terra/qiskit/circuit/quantumcircuit.py", line 541, in add_register
    if register.name in [reg.name for reg in self.qregs + self.cregs]:
AttributeError: 'numpy.int64' object has no attribute 'name'
```

Similar to as was added for `Register`s in #2288, the `QuantumCircuit` constructor should test if a provided argument can be cast to an int before it raises an error.

For reference, here is where `Register` does the check:
https://github.com/Qiskit/qiskit-terra/blob/2ee7a3a/qiskit/circuit/register.py#L39

and where `QuantumCircuit` makes new `Registers` from the provided `int`:
https://github.com/Qiskit/qiskit-terra/blob/703c9a3/qiskit/circuit/quantumcircuit.py#L522


Discussion:
@1ucian0 have you made progress on this? I'd like to give it a go if not (I'm new to qiskit and open source and this looks like a nice first issue to try out!)
Sure! Go ahead! 
Yay great I'll get cracking! Is there a corresponding test file that needs updating as well? 
Yes, tests should be added (maybe in the files we already have?). You can use the code from OP for that.

Resolving patch:
diff --git a/qiskit/circuit/quantumcircuit.py b/qiskit/circuit/quantumcircuit.py
--- a/qiskit/circuit/quantumcircuit.py
+++ b/qiskit/circuit/quantumcircuit.py
@@ -124,6 +124,13 @@ class QuantumCircuit:
     extension_lib = "include \"qelib1.inc\";"
 
     def __init__(self, *regs, name=None):
+        if any([not isinstance(reg, (QuantumRegister, ClassicalRegister)) for reg in regs]):
+            try:
+                regs = tuple(int(reg) for reg in regs)
+            except Exception:
+                raise CircuitError("Circuit args must be Registers or be castable to an int" +
+                                   "(%s '%s' was provided)"
+                                   % ([type(reg).__name__ for reg in regs], regs))
         if name is None:
             name = self.cls_prefix() + str(self.cls_instances())
             if sys.platform != "win32" and not is_main_process():


Test patch:
diff --git a/test/python/circuit/test_circuit_properties.py b/test/python/circuit/test_circuit_properties.py
--- a/test/python/circuit/test_circuit_properties.py
+++ b/test/python/circuit/test_circuit_properties.py
@@ -17,8 +17,10 @@
 """Test Qiskit's inverse gate operation."""
 
 import unittest
+import numpy as np
 from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
 from qiskit.test import QiskitTestCase
+from qiskit.circuit.exceptions import CircuitError
 # pylint: disable=unused-import
 from qiskit.extensions.simulator import snapshot
 
@@ -26,6 +28,37 @@
 class TestCircuitProperties(QiskitTestCase):
     """QuantumCircuit properties tests."""
 
+    def test_qarg_numpy_int(self):
+        """Test castable to integer args for QuantumCircuit.
+        """
+        n = np.int64(12)
+        qc1 = QuantumCircuit(n)
+        self.assertEqual(qc1.n_qubits, 12)
+        self.assertEqual(type(qc1), QuantumCircuit)
+
+    def test_carg_numpy_int(self):
+        """Test castable to integer cargs for QuantumCircuit.
+        """
+        n = np.int64(12)
+        c1 = ClassicalRegister(n)
+        qc1 = QuantumCircuit(c1)
+        c_regs = qc1.cregs
+        self.assertEqual(c_regs[0], c1)
+        self.assertEqual(type(qc1), QuantumCircuit)
+
+    def test_carg_numpy_int_2(self):
+        """Test castable to integer cargs for QuantumCircuit.
+        """
+        qc1 = QuantumCircuit(12, np.int64(12))
+        c_regs = qc1.cregs
+        self.assertEqual(c_regs[0], ClassicalRegister(12, 'c'))
+        self.assertEqual(type(qc1), QuantumCircuit)
+
+    def test_qarg_numpy_int_exception(self):
+        """Test attempt to pass non-castable arg to QuantumCircuit.
+        """
+        self.assertRaises(CircuitError, QuantumCircuit, 'string')
+
     def test_circuit_depth_empty(self):
         """Test depth of empty circuity
         """