openmdao/core/problem.py
def check_totals(self, of=None, wrt=None, out_stream=_DEFAULT_OUT_STREAM, compact_print=False,
                     driver_scaling=False, abs_err_tol=1e-6, rel_err_tol=1e-6,
                     method='fd', step=None, form='forward', step_calc='abs'):
        """
        Check total derivatives for the model vs. finite difference.

        Parameters
        ----------
        of : list of variable name strings or None
            Variables whose derivatives will be computed. Default is None, which
            uses the driver's objectives and constraints.
        wrt : list of variable name strings or None
            Variables with respect to which the derivatives will be computed.
            Default is None, which uses the driver's desvars.
        out_stream : file-like object
            Where to send human readable output. By default it goes to stdout.
            Set to None to suppress.
        compact_print : bool
            Set to True to just print the essentials, one line per unknown-param pair.
        driver_scaling : bool
            Set to True to scale derivative values by the quantities specified when the desvars and
            responses were added. Default if False, which is unscaled.
        abs_err_tol : float
            Threshold value for absolute error.  Errors about this value will have a '*' displayed
            next to them in output, making them easy to search for. Default is 1.0E-6.
        rel_err_tol : float
            Threshold value for relative error.  Errors about this value will have a '*' displayed
            next to them in output, making them easy to search for. Note at times there may be a
            significant relative error due to a minor absolute error.  Default is 1.0E-6.
        method : str
            Method, 'fd' for finite difference or 'cs' for complex step. Default is 'fd'
        step : float
            Step size for approximation. Default is None, which means 1e-6 for 'fd' and 1e-40 for
            'cs'.
        form : string
            Form for finite difference, can be 'forward', 'backward', or 'central'. Default
            'forward'.
        step_calc : string
            Step type for finite difference, can be 'abs' for absolute', or 'rel' for relative.
            Default is 'abs'.

        Returns
        -------
        Dict of Dicts of Tuples of Floats

            First key:
                is the (output, input) tuple of strings;
            Second key:
                is one of ['rel error', 'abs error', 'magnitude', 'fdstep'];

            For 'rel error', 'abs error', 'magnitude' the value is: A tuple containing norms for
                forward - fd, adjoint - fd, forward - adjoint.
        """
        model = self.model

        if method == 'cs' and not model._outputs._alloc_complex:
            msg = "\nTo enable complex step, specify 'force_alloc_complex=True' when calling " + \
                  "setup on the problem, e.g. 'problem.setup(force_alloc_complex=True)'"
            raise RuntimeError(msg)

        # TODO: Once we're tracking iteration counts, run the model if it has not been run before.

        with self.model._scaled_context_all():

            # Calculate Total Derivatives
            total_info = _TotalJacInfo(self, of, wrt, False, return_format='flat_dict',
                                       driver_scaling=driver_scaling)
            Jcalc = total_info.compute_totals()

            if step is None:
                if method == 'cs':
                    step = DEFAULT_CS_OPTIONS['step']
                else:
                    step = DEFAULT_FD_OPTIONS['step']

            # Approximate FD
            fd_args = {
                'step': step,
                'form': form,
                'step_calc': step_calc,
            }
            approx = model._owns_approx_jac
            old_jac = model._jacobian

            model.approx_totals(method=method, step=step, form=form,
                                step_calc=step_calc if method is 'fd' else None)
            total_info = _TotalJacInfo(self, of, wrt, False, return_format='flat_dict', approx=True,
                                       driver_scaling=driver_scaling)
            Jfd = total_info.compute_totals_approx(initialize=True)

            # reset the _owns_approx_jac flag after approximation is complete.
            if not approx:
                model._jacobian = old_jac
                model._owns_approx_jac = False

        # Assemble and Return all metrics.
        data = {}
        data[''] = {}
        for key, val in iteritems(Jcalc):
            data[''][key] = {}
            data[''][key]['J_fwd'] = val
            data[''][key]['J_fd'] = Jfd[key]
        fd_args['method'] = 'fd'

        if out_stream == _DEFAULT_OUT_STREAM:
            out_stream = sys.stdout

        _assemble_derivative_data(data, rel_err_tol, abs_err_tol, out_stream, compact_print,
                                  [model], {'': fd_args}, totals=True)
        return data['']

        Check total derivatives for the model vs. finite difference.

        Parameters
        ----------
        of : list of variable name strings or None
            Variables whose derivatives will be computed. Default is None, which
            uses the driver's objectives and constraints.
        wrt : list of variable name strings or None
            Variables with respect to which the derivatives will be computed.
            Default is None, which uses the driver's desvars.
        out_stream : file-like object
            Where to send human readable output. By default it goes to stdout.
            Set to None to suppress.
        compact_print : bool
            Set to True to just print the essentials, one line per unknown-param pair.
        driver_scaling : bool
            Set to True to scale derivative values by the quantities specified when the desvars and
            responses were added. Default if False, which is unscaled.
        abs_err_tol : float
            Threshold value for absolute error.  Errors about this value will have a '*' displayed
            next to them in output, making them easy to search for. Default is 1.0E-6.
        rel_err_tol : float
            Threshold value for relative error.  Errors about this value will have a '*' displayed
            next to them in output, making them easy to search for. Note at times there may be a
            significant relative error due to a minor absolute error.  Default is 1.0E-6.
        method : str
            Method, 'fd' for finite difference or 'cs' for complex step. Default is 'fd'
        step : float
            Step size for approximation. Default is None, which means 1e-6 for 'fd' and 1e-40 for
            'cs'.
        form : string
            Form for finite difference, can be 'forward', 'backward', or 'central'. Default
            'forward'.
        step_calc : string
            Step type for finite difference, can be 'abs' for absolute', or 'rel' for relative.
            Default is 'abs'.

        Returns
        -------
        Dict of Dicts of Tuples of Floats

            First key:
                is the (output, input) tuple of strings;
            Second key:
                is one of ['rel error', 'abs error', 'magnitude', 'fdstep'];

            For 'rel error', 'abs error', 'magnitude' the value is: A tuple containing norms for
                forward - fd, adjoint - fd, forward - adjoint.
        
Check total derivatives for the model vs. finite difference.
Parameters

of : list of variable name strings or None
Variables whose derivatives will be computed. Default is None, which
uses the driver's objectives and constraints.
wrt : list of variable name strings or None
Variables with respect to which the derivatives will be computed.
Default is None, which uses the driver's desvars.
out_stream : file-like object
Where to send human readable output. By default it goes to stdout.
Set to None to suppress.
compact_print : bool
Set to True to just print the essentials, one line per unknown-param pair.
driver_scaling : bool
Set to True to scale derivative values by the quantities specified when the desvars and
responses were added. Default if False, which is unscaled.
abs_err_tol : float
Threshold value for absolute error.  Errors about this value will have a '*' displayed
next to them in output, making them easy to search for.

Returns

Dict of Dicts of Tuples of Floats




Check total derivatives for the model vs . finite difference . Parameters of : list of variable name strings or None Variables whose derivatives will be computed . Default is None which uses the driver ' s objectives and constraints . wrt : list of variable name strings or None Variables with respect to which the derivatives will be computed . Default is None which uses the driver ' s desvars . out_stream : file - like object Where to send human readable output . By default it goes to stdout . Set to None to suppress . compact_print : bool Set to True to just print the essentials one line per unknown - param pair . driver_scaling : bool Set to True to scale derivative values by the quantities specified when the desvars and responses were added . Default if False which is unscaled . abs_err_tol : float Threshold value for absolute error . Errors about this value will have a ' * ' displayed next to them in output making them easy to search for . Returns Dict of Dicts of Tuples of Floats
def check_totals(self, of=None, wrt=None, out_stream=_DEFAULT_OUT_STREAM, compact_print=False,
                     driver_scaling=False, abs_err_tol=1e-6, rel_err_tol=1e-6,
                     method='fd', step=None, form='forward', step_calc='abs'):
        model = self.model
        if method == 'cs' and not model._outputs._alloc_complex:
            msg = "\nTo enable complex step, specify 'force_alloc_complex=True' when calling " + \
                  "setup on the problem, e.g. 'problem.setup(force_alloc_complex=True)'"
            raise RuntimeError(msg)
        with self.model._scaled_context_all():
            total_info = _TotalJacInfo(self, of, wrt, False, return_format='flat_dict',
                                       driver_scaling=driver_scaling)
            Jcalc = total_info.compute_totals()
            if step is None:
                if method == 'cs':
                    step = DEFAULT_CS_OPTIONS['step']
                else:
                    step = DEFAULT_FD_OPTIONS['step']
            fd_args = {
                'step': step,
                'form': form,
                'step_calc': step_calc,
            }
            approx = model._owns_approx_jac
            old_jac = model._jacobian
            model.approx_totals(method=method, step=step, form=form,
                                step_calc=step_calc if method is 'fd' else None)
            total_info = _TotalJacInfo(self, of, wrt, False, return_format='flat_dict', approx=True,
                                       driver_scaling=driver_scaling)
            Jfd = total_info.compute_totals_approx(initialize=True)
            if not approx:
                model._jacobian = old_jac
                model._owns_approx_jac = False
        data = {}
        data[''] = {}
        for key, val in iteritems(Jcalc):
            data[''][key] = {}
            data[''][key]['J_fwd'] = val
            data[''][key]['J_fd'] = Jfd[key]
        fd_args['method'] = 'fd'
        if out_stream == _DEFAULT_OUT_STREAM:
            out_stream = sys.stdout
        _assemble_derivative_data(data, rel_err_tol, abs_err_tol, out_stream, compact_print,
                                  [model], {'': fd_args}, totals=True)
        return data['']
def check_totals ( self , of = None , wrt = None , out_stream = _DEFAULT_OUT_STREAM , compact_print = False , driver_scaling = False , abs_err_tol = 1e-6 , rel_err_tol = 1e-6 , method = 'fd' , step = None , form = 'forward' , step_calc = 'abs' ) : model = self . model if method == 'cs' and not model . _outputs . _alloc_complex : msg = "\nTo enable complex step, specify 'force_alloc_complex=True' when calling " + "setup on the problem, e.g. 'problem.setup(force_alloc_complex=True)'" raise RuntimeError ( msg ) with self . model . _scaled_context_all ( ) : total_info = _TotalJacInfo ( self , of , wrt , False , return_format = 'flat_dict' , driver_scaling = driver_scaling ) Jcalc = total_info . compute_totals ( ) if step is None : if method == 'cs' : step = DEFAULT_CS_OPTIONS [ 'step' ] else : step = DEFAULT_FD_OPTIONS [ 'step' ] fd_args = { 'step' : step , 'form' : form , 'step_calc' : step_calc , } approx = model . _owns_approx_jac old_jac = model . _jacobian model . approx_totals ( method = method , step = step , form = form , step_calc = step_calc if method is 'fd' else None ) total_info = _TotalJacInfo ( self , of , wrt , False , return_format = 'flat_dict' , approx = True , driver_scaling = driver_scaling ) Jfd = total_info . compute_totals_approx ( initialize = True ) if not approx : model . _jacobian = old_jac model . _owns_approx_jac = False data = { } data [ '' ] = { } for key , val in iteritems ( Jcalc ) : data [ '' ] [ key ] = { } data [ '' ] [ key ] [ 'J_fwd' ] = val data [ '' ] [ key ] [ 'J_fd' ] = Jfd [ key ] fd_args [ 'method' ] = 'fd' if out_stream == _DEFAULT_OUT_STREAM : out_stream = sys . stdout _assemble_derivative_data ( data , rel_err_tol , abs_err_tol , out_stream , compact_print , [ model ] , { '' : fd_args } , totals = True ) return data [ '' ]
Check total derivatives for the model vs. finite difference.
Check total derivatives for the model vs . finite difference .
"""
        Check total derivatives for the model vs. finite difference.

        Parameters
        ----------
        of : list of variable name strings or None
            Variables whose derivatives will be computed. Default is None, which
            uses the driver's objectives and constraints.
        wrt : list of variable name strings or None
            Variables with respect to which the derivatives will be computed.
            Default is None, which uses the driver's desvars.
        out_stream : file-like object
            Where to send human readable output. By default it goes to stdout.
            Set to None to suppress.
        compact_print : bool
            Set to True to just print the essentials, one line per unknown-param pair.
        driver_scaling : bool
            Set to True to scale derivative values by the quantities specified when the desvars and
            responses were added. Default if False, which is unscaled.
        abs_err_tol : float
            Threshold value for absolute error.  Errors about this value will have a '*' displayed
            next to them in output, making them easy to search for. Default is 1.0E-6.
        rel_err_tol : float
            Threshold value for relative error.  Errors about this value will have a '*' displayed
            next to them in output, making them easy to search for. Note at times there may be a
            significant relative error due to a minor absolute error.  Default is 1.0E-6.
        method : str
            Method, 'fd' for finite difference or 'cs' for complex step. Default is 'fd'
        step : float
            Step size for approximation. Default is None, which means 1e-6 for 'fd' and 1e-40 for
            'cs'.
        form : string
            Form for finite difference, can be 'forward', 'backward', or 'central'. Default
            'forward'.
        step_calc : string
            Step type for finite difference, can be 'abs' for absolute', or 'rel' for relative.
            Default is 'abs'.

        Returns
        -------
        Dict of Dicts of Tuples of Floats

            First key:
                is the (output, input) tuple of strings;
            Second key:
                is one of ['rel error', 'abs error', 'magnitude', 'fdstep'];

            For 'rel error', 'abs error', 'magnitude' the value is: A tuple containing norms for
                forward - fd, adjoint - fd, forward - adjoint.
        """ # TODO: Once we're tracking iteration counts, run the model if it has not been run before. # Calculate Total Derivatives # Approximate FD # reset the _owns_approx_jac flag after approximation is complete. # Assemble and Return all metrics.
self
of
wrt
out_stream
compact_print
driver_scaling
abs_err_tol
rel_err_tol
method
step
form
step_calc