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


Python DBCaseRecorder.register方法代码示例

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


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

示例1: test_close

# 需要导入模块: from openmdao.lib.casehandlers.api import DBCaseRecorder [as 别名]
# 或者: from openmdao.lib.casehandlers.api.DBCaseRecorder import register [as 别名]
    def test_close(self):
        # :memory: can be used after close.
        recorder = DBCaseRecorder()
        inps = ['str', 'unicode', 'list']
        recorder.register(self, inps, [])
        inputs = ['Normal String', u'Unicode String', ['Hello', 'world']]
        recorder.record(self, inputs, [], None, '', '')
        recorder.close()
        recorder.record(self, inputs, [], None, '', '')

        # File-based DB recorder can not be used after close.
        tmpdir = tempfile.mkdtemp()
        try:
            dfile = os.path.join(tmpdir, 'junk.db')
            recorder = DBCaseRecorder(dfile)
            recorder.register(self, inps, [])
            recorder.record(self, inputs, [], None, '', '')
            recorder.close()
            code = "recorder.record(self, inputs, [], None, '', '')"
            assert_raises(self, code, globals(), locals(), RuntimeError,
                          'Attempt to record on closed recorder')
        finally:
            try:
                shutil.rmtree(tmpdir, onerror=onerror)
            except OSError:
                logging.error("problem removing directory %s", tmpdir)
开发者ID:FashtimeDotCom,项目名称:OpenMDAO-Framework,代码行数:28,代码来源:test_dbcaserecorder.py

示例2: test_db_to_dict

# 需要导入模块: from openmdao.lib.casehandlers.api import DBCaseRecorder [as 别名]
# 或者: from openmdao.lib.casehandlers.api.DBCaseRecorder import register [as 别名]
    def test_db_to_dict(self):
        tmpdir = tempfile.mkdtemp()
        dfile = os.path.join(tmpdir, 'junk.db')
        recorder = DBCaseRecorder(dfile)

        # create some Cases where some are missing a variable
        outputs = ['comp1.z', 'comp2.z']
        inputs = ['comp1.x', 'comp1.y', 'comp1.y2']
        recorder.register(self, inputs, outputs)
        for i in range(10):
            inputs = [i, i*2, i*3]
            outputs = [i*i, float('NaN')]
            recorder.record(self, inputs, outputs, None, '', '')

        varnames = ['comp1.x', 'comp1.y', 'comp1.y2']
        varinfo = case_db_to_dict(dfile, varnames)

        self.assertEqual(len(varinfo), 3)
        # each var list should have 10 data values in it
        for lst in varinfo.values():
            self.assertEqual(len(lst), 10)

        # now use caseiter_to_dict to grab the same data
        varinfo = caseiter_to_dict(recorder.get_iterator(), varnames)
        # each var list should have 10 data values in it
        for lst in varinfo.values():
            self.assertEqual(len(lst), 10)

        try:
            shutil.rmtree(tmpdir, onerror=onerror)
        except OSError:
            logging.error("problem removing directory %s", tmpdir)
开发者ID:FashtimeDotCom,项目名称:OpenMDAO-Framework,代码行数:34,代码来源:test_dbcaserecorder.py

示例3: test_string

# 需要导入模块: from openmdao.lib.casehandlers.api import DBCaseRecorder [as 别名]
# 或者: from openmdao.lib.casehandlers.api.DBCaseRecorder import register [as 别名]
 def test_string(self):
     recorder = DBCaseRecorder()
     inputs = ['str', 'unicode', 'list']  # Check pickling.
     recorder.register(self, inputs, [])
     inputs = ['Normal String', u'Unicode String', ['Hello', 'world']]
     recorder.record(self, inputs, [], None, '', '')
     for case in recorder.get_iterator():
         self.assertEqual(case['str'], 'Normal String')
         self.assertEqual(case['unicode'], u'Unicode String')
         self.assertEqual(case['list'], ['Hello', 'world'])
开发者ID:FashtimeDotCom,项目名称:OpenMDAO-Framework,代码行数:12,代码来源:test_dbcaserecorder.py

示例4: test_pickle_conversion

# 需要导入模块: from openmdao.lib.casehandlers.api import DBCaseRecorder [as 别名]
# 或者: from openmdao.lib.casehandlers.api.DBCaseRecorder import register [as 别名]
 def test_pickle_conversion(self):
     recorder = DBCaseRecorder()
     inputs = ['comp1.x', 'comp1.y']
     outputs = ['comp1.z', 'comp2.normal']
     recorder.register(self, inputs, outputs)
     for i in range(10):
         inputs = [i, i*2.]
         outputs = [i*1.5, NormalDistribution(float(i), 0.5)]
         recorder.record(self, inputs, outputs, None, '', '')
     iterator = recorder.get_iterator()
     for i, case in enumerate(iterator):
         self.assertTrue(isinstance(case['comp2.normal'], NormalDistribution))
         self.assertEqual(case['comp2.normal'].mu, float(i))
         self.assertEqual(case['comp2.normal'].sigma, 0.5)
         self.assertTrue(isinstance(case['comp1.y'], float))
         self.assertEqual(case['comp1.y'], i*2.)
         self.assertEqual(case['comp1.z'], i*1.5)
开发者ID:FashtimeDotCom,项目名称:OpenMDAO-Framework,代码行数:19,代码来源:test_dbcaserecorder.py

示例5: test_query

# 需要导入模块: from openmdao.lib.casehandlers.api import DBCaseRecorder [as 别名]
# 或者: from openmdao.lib.casehandlers.api.DBCaseRecorder import register [as 别名]
    def test_query(self):
        recorder = DBCaseRecorder()
        inputs = ['comp1.x', 'comp1.y']
        outputs = ['comp1.z', 'comp2.normal']
        recorder.register(self, inputs, outputs)
        for i in range(10):
            inputs = [i, i*2.]
            outputs = [i*1.5, NormalDistribution(float(i), 0.5)]
            recorder.record(self, inputs, outputs, None, '', '')
        iterator = recorder.get_iterator()
        iterator.selectors = ["value>=0", "value<3"]

        count = 0
        for i, case in enumerate(iterator):
            count += 1
            for value in case.values():
                self.assertTrue(value >= 0 and value < 3)
        self.assertEqual(count, 3)
开发者ID:FashtimeDotCom,项目名称:OpenMDAO-Framework,代码行数:20,代码来源:test_dbcaserecorder.py


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