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


Python DBCaseRecorder.record方法代码示例

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


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

示例1: test_db_to_dict

# 需要导入模块: from openmdao.lib.casehandlers.api import DBCaseRecorder [as 别名]
# 或者: from openmdao.lib.casehandlers.api.DBCaseRecorder import record [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

示例2: test_string

# 需要导入模块: from openmdao.lib.casehandlers.api import DBCaseRecorder [as 别名]
# 或者: from openmdao.lib.casehandlers.api.DBCaseRecorder import record [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

示例3: test_string

# 需要导入模块: from openmdao.lib.casehandlers.api import DBCaseRecorder [as 别名]
# 或者: from openmdao.lib.casehandlers.api.DBCaseRecorder import record [as 别名]
 def test_string(self):
     recorder = DBCaseRecorder()
     case = Case(inputs=[('str', 'Normal String'),
                         ('unicode', u'Unicode String'),
                         ('list', ['Hello', 'world'])])  # Check pickling.
     recorder.record(case)
     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:akhi28,项目名称:OpenMDAO-Framework,代码行数:12,代码来源:test_dbcaserecorder.py

示例4: test_string

# 需要导入模块: from openmdao.lib.casehandlers.api import DBCaseRecorder [as 别名]
# 或者: from openmdao.lib.casehandlers.api.DBCaseRecorder import record [as 别名]
 def test_string(self):
     recorder = DBCaseRecorder()
     case = Case(
         inputs=[("str", "Normal String"), ("unicode", u"Unicode String"), ("list", ["Hello", "world"])]
     )  # Check pickling.
     recorder.record(case)
     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:naylor-b,项目名称:OpenMDAO-Framework,代码行数:12,代码来源:test_dbcaserecorder.py

示例5: test_pickle_conversion

# 需要导入模块: from openmdao.lib.casehandlers.api import DBCaseRecorder [as 别名]
# 或者: from openmdao.lib.casehandlers.api.DBCaseRecorder import record [as 别名]
 def test_pickle_conversion(self):
     recorder = DBCaseRecorder()
     for i in range(10):
         inputs = [('comp1.x', i), ('comp1.y', i*2.)]
         outputs = [('comp1.z', i*1.5), ('comp2.normal', NormalDistribution(float(i),0.5))]
         recorder.record(Case(inputs=inputs, outputs=outputs, label='case%s'%i))
     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:akhi28,项目名称:OpenMDAO-Framework,代码行数:16,代码来源:test_dbcaserecorder.py

示例6: test_query

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

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

示例7: test_pickle_conversion

# 需要导入模块: from openmdao.lib.casehandlers.api import DBCaseRecorder [as 别名]
# 或者: from openmdao.lib.casehandlers.api.DBCaseRecorder import record [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

示例8: test_query

# 需要导入模块: from openmdao.lib.casehandlers.api import DBCaseRecorder [as 别名]
# 或者: from openmdao.lib.casehandlers.api.DBCaseRecorder import record [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

示例9: test_close

# 需要导入模块: from openmdao.lib.casehandlers.api import DBCaseRecorder [as 别名]
# 或者: from openmdao.lib.casehandlers.api.DBCaseRecorder import record [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

示例10: test_close

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

        # 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.record(case)
            recorder.close()
            assert_raises(self, 'recorder.record(case)',
                          globals(), locals(), RuntimeError,
                          'Attempt to record on closed recorder')
        finally:
            try:
                shutil.rmtree(tmpdir)
            except OSError:
                logging.error("problem removing directory %s" % tmpdir)
开发者ID:akhi28,项目名称:OpenMDAO-Framework,代码行数:27,代码来源:test_dbcaserecorder.py

示例11: test_close

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

        # 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.record(case)
            recorder.close()
            assert_raises(
                self, "recorder.record(case)", globals(), locals(), RuntimeError, "Attempt to record on closed recorder"
            )
        finally:
            try:
                shutil.rmtree(tmpdir)
            except OSError:
                logging.error("problem removing directory %s" % tmpdir)
开发者ID:naylor-b,项目名称:OpenMDAO-Framework,代码行数:27,代码来源:test_dbcaserecorder.py

示例12: test_db_to_dict

# 需要导入模块: from openmdao.lib.casehandlers.api import DBCaseRecorder [as 别名]
# 或者: from openmdao.lib.casehandlers.api.DBCaseRecorder import record [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']
        cases = []
        for i in range(10):
            if i>1:
                msg = ''
            else:
                msg = 'an error occurred'
            if i<5:
                inputs = [('comp1.x', i), ('comp1.y', i*2), ('comp1.y2', i*3)]
            else:
                inputs = [('comp1.x', i), ('comp1.y', i*2)]
            recorder.record(Case(inputs=inputs, outputs=outputs, msg=msg))

        varnames = ['comp1.x','comp1.y','comp1.y2']
        varinfo = case_db_to_dict(dfile, varnames)
        
        self.assertEqual(len(varinfo), 3)
        # each var list should have 3 data values in it (5 with the required variables minus
        # 2 with errors
        for name,lst in varinfo.items():
            self.assertEqual(len(lst), 3)
            
        # now use caseiter_to_dict to grab the same data
        varinfo = caseiter_to_dict(recorder.get_iterator(), varnames)
        # each var list should have 3 data values in it (5 with the required variables minus
        # 2 with errors
        for name,lst in varinfo.items():
            self.assertEqual(len(lst), 3)
        
        try:
            shutil.rmtree(tmpdir)
        except OSError:
            logging.error("problem removing directory %s" % tmpdir)
开发者ID:akhi28,项目名称:OpenMDAO-Framework,代码行数:41,代码来源:test_dbcaserecorder.py


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