-
Notifications
You must be signed in to change notification settings - Fork 26
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
Basesolver init function now accepts a comm #30
Changes from 5 commits
da32442
2f50006
e86777d
b6d0afc
d239ec7
58cb778
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 |
---|---|---|
|
@@ -27,7 +27,15 @@ class AeroSolver(BaseSolver): | |
""" | ||
|
||
def __init__( | ||
self, name, category={}, def_options={}, informs={}, options={}, immutableOptions=set(), deprecatedOptions={} | ||
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. I think changing the order will break pyFriction so we should change that as well. 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. Yeah I will submit PR for the remaining repos that use baseclasses |
||
self, | ||
name, | ||
category, | ||
defaultOptions={}, | ||
options={}, | ||
immutableOptions=set(), | ||
deprecatedOptions={}, | ||
comm=None, | ||
informs={}, | ||
): | ||
|
||
""" | ||
|
@@ -37,10 +45,12 @@ def __init__( | |
super().__init__( | ||
name, | ||
category=category, | ||
def_options=def_options, | ||
defaultOptions=defaultOptions, | ||
options=options, | ||
immutableOptions=immutableOptions, | ||
deprecatedOptions=deprecatedOptions, | ||
comm=comm, | ||
informs=informs, | ||
) | ||
self.families = CaseInsensitiveDict() | ||
self._updateGeomInfo = False | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,20 @@ | ||
try: | ||
from mpi4py import MPI | ||
except ImportError: | ||
MPI = None | ||
|
||
import unittest | ||
from baseclasses import BaseSolver | ||
from baseclasses.utils import Error | ||
|
||
|
||
class SOLVER(BaseSolver): | ||
def __init__(self, name, options=None, *args, **kwargs): | ||
def __init__(self, name, options={}, comm=None, *args, **kwargs): | ||
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. I don't believe 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. Ok, will remove |
||
|
||
"""Create an artificial class for testing""" | ||
|
||
category = "Solver for testing BaseSolver" | ||
def_opts = { | ||
defaultOptions = { | ||
"boolOption": [bool, True], | ||
"floatOption": [float, 10.0], | ||
"intOption": [int, [1, 2, 3]], | ||
|
@@ -22,9 +27,22 @@ def __init__(self, name, options=None, *args, **kwargs): | |
"oldOption": "Use boolOption instead.", | ||
} | ||
|
||
informs = { | ||
-1: "Failure -1", | ||
0: "Success", | ||
1: "Failure 1", | ||
} | ||
|
||
# Initialize the inherited BaseSolver | ||
super().__init__( | ||
name, category, def_opts, options, immutableOptions=immutableOptions, deprecatedOptions=deprecatedOptions | ||
name, | ||
category, | ||
defaultOptions=defaultOptions, | ||
options=options, | ||
immutableOptions=immutableOptions, | ||
deprecatedOptions=deprecatedOptions, | ||
comm=comm, | ||
informs=informs, | ||
) | ||
|
||
|
||
|
@@ -85,3 +103,27 @@ def test_options(self): | |
solver.setOption("strOPTION", "str2") # test immutableOptions | ||
with self.assertRaises(Error): | ||
solver.setOption("oldoption", 4) # test deprecatedOptions | ||
|
||
|
||
class TestComm(unittest.TestCase): | ||
|
||
N_PROCS = 2 | ||
|
||
@unittest.skipIf(MPI is None, "mpi4py not imported") | ||
def test_comm_with_mpi(self): | ||
# initialize solver | ||
solver = SOLVER("testComm", comm=MPI.COMM_WORLD) | ||
self.assertFalse(solver.comm is None) | ||
solver.printCurrentOptions() | ||
|
||
def test_comm_without_mpi(self): | ||
# initialize solver | ||
solver = SOLVER("testComm", comm=None) | ||
self.assertTrue(solver.comm is None) | ||
solver.printCurrentOptions() | ||
|
||
|
||
class TestInforms(unittest.TestCase): | ||
def test_informs(self): | ||
solver = SOLVER("testInforms") | ||
self.assertEqual(solver.informs[0], "Success") |
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 think now that we have broken backwards compatibility, we should bump to
1.3.0
at a minimum.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.
Yes I agree, will bump