# Buggy code
def params(self, parameters):
    self._params = []
    for single_param in parameters:
        # example: u2(pi/2, sin(pi/4))
        if isinstance(single_param, (ParameterExpression)):
            self._params.append(single_param)
        # example: u3(0.1, 0.2, 0.3)
        elif isinstance(single_param, (int, float)):
            self._params.append(single_param)
        # example: Initialize([complex(0,1), complex(0,0)])
        elif isinstance(single_param, complex):
            self._params.append(single_param)
        # example: snapshot('label')
        elif isinstance(single_param, str):
            self._params.append(single_param)
        # example: Aer expectation_value_snapshot [complex, 'X']
        elif isinstance(single_param, list):
            self._params.append(single_param)
        # example: numpy.array([[1, 0], [0, 1]])
        elif isinstance(single_param, numpy.ndarray):
            self._params.append(single_param)
        elif isinstance(single_param, numpy.number):
            self._params.append(single_param.item())
        else:
            raise CircuitError(
                "invalid param type {0} in instruction {1}".format(
                    type(single_param), self.name
                )
            )


# Traceback (RuntimeError)
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-42-e6a6395b5aa4> in <module>
6 backend = Aer.get_backend('statevector_simulator')
7 job = execute(qc, backend)
----> 8 result = job.result()

/usr/local/anaconda3/lib/python3.7/site-packages/qiskit/providers/aer/aerjob.py in _wrapper(self, *args, **kwargs)
39         if self._future is None:
40             raise JobError("Job not submitted yet!. You have to .submit() first!")
---> 41         return func(self, *args, **kwargs)
42     return _wrapper
43

/usr/local/anaconda3/lib/python3.7/site-packages/qiskit/providers/aer/aerjob.py in result(self, timeout)
92             concurrent.futures.CancelledError: if job cancelled before completed.
93         """
---> 94         return self._future.result(timeout=timeout)
95
96     @requires_submit

/usr/local/anaconda3/lib/python3.7/concurrent/futures/_base.py in result(self, timeout)
433                 raise CancelledError()
434             elif self._state == FINISHED:
--> 435                 return self.__get_result()
436             else:
437                 raise TimeoutError()

/usr/local/anaconda3/lib/python3.7/concurrent/futures/_base.py in __get_result(self)
382     def __get_result(self):
383         if self._exception:
--> 384             raise self._exception
385         else:
386             return self._result

/usr/local/anaconda3/lib/python3.7/concurrent/futures/thread.py in run(self)
55
56         try:
---> 57             result = self.fn(*self.args, **self.kwargs)
58         except BaseException as exc:
59             self.future.set_exception(exc)

/usr/local/anaconda3/lib/python3.7/site-packages/qiskit/providers/aer/backends/aerbackend.py in _run_job(self, job_id, qobj, backend_options, noise_model, validate)
131             validate_qobj_against_schema(qobj)
132             self._validate(qobj, backend_options, noise_model)
--> 133         output = self._controller(self._format_qobj(qobj, backend_options, noise_model))
134         self._validate_controller_output(output)
135         end = time.time()

RuntimeError: Unable to cast Python instance to C++ type (compile in debug mode for details)

# Fixed code
def params(self, parameters):
    self._params = []
    for single_param in parameters:
        # example: u2(pi/2, sin(pi/4))
        if isinstance(single_param, (ParameterExpression)):
            self._params.append(single_param)
        elif isinstance(single_param, numpy.number):
            self._params.append(single_param.item())
        # example: u3(0.1, 0.2, 0.3)
        elif isinstance(single_param, (int, float)):
            self._params.append(single_param)
        # example: Initialize([complex(0,1), complex(0,0)])
        elif isinstance(single_param, complex):
            self._params.append(single_param)
        # example: snapshot('label')
        elif isinstance(single_param, str):
            self._params.append(single_param)
        # example: Aer expectation_value_snapshot [complex, 'X']
        elif isinstance(single_param, list):
            self._params.append(single_param)
        # example: numpy.array([[1, 0], [0, 1]])
        elif isinstance(single_param, numpy.ndarray):
            self._params.append(single_param)
        else:
            raise CircuitError(
                "invalid param type {0} in instruction {1}".format(
                    type(single_param), self.name
                )
            )