honegumi.core packageο
Submodulesο
honegumi.core._honegumi moduleο
This module contains Honegumiβs core functionality.
References
- class honegumi.core._honegumi.ResultsCollector[source]ο
Bases:
objectA class for collecting and summarizing results of pytest test runs.
https://stackoverflow.com/a/72278485/13697228
- reportsο
A list of test reports generated during the test run.
- Type:
List[pytest.TestReport]
- passedο
A list of test reports for tests that passed.
- Type:
List[pytest.TestReport]
- failedο
A list of test reports for tests that failed.
- Type:
List[pytest.TestReport]
- xfailedο
A list of test reports for tests that were expected to fail but passed.
- Type:
List[pytest.TestReport]
- skippedο
A list of test reports for tests that were skipped.
- Type:
List[pytest.TestReport]
Examples
>>> collector = ResultsCollector() >>> # run pytest tests >>> collector.total_duration 10.123456789
- pytest_collection_modifyitems(items: List[Item]) None[source]ο
A pytest hook for modifying collected test items.
- Parameters:
items (List[pytest.Item]) β A list of pytest.Item objects representing the collected test items.
Examples
>>> items = ... >>> collector = ResultsCollector() >>> collector.pytest_collection_modifyitems(items)
- pytest_runtest_makereport(item: Item, call: CallInfo) None[source]ο
A pytest hook for collecting test reports.
- Parameters:
item (pytest.Item) β The test item being run.
call (pytest.CallInfo) β The result of running the test item.
Examples
>>> item = ... >>> call = ... >>> collector = ResultsCollector() >>> collector.pytest_runtest_makereport(item, call)
- pytest_terminal_summary(terminalreporter: TerminalReporter, exitstatus: int) None[source]ο
A pytest hook for summarizing test results.
- Parameters:
terminalreporter (pytest.terminal.TerminalReporter) β The terminal reporter object used to report test results.
exitstatus (int) β The exit status code of the test run.
Examples
>>> terminalreporter = ... >>> exitstatus = ... >>> collector = ResultsCollector() >>> collector.pytest_terminal_summary(terminalreporter, exitstatus)
- honegumi.core._honegumi.add_model_specific_keys(option_names, opt)[source]ο
Add model-specific keys to the options dictionary (in-place).
This function adds model-specific keys to the options dictionary opt. For example, if use_custom_gen is a hidden variable, and the model is FULLYBAYESIAN, then use_custom_gen should be True.
It also sets the value of the key model_kwargs based on the value of MODEL_OPT_KEY in opt.
Examples
The following example is demonstrative, the range of cases may be expanded later.
>>> option_names = [ ... "objective", ... "model", ... "custom_gen", ... "existing_data", ... "sum_constraint", ... "order_constraint", ... "linear_constraint", ... "composition_constraint", ... "categorical", ... "custom_threshold", ... "fidelity", ... "synchrony", ... ] >>> opt = { ... "objective": "single", ... "model": "Default", ... "existing_data": False, ... "sum_constraint": False, ... "order_constraint": False, ... "linear_constraint": False, ... "composition_constraint": False, ... "categorical": False, ... "custom_threshold": False, ... "fidelity": "single", ... "synchrony": "single", ... }
>>> add_model_specific_keys(option_names, opt) { "objective": "single", "model": "Default", "existing_data": False, "sum_constraint": False, "order_constraint": False, "linear_constraint": False, "composition_constraint": False, "categorical": False, "custom_threshold": False, "fidelity": "single", "synchrony": "single", "custom_gen": False, "model_kwargs": {}, }
- honegumi.core._honegumi.gen_combs_with_keys(visible_option_names: List[str], visible_option_rows: List[dict])[source]ο
Generate a list of dictionaries, each representing a combination of options. Each dictionary uses option names as keys and the corresponding option from each combination as values.
- Parameters:
visible_option_names (list of str) β A list of option names. These will be used as the keys in the output dictionaries.
visible_option_rows (list of dict) β A list of dictionaries, each containing an βoptionsβ key associated with a list of options. The βoptionsβ from each dictionary are combined to form the output dictionaries.
- Returns:
A list of dictionaries, each representing a combination of options. Each dictionary uses option names as keys and the corresponding option from each combination as values.
- Return type:
Examples
>>> visible_option_names = ['color', 'size'] >>> visible_option_rows = [ ... {"options": ["red", "blue"]}, ... {"options": ["small", "large"]}, ... ] >>> gen_combs_with_keys(visible_option_names, visible_option_rows) [ {"color": "red", "size": "small"}, {"color": "red", "size": "large"}, {"color": "blue", "size": "small"}, {"color": "blue", "size": "large"}, ]
- honegumi.core._honegumi.generate_lookup_dict(df, option_names, key)[source]ο
Generate a lookup dictionary from a pandas DataFrame.
Examples
>>> df = pd.DataFrame( >>> { >>> "option1": ["a", "b", "c"], >>> "option2": [1, 2, 3], >>> "key": ["foo", "bar", "baz"], >>> } >>> ) >>> generate_lookup_dict(df, ['option1', 'option2'], 'key') {'a,1': 'foo', 'b,2': 'bar', 'c,3': 'baz'}
- honegumi.core._honegumi.get_rendered_template_stem(datum, option_names)[source]ο
Returns a string that represents the rendered template stem based on the given data and option names.
Filenames still have strict character limits even if longpaths enabled on Windows (https://stackoverflow.com/a/61628356/13697228), so use folder structure instead
- Parameters:
- Returns:
A string representing the rendered template stem.
- Return type:
Examples
>>> data = {'option1': 'value1', 'option2': 'value2'} >>> option_names = ['option1', 'option2'] >>> get_rendered_template_stem(data, option_names) 'option1-value1+option2-value2'
- honegumi.core._honegumi.is_incompatible(opt)[source]ο
Check if the given option dictionary contains incompatible options.
An option is considered incompatible if it cannot be used together with another option. For example, if the model is fully Bayesian, it cannot use the custom generator (use_custom_gen). Similarly, if the objective is single, it cannot use the custom threshold (use_custom_threshold).
- honegumi.core._honegumi.main(args)[source]ο
Wrapper allowing
fib()to be called with string arguments in a CLI fashionInstead of returning the value from
fib(), it prints the result to thestdoutin a nicely formatted message.- Parameters:
args (List[str]) β command line parameters as list of strings (for example
["--verbose", "42"]).
- honegumi.core._honegumi.parse_args(args)[source]ο
Parse command line parameters
- Parameters:
args (List[str]) β command line parameters as list of strings (for example
["--help"]).- Returns:
command line parameters namespace
- Return type:
- honegumi.core._honegumi.prep_datum_for_render(option_names, datum)[source]ο
Checks the compatibility of the given options and updates the datum dictionary with the rendered template stem and compatibility status.
- Parameters:
- Return type:
None
Examples
>>> check_compatibility_and_update(['option1', 'option2'], {'option1': 'value1', 'option2': 'value2'}) # noqa: E501 OUTPUT
Notes
This function will always set the βdummyβ key in the βdatumβ dictionary to False.
- honegumi.core._honegumi.run()[source]ο
Calls
main()passing the CLI arguments extracted fromsys.argvThis function can be used as entry point to create console scripts with setuptools.
- honegumi.core._honegumi.setup_logging(loglevel)[source]ο
Setup basic logging
- Parameters:
loglevel (int) β minimum loglevel for emitting messages
- honegumi.core._honegumi.unpack_rendered_template_stem(rendered_template_stem)[source]ο
This function takes a rendered template stem as input and returns a dictionary of options and their values.
- Parameters:
rendered_template_stem (str) β The rendered template stem to be unpacked.
- Returns:
A dictionary containing the options and their values.
- Return type:
Examples
>>> unpack_rendered_template_stem("option1-value1+option2-value2+option3-value3") {'option1': 'value1', 'option2': 'value2', 'option3': 'value3'}