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


Python ResourceAllocationManager.validate_resources方法代码示例

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


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

示例1: test_resources

# 需要导入模块: from openmdao.main.resource import ResourceAllocationManager [as 别名]
# 或者: from openmdao.main.resource.ResourceAllocationManager import validate_resources [as 别名]
    def test_resources(self):
        logging.debug('')
        logging.debug('test_resources')

        result = RAM.allocate({'localhost': False})
        self.assertEqual(result, (None, None))

        result = RAM.allocate({'exclude': [platform.node()]})
        self.assertEqual(result, (None, None))

        result = RAM.allocate({'min_cpus': 1000000})
        self.assertEqual(result, (None, None))

        result = RAM.allocate({'orphan_modules': ['xyzzy']})
        self.assertEqual(result, (None, None))

        result = RAM.allocate({'python_version': '2.999'})
        self.assertEqual(result, (None, None))

        start_time = datetime.datetime(2012, 2, 8, 16, 42)
        resource_limits = {}
        for i, limit in enumerate(RESOURCE_LIMITS):
            resource_limits[limit] = i
        RAM.validate_resources(dict(remote_command='echo',
                                    args=['hello', 'world'],
                                    submit_as_hold=True,
                                    rerunnable=True,
                                    job_environment={'ENV_VAR': 'env_value'},
                                    working_directory='.',
                                    job_category='MPI',
                                    min_cpus=256,
                                    max_cpus=512,
                                    email=['[email protected]', '[email protected]'],
                                    email_on_started=True,
                                    email_on_terminated=True,
                                    job_name='TestJob',
                                    input_path='echo.in',
                                    output_path='echo.out',
                                    error_path='echo.err',
                                    join_files=True,
                                    reservation_id='res-1234',
                                    queue_name='debug_q',
                                    priority=42,
                                    start_time=start_time,
                                    resource_limits=resource_limits,
                                    accounting_id='CFD-R-US',
                                    native_specification=('-ac', 'name=value')))

        code = "RAM.validate_resources(dict(max_cpus=2))"
        assert_raises(self, code, globals(), locals(), KeyError,
                      "'min_cpus required if max_cpus specified'")

        code = "RAM.validate_resources(dict(min_cpus=2, max_cpus=1))"
        assert_raises(self, code, globals(), locals(), ValueError,
                      "max_cpus 1 < min_cpus 2")

        # Must be positive.
        code = "RAM.validate_resources(dict(min_cpus=-2))"
        assert_raises(self, code, globals(), locals(), ValueError,
                      "Invalid resource value for 'min_cpus': -2")

        # Must be sequence.
        code = "RAM.validate_resources(dict(args='hello'))"
        assert_raises(self, code, globals(), locals(), ValueError,
                      "Invalid resource value for 'args': 'hello'")

        # Must be strings.
        code = "RAM.validate_resources(dict(args=['hello', 42]))"
        assert_raises(self, code, globals(), locals(), ValueError,
                      "Invalid resource value for 'args': ['hello', 42]")

        # Must be registered allocator.
        code = "RAM.validate_resources(dict(allocator='NoSuchAllocator'))"
        assert_raises(self, code, globals(), locals(), ValueError,
                      "Invalid resource value for 'allocator': 'NoSuchAllocator'")

        # Must be dict.
        code = "RAM.validate_resources(dict(job_environment='hello'))"
        assert_raises(self, code, globals(), locals(), ValueError,
                      "Invalid resource value for 'job_environment': 'hello'")

        # Key must be string.
        env = {}
        env[3] = 'hello'
        code = "RAM.validate_resources(dict(job_environment=env))"
        assert_raises(self, code, globals(), locals(), ValueError,
                      "Invalid resource value for 'job_environment':"
                      " {3: 'hello'}")

        # Key must not have whitespace.
        env = {}
        env['hello there'] = 'world'
        code = "RAM.validate_resources(dict(job_environment=env))"
        assert_raises(self, code, globals(), locals(), ValueError,
                      "Invalid resource value for 'job_environment':"
                      " {'hello there': 'world'}")

        # Value must be string.
        env = {}
        env['hello'] = 3
#.........这里部分代码省略.........
开发者ID:FashtimeDotCom,项目名称:OpenMDAO-Framework,代码行数:103,代码来源:test_resource.py


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