-
Notifications
You must be signed in to change notification settings - Fork 37
Minor cleanup in datatypes #438
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7e7b5a2
Made communicator class attribute of `mesh`
brownbaerchen f242f1f
Moved to communicator as class attribute of `Tensor` as well
brownbaerchen b6699ad
Forgot to add file to commit.
brownbaerchen b034645
Fixes
brownbaerchen 4039cbb
Fixed environment
brownbaerchen 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 hidden or 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 |
|---|---|---|
|
|
@@ -11,3 +11,5 @@ dependencies: | |
| - pytorch | ||
| - matplotlib>=3.0 | ||
| - dill | ||
| - mpich | ||
| - mpi4py>=3.0.0 | ||
This file contains hidden or 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 hidden or 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 hidden or 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,107 @@ | ||
| import pytest | ||
|
|
||
|
|
||
| def get_dtype(name): | ||
| if name == 'Tensor': | ||
| from pySDC.playgrounds.ML_initial_guess.tensor import Tensor as dtype_cls | ||
| elif name in ['mesh', 'imex_mesh']: | ||
| import pySDC.implementations.datatype_classes.mesh as mesh | ||
|
|
||
| dtype_cls = eval(f'mesh.{name}') | ||
| else: | ||
| raise NotImplementedError(f'Don\'t know a dtype of name {name!r}!') | ||
|
|
||
| return dtype_cls | ||
|
|
||
|
|
||
| def single_test(name, useMPI=False): | ||
| """ | ||
| This test checks that the communicator and datatype are maintained when generating new instances. | ||
| Also, it makes sure that you can supply different communicators. | ||
| """ | ||
| import numpy as np | ||
|
|
||
| dtype_cls = get_dtype(name) | ||
|
|
||
| shape = (5,) | ||
| comm = None | ||
| dtype = np.dtype('f') | ||
|
|
||
| if useMPI: | ||
| from mpi4py import MPI | ||
|
|
||
| comm_wd = MPI.COMM_WORLD | ||
| comm = comm_wd.Split(comm_wd.rank < comm_wd.size - 1) | ||
|
|
||
| expected_rank = comm_wd.rank % (comm_wd.size - 1) | ||
|
|
||
| init = (shape, comm, dtype) | ||
|
|
||
| a = dtype_cls(init, val=1.0) | ||
| b = dtype_cls(init, val=99.0) | ||
| c = dtype_cls(a) | ||
| d = a + b | ||
|
|
||
| for me in [a, b, c, d]: | ||
| assert type(me) == dtype_cls | ||
| assert me.comm == comm | ||
|
|
||
| if hasattr(me, 'shape') and not hasattr(me, 'components'): | ||
| assert me.shape == shape | ||
|
|
||
| if useMPI: | ||
| assert comm.rank == expected_rank | ||
| assert comm.size < comm_wd.size | ||
|
|
||
|
|
||
| def launch_test(name, useMPI, num_procs=1): | ||
| if useMPI: | ||
| import os | ||
| import subprocess | ||
|
|
||
| # Set python path once | ||
| my_env = os.environ.copy() | ||
| my_env['PYTHONPATH'] = '../../..:.' | ||
| my_env['COVERAGE_PROCESS_START'] = 'pyproject.toml' | ||
|
|
||
| cmd = f"mpirun -np {num_procs} python {__file__} --name={name} --useMPI=True" | ||
|
|
||
| p = subprocess.Popen(cmd.split(), env=my_env, cwd=".") | ||
|
|
||
| p.wait() | ||
| assert p.returncode == 0, 'ERROR: did not get return code 0, got %s with %2i processes' % ( | ||
| p.returncode, | ||
| num_procs, | ||
| ) | ||
| else: | ||
| single_test(name, False) | ||
|
|
||
|
|
||
| @pytest.mark.pytorch | ||
| @pytest.mark.parametrize('useMPI', [True, False]) | ||
| def test_PyTorch_dtype(useMPI): | ||
| launch_test('Tensor', useMPI=useMPI, num_procs=4) | ||
|
|
||
|
|
||
| @pytest.mark.mpi4py | ||
| @pytest.mark.parametrize('name', ['mesh', 'imex_mesh']) | ||
| def test_mesh_dtypes_MPI(name): | ||
| launch_test(name, useMPI=True, num_procs=4) | ||
|
|
||
|
|
||
| @pytest.mark.base | ||
| @pytest.mark.parametrize('name', ['mesh', 'imex_mesh']) | ||
| def test_mesh_dtypes(name): | ||
| launch_test(name, useMPI=False) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| str_to_bool = lambda me: False if me == 'False' else True | ||
| import argparse | ||
|
|
||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument('--name', type=str, help='Name of the datatype') | ||
| parser.add_argument('--useMPI', type=str_to_bool, help='Toggle for MPI', choices=[True, False]) | ||
| args = parser.parse_args() | ||
|
|
||
| single_test(**vars(args)) |
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 not
_commhere?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.
I removed the getter function. I honestly don't see the point. But I can add it back in if you want.
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.
I "get" it. Let's keep it explicit, then.
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.
We can still have private "explicit" attributes denoted by the leading
_, but no getter and setter (which are indeed superfluous)