def test_add_directive(self, available_directives_list): directives = _Directives(available_directives_list[:-1]) directives._add_directive(_PROCESSOR_FRACTION) assert directives[_PROCESSOR_FRACTION._name] == _PROCESSOR_FRACTION._default with pytest.raises(TypeError): directives._add_directive("Test") with pytest.raises(ValueError): directives._add_directive(_PROCESSOR_FRACTION)
def test_update_directive_parallel(self, available_directives_list, non_default_directive_values): directives1 = _Directives(available_directives_list) directives2 = _Directives(available_directives_list) valid_values_0 = non_default_directive_values[0] valid_values_1 = non_default_directive_values[1] expected_values = { "np": 104, "ngpu": 11, "nranks": 5, "omp_num_threads": 30, "executable": "Non Default Path", "walltime": 64.0, "memory": 48, "processor_fraction": 0.5, } directives1.update(valid_values_0) directives2.update(valid_values_1) directives1.update(directives2, aggregate=True, parallel=True) for dirs in directives1: assert directives1[dirs] == expected_values[dirs]
def test_update_directive_parallel(self, available_directives_list, non_default_directive_values): directives1 = _Directives(available_directives_list) directives2 = _Directives(available_directives_list) valid_values_0 = non_default_directive_values[0] valid_values_1 = non_default_directive_values[1] expected_values = { 'np': 104, 'ngpu': 11, 'nranks': 5, 'omp_num_threads': 30, 'executable': 'Non Default Path', 'walltime': 64.0, 'memory': 48, 'processor_fraction': 0.5 } directives1.update(valid_values_0) directives2.update(valid_values_1) directives1.update(directives2, aggregate=True, parallel=True) for dirs in directives1: assert directives1[dirs] == expected_values[dirs]
def test_evaluate_directive_valid_job(self, available_directives_list, non_default_directive_values): _tmp_dir = TemporaryDirectory(prefix="flow-directives_") FlowProject.init_project(name="DirectivesTest", root=_tmp_dir.name) project = FlowProject.get_project(root=_tmp_dir.name) for i in range(5): project.open_job(dict(i=i)).init() valid_values = non_default_directive_values[0] valid_values["processor_fraction"] = lambda job: round( job.sp.i / 10, 1) for job in project: directives = _Directives(available_directives_list) directives.update( {"processor_fraction": lambda job: round(job.sp.i / 10, 1)}) directives.evaluate((job, )) assert directives["processor_fraction"] == round(job.sp.i / 10, 1)
def directives(available_directives_list): return _Directives(available_directives_list)