本文整理汇总了Python中openmdao.recorders.recording_manager.RecordingManager.record_derivatives方法的典型用法代码示例。如果您正苦于以下问题:Python RecordingManager.record_derivatives方法的具体用法?Python RecordingManager.record_derivatives怎么用?Python RecordingManager.record_derivatives使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openmdao.recorders.recording_manager.RecordingManager
的用法示例。
在下文中一共展示了RecordingManager.record_derivatives方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Driver
# 需要导入模块: from openmdao.recorders.recording_manager import RecordingManager [as 别名]
# 或者: from openmdao.recorders.recording_manager.RecordingManager import record_derivatives [as 别名]
#.........这里部分代码省略.........
Args
----
problem : `Problem`
Our parent `Problem`.
"""
self.run_once(problem)
def run_once(self, problem):
""" Runs root's solve_nonlinear one time
Args
----
problem : `Problem`
Our parent `Problem`.
"""
system = problem.root
# Metadata Setup
self.iter_count += 1
metadata = self.metadata = create_local_meta(None, 'Driver')
system.ln_solver.local_meta = metadata
update_local_meta(metadata, (self.iter_count,))
# Solve the system once and record results.
with system._dircontext:
system.solve_nonlinear(metadata=metadata)
self.recorders.record_iteration(system, metadata)
def calc_gradient(self, indep_list, unknown_list, mode='auto',
return_format='array', sparsity=None):
""" Returns the scaled gradient for the system that is contained in
self.root, scaled by all scalers that were specified when the desvars
and constraints were added.
Args
----
indep_list : list of strings
List of independent variable names that derivatives are to
be calculated with respect to. All params must have a IndepVarComp.
unknown_list : list of strings
List of output or state names that derivatives are to
be calculated for. All must be valid unknowns in OpenMDAO.
mode : string, optional
Deriviative direction, can be 'fwd', 'rev', 'fd', or 'auto'.
Default is 'auto', which uses mode specified on the linear solver
in root.
return_format : string, optional
Format for the derivatives, can be 'array' or 'dict'.
sparsity : dict, optional
Dictionary that gives the relevant design variables for each
constraint. This option is only supported in the `dict` return
format.
Returns
-------
ndarray or dict
Jacobian of unknowns with respect to params.
"""
J = self._problem.calc_gradient(indep_list, unknown_list, mode=mode,
return_format=return_format,
dv_scale=self.dv_conversions,
cn_scale=self.fn_conversions,
sparsity=sparsity)
self.recorders.record_derivatives(J, self.metadata)
return J
def generate_docstring(self):
"""
Generates a numpy-style docstring for a user-created Driver class.
Returns
-------
docstring : str
string that contains a basic numpy docstring.
"""
#start the docstring off
docstring = ' \"\"\"\n'
#Put options into docstring
firstTime = 1
for key, value in sorted(vars(self).items()):
if type(value)==OptionsDictionary:
if key == "supports":
continue
if firstTime: #start of Options docstring
docstring += '\n Options\n -------\n'
firstTime = 0
docstring += value._generate_docstring(key)
#finish up docstring
docstring += '\n \"\"\"\n'
return docstring