当前位置: 首页>>代码示例>>Python>>正文


Python RecordingManager.record方法代码示例

本文整理汇总了Python中openmdao.recorders.recording_manager.RecordingManager.record方法的典型用法代码示例。如果您正苦于以下问题:Python RecordingManager.record方法的具体用法?Python RecordingManager.record怎么用?Python RecordingManager.record使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在openmdao.recorders.recording_manager.RecordingManager的用法示例。


在下文中一共展示了RecordingManager.record方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Driver

# 需要导入模块: from openmdao.recorders.recording_manager import RecordingManager [as 别名]
# 或者: from openmdao.recorders.recording_manager.RecordingManager import record [as 别名]
class Driver(object):
    """ Base class for drivers in OpenMDAO. Drivers can only be placed in a
    Problem, and every problem has a Driver. Driver is the simplest driver that
    runs (solves using solve_nonlinear) a problem once.
    """

    def __init__(self):
        super(Driver, self).__init__()
        self.recorders = RecordingManager()

        # What this driver supports
        self.supports = OptionsDictionary(read_only=True)
        self.supports.add_option("inequality_constraints", True)
        self.supports.add_option("equality_constraints", True)
        self.supports.add_option("linear_constraints", True)
        self.supports.add_option("multiple_objectives", True)
        self.supports.add_option("two_sided_constraints", True)
        self.supports.add_option("integer_design_vars", True)

        # This driver's options
        self.options = OptionsDictionary()

        self._desvars = OrderedDict()
        self._objs = OrderedDict()
        self._cons = OrderedDict()

        self._voi_sets = []
        self._vars_to_record = None

        # We take root during setup
        self.root = None

        self.iter_count = 0

    def _setup(self, root):
        """ Updates metadata for params, constraints and objectives, and
        check for errors. Also determines all variables that need to be
        gathered for case recording.
        """
        self.root = root

        desvars = OrderedDict()
        objs = OrderedDict()
        cons = OrderedDict()

        item_tups = [
            ("Parameter", self._desvars, desvars),
            ("Objective", self._objs, objs),
            ("Constraint", self._cons, cons),
        ]

        for item_name, item, newitem in item_tups:
            for name, meta in iteritems(item):
                rootmeta = root.unknowns.metadata(name)

                if MPI and "src_indices" in rootmeta:  # pragma: no cover
                    raise ValueError(
                        "'%s' is a distributed variable and may "
                        "not be used as a design var, objective, "
                        "or constraint." % name
                    )

                # Check validity of variable
                if name not in root.unknowns:
                    msg = "{} '{}' not found in unknowns."
                    msg = msg.format(item_name, name)
                    raise ValueError(msg)

                # Size is useful metadata to save
                if "indices" in meta:
                    meta["size"] = len(meta["indices"])
                else:
                    meta["size"] = rootmeta["size"]

                newitem[name] = meta

        self._desvars = desvars
        self._objs = objs
        self._cons = cons

    def _map_voi_indices(self):
        poi_indices = {}
        qoi_indices = {}
        for name, meta in chain(iteritems(self._cons), iteritems(self._objs)):
            # set indices of interest
            if "indices" in meta:
                qoi_indices[name] = meta["indices"]

        for name, meta in iteritems(self._desvars):
            # set indices of interest
            if "indices" in meta:
                poi_indices[name] = meta["indices"]

        return poi_indices, qoi_indices

    def _of_interest(self, voi_list):
        """Return a list of tuples, with the given voi_list organized
        into tuples based on the previously defined grouping of VOIs.
        """
        vois = []
#.........这里部分代码省略.........
开发者ID:briantomko,项目名称:OpenMDAO,代码行数:103,代码来源:driver.py


注:本文中的openmdao.recorders.recording_manager.RecordingManager.record方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。