Skip to content

Commit

Permalink
Merge pull request #435 from NREL/pp/gen_mw_default
Browse files Browse the repository at this point in the history
Generation `max_workers` defaults to `None` if omitted from config file
  • Loading branch information
ppinchuk authored Nov 22, 2023
2 parents 2763063 + ec710b6 commit ed82907
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
1 change: 1 addition & 0 deletions reV/generation/cli_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def _preprocessor(config, job_name, log_directory, verbose,
Updated config file.
"""
init_cli_logging(job_name, log_directory, verbose)
config.get("execution_control", {}).setdefault("max_workers")
analysis_years = format_analysis_years(analysis_years)

config["resource_file"] = _parse_res_files(config["resource_file"],
Expand Down
5 changes: 4 additions & 1 deletion reV/generation/generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,10 @@ def run(self, out_fpath=None, max_workers=1, timeout=1800,
module name and/or resource data year will get added to the
output file name. By default, ``None``.
max_workers : int, optional
Number of local workers to run on. By default, ``1``.
Number of local workers to run on. If ``None``, or if
running from the command line and omitting this argument
from your config file completely, this input is set to
``os.cpu_count()``. Otherwise, the default is ``1``.
timeout : int, optional
Number of seconds to wait for parallel run iteration to
complete before returning zeros. By default, ``1800``
Expand Down
43 changes: 43 additions & 0 deletions tests/test_gen_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,49 @@ def test_sam_config(tech):
gen_dict.out['cf_profile']), msg


@pytest.mark.parametrize('expected_log_message',
["Running serial generation for",
"Running parallel generation for"])
def test_gen_mw_config_input(runner, clear_loggers, expected_log_message):
"""Test max_workers input from gen config"""
with tempfile.TemporaryDirectory() as td:

run_dir = os.path.join(td, 'generation')
os.mkdir(run_dir)
project_points = os.path.join(TESTDATADIR, 'config', '..',
'config', "wtk_pp_2012_10.csv")
resource_file = os.path.join(TESTDATADIR, 'wtk/ri_100_wtk_{}.h5')
sam_files = {"wind0":
os.path.join(TESTDATADIR,
"SAM/wind_gen_standard_losses_0.json")}

config = os.path.join(TESTDATADIR, 'config', 'local_wind.json')
config = safe_json_load(config)
if "parallel" in expected_log_message:
config["execution_control"].pop("max_workers")
else:
config["execution_control"]["max_workers"] = 1

config['project_points'] = project_points
config['resource_file'] = resource_file
config['sam_files'] = sam_files
config['log_directory'] = run_dir

config_path = os.path.join(run_dir, 'config.json')
with open(config_path, 'w') as f:
json.dump(config, f)

result = runner.invoke(main, ['generation', '-c', config_path])
msg = ('Failed with error {}'
.format(traceback.print_exception(*result.exc_info)))
assert result.exit_code == 0, msg

log_file = os.path.join(run_dir, 'generation_generation.log')
with open(log_file, "r") as fh:
assert expected_log_message in fh.read()
clear_loggers()


def execute_pytest(capture='all', flags='-rapP'):
"""Execute module as pytest with detailed summary report.
Expand Down

0 comments on commit ed82907

Please sign in to comment.