def _gradfunc(self, dv_dict, func_dict):

        fail = 0

        try:

            try:
                sens_dict = self.calc_gradient(dv_dict, self.quantities,
                                               return_format='dict',
                                               sparsity=self.sparsity)

            # Let the optimizer try to handle the error
            except AnalysisError:
                fail = 1

                # We need to cobble together a sens_dict of the correct size.
                # Best we can do is return zeros.

                sens_dict = OrderedDict()
                for okey, oval in iteritems(func_dict):
                    sens_dict[okey] = OrderedDict()
                    osize = len(oval)
                    for ikey, ival in iteritems(dv_dict):
                        isize = len(ival)
                        sens_dict[okey][ikey] = np.zeros((osize, isize))

            # Support for sub-index sparsity by returning the Jacobian in a
            # pyopt sparse format.
            for con, val1 in iteritems(self.sub_sparsity):
                for desvar, rel_idx in iteritems(val1):
                    coo = {}
                    jac = sens_dict[con][desvar]
                    nrow, ncol = jac.shape
                    coo['shape'] = [nrow, ncol]

                    row = []
                    col = []
                    data = []
                    ncol = len(rel_idx)
                    for i in range(nrow):
                        row.extend([i]*ncol)
                        col.extend(rel_idx)
                        data.extend(jac[i][rel_idx])

                    coo['coo'] = [np.array(row), np.array(col), np.array(data)]
                    sens_dict[con][desvar] = coo

        except Exception as msg:
            tb = traceback.format_exc()

            # Exceptions seem to be swallowed by the C code, so this
            # should give the user more info than the dreaded "segfault"
            print("Exception: %s" % str(msg))
            print(70*"=",tb,70*"=")
            sens_dict = {}

        #print("Derivatives calculated")
        #print(dv_dict)
        #print(sens_dict)
        return sens_dict, fail
Function that evaluates and returns the gradient of the objective
dataset/ETHPy150Open OpenMDAO/OpenMDAO/openmdao/drivers/pyoptsparse_driver.py/pyOptSparseDriver._gradfunc