Repository navigation
Delete shared default options after context #59
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
base: main
Are you sure you want to change the base?
Changes from 9 commits
0f94d5b
90c7bbc
03e58ed
997a0a7
78b35e5
b58aed5
2940ce0
79055e5
242c815
965a564
9c9937b
6007fc4
916517d
a1e5081
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -179,6 +179,75 @@ def test_default_options(): | |
| assert options2.parameters["opt4"] == "6" | ||
|
|
||
|
|
||
| @pytest.mark.skipnopetsc4py | ||
| def test_inserted_options_deletes_default_options(): | ||
| """Check that inserted_options removes the options that the | ||
| OptionsManager receives through its default options set, and keeps | ||
| the options that the database already held.""" | ||
| from petsc4py import PETSc | ||
|
|
||
| options = PETSc.Options() | ||
| options["parent_ksp_type"] = "cg" | ||
| options["parent_0_pc_type"] = "jacobi" | ||
| opts_before = dict(options.getAll()) | ||
|
Comment on lines
+189
to
+192
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please can you test:
|
||
|
|
||
| child = petsctools.OptionsManager( | ||
| parameters={}, | ||
| options_prefix="parent_0", | ||
| default_options_set=petsctools.DefaultOptionSet("parent", [0])) | ||
| assert child.parameters == {"ksp_type": "cg", "pc_type": "jacobi"} | ||
|
|
||
| with child.inserted_options(): | ||
| pass | ||
|
|
||
| assert options.getAll() == opts_before | ||
|
|
||
|
|
||
| @pytest.mark.skipnopetsc4py | ||
| def test_inserted_options_deletes_defaults_for_multiple_prefixes(): | ||
| """Check shared defaults are removed for sequential child managers.""" | ||
| from petsc4py import PETSc | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the reasoning for having these as three separate tests? It'd be simpler just to have one test that covers all these cases.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The advantage to keeping separate tests is that one can easily tell when individual features break. But we also want to be covering the interaction between these features, so it makes sense to merge them into a single test, so I did this. |
||
|
|
||
| options = PETSc.Options() | ||
| options["parent_ksp_type"] = "cg" | ||
| default_options_set = petsctools.DefaultOptionSet("parent", [0, 1]) | ||
| children = [ | ||
| petsctools.OptionsManager( | ||
| parameters={}, | ||
| options_prefix=f"parent_{i}", | ||
| default_options_set=default_options_set, | ||
| ) | ||
| for i in (0, 1) | ||
| ] | ||
|
|
||
| for child in children: | ||
| key = child.options_prefix + "ksp_type" | ||
| with child.inserted_options(): | ||
| assert options[key] == "cg" | ||
| assert key not in options.getAll() | ||
|
|
||
|
|
||
| @pytest.mark.skipnopetsc4py | ||
| def test_inserted_options_child_option_overrides_default(): | ||
| """Check a child option overrides a shared default while inserted.""" | ||
| from petsc4py import PETSc | ||
|
|
||
| options = PETSc.Options() | ||
| options["parent_ksp_type"] = "cg" | ||
| options["parent_1_ksp_type"] = "gmres" | ||
| opts_before = dict(options.getAll()) | ||
| child = petsctools.OptionsManager( | ||
| parameters={}, | ||
| options_prefix="parent_1", | ||
| default_options_set=petsctools.DefaultOptionSet("parent", [0, 1]), | ||
| ) | ||
|
|
||
| assert child.parameters["ksp_type"] == "gmres" | ||
| with child.inserted_options(): | ||
| assert options["parent_1_ksp_type"] == "gmres" | ||
| assert options.getAll() == opts_before | ||
|
|
||
|
|
||
| @pytest.mark.skipnopetsc4py | ||
| def test_python_options_with_manager(): | ||
| petsctools.init() | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.