Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generation max_workers defaults to None if omitted from config file #435

Merged
merged 3 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading