-
Notifications
You must be signed in to change notification settings - Fork 33
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
Easier generation of description dictionaries #367
Merged
pancetta
merged 3 commits into
Parallel-in-Time:master
from
brownbaerchen:description_helper
Oct 26, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
def generate_description(problem_class, **kwargs): | ||
""" | ||
Generate a description object that you can use to run pySDC based on a problem class and various input. | ||
This function does not set any additional defaults, but distributes the values to where they belong. | ||
|
||
Args: | ||
problem_class (pySDC.Problem): A problem class | ||
|
||
Returns: | ||
dict: A description object for running pySDC | ||
""" | ||
from pySDC.core.Level import _Pars as level_params | ||
from pySDC.core.Step import _Pars as step_params | ||
|
||
description = { | ||
'level_params': {}, | ||
'problem_params': {}, | ||
'sweeper_params': {}, | ||
'problem_class': problem_class, | ||
'step_params': {}, | ||
'sweeper_class': kwargs.get('sweeper_class', problem_class.get_default_sweeper_class()), | ||
'convergence_controllers': {}, | ||
} | ||
|
||
problem_keys = problem_class.__init__.__code__.co_varnames | ||
level_keys = level_params({}).__dict__.keys() | ||
sweeper_keys = description['sweeper_class']({'num_nodes': 1, 'quad_type': 'RADAU-RIGHT'}).params.__dict__.keys() | ||
step_keys = step_params({}).__dict__.keys() | ||
|
||
# TODO: add convergence controllers | ||
for key, val in kwargs.items(): | ||
if key in problem_keys: | ||
description['problem_params'][key] = val | ||
elif key in level_keys: | ||
description['level_params'][key] = val | ||
elif key in sweeper_keys: | ||
description['sweeper_params'][key] = val | ||
elif key in step_keys: | ||
description['step_params'][key] = val | ||
elif key == 'sweeper_class': | ||
pass | ||
else: | ||
raise ValueError(f'Don\'t know what parameter \"{key}\" is for!') | ||
|
||
return description |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import pytest | ||
|
||
|
||
@pytest.mark.base | ||
def test_setup_helper(): | ||
from pySDC.helpers.setup_helper import generate_description | ||
from pySDC.implementations.problem_classes.AdvectionEquation_ND_FD import advectionNd | ||
from pySDC.implementations.sweeper_classes.generic_implicit import generic_implicit | ||
|
||
# build classic description | ||
# initialize level parameters | ||
level_params = {} | ||
level_params['dt'] = 0.05 | ||
|
||
# initialize sweeper parameters | ||
sweeper_params = {} | ||
sweeper_params['quad_type'] = 'RADAU-RIGHT' | ||
sweeper_params['num_nodes'] = 3 | ||
sweeper_params['QI'] = 'IE' | ||
|
||
problem_params = {'freq': 2, 'nvars': 2**9, 'c': 1.0, 'stencil_type': 'center', 'order': 4, 'bc': 'periodic'} | ||
|
||
# initialize step parameters | ||
step_params = {} | ||
step_params['maxiter'] = 5 | ||
|
||
description = {} | ||
description['problem_class'] = advectionNd | ||
description['problem_params'] = problem_params | ||
description['sweeper_class'] = generic_implicit | ||
description['sweeper_params'] = sweeper_params | ||
description['level_params'] = level_params | ||
description['step_params'] = step_params | ||
description['convergence_controllers'] = {} | ||
|
||
easy_description = generate_description( | ||
problem_class=advectionNd, **problem_params, **level_params, **sweeper_params, **step_params | ||
) | ||
|
||
assert ( | ||
easy_description == description | ||
), 'The generate description function did not reproduce the desired description' | ||
|
||
easy_description = generate_description( | ||
problem_class=advectionNd, | ||
sweeper_class=generic_implicit, | ||
**problem_params, | ||
**level_params, | ||
**sweeper_params, | ||
**step_params | ||
) | ||
|
||
assert ( | ||
easy_description == description | ||
), 'The generate description function did not reproduce the desired description when supplying a sweeper class' | ||
|
||
|
||
if __name__ == '__main__': | ||
test_setup_helper() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is that the default sweeper class for this problem type? Could also be IMEX?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, but I guess the IMEX as standard should come with a bigger rework of pySDC, right ?