-
Notifications
You must be signed in to change notification settings - Fork 0
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
Start PetscObject #1
Conversation
Start of PetscObject ... please review if you have time, thanks! |
@edsml-zl5621 @FabioLuporini I think can make use of the standard devito objects and interface rather than resulting in all these new classe. Below is an example of something that would work as a nice extension without needing to go all the way down to
|
devito/types/object.py
Outdated
# taken exactly from Function class but removed the "shape_global" | ||
# # and also added the option for all dimensions, shape and grid to be None | ||
@classmethod | ||
def __shape_setup__(cls, **kwargs): |
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.
both shape_setup and indices_setup should belong to AbstractObjectWithShape
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.
Does this mean I should remove the 'empty' shape_setup and indices_setup that are currently inside AbstractObjectWithShape and replace them with these ones?
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?
Say I create a new subtype, let's call it class MyNewObject(AbstractObjectWithShape)
I want this new type to share all the key PetscObject mechanisms , don't I?
devito/types/object.py
Outdated
if len(shape) != len(dimensions): | ||
raise ValueError("`shape` and `dimensions` must have the " | ||
"same number of entries") | ||
loc_shape = [] |
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.
no distinction between global and local shape (MPI irrelevant for Objects), so we don't need this part
devito/types/object.py
Outdated
PetscObject | ||
""" | ||
|
||
AbstractObjectWithShape = True |
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.
don't add unless proven useful. Too early
devito/types/object.py
Outdated
|
||
AbstractObjectWithShape | ||
| | ||
PetscObject |
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.
a PetscObject is way too special to live inside the types/object
directory. Only the more general class belong here.
The PetscObject type should instead be defined wherever you will implement the petsc machinery (passes/iet/petsc/
?) . Just like we do for some MPI Objects under /mpi/distributed
or /mpi/routines
devito/types/object.py
Outdated
@@ -1,14 +1,17 @@ | |||
from ctypes import byref | |||
from ctypes import POINTER |
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 from ctypes import byref, POINTER
?
devito/types/object.py
Outdated
self._is_const = kwargs.get('is_const', False) | ||
|
||
# taken exactly from Function class but removed the "shape_global" | ||
# # and also added the option for all dimensions, shape and grid to be None |
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.
Extra #
in the second comment here
devito/types/object.py
Outdated
@classmethod | ||
def __indices_setup__(cls, **kwargs): | ||
grid = kwargs.get('grid') | ||
# shape = kwargs.get('shape', None) |
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.
Leftover comment
devito/types/object.py
Outdated
|
||
@property | ||
def _C_ctype(self): | ||
""" |
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.
Is the empty docstring intentional?
Hi, I added a FunctionPtr class and a test for the symbolic representation of C's function pointers. I'm not sure if this is the right way to do it so if someone could have a look that would be great! Thank you |
devito/symbolics/extended_sympy.py
Outdated
Symbolic representation of C's function pointers. | ||
""" | ||
|
||
_return_typ = '' |
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 aren't these instance attributes?
also, you can add an 'e' at the end of 'type' ;)
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 took inspo from the Cast class https://github.com/devitocodes/devito/blob/0abe3952a792ed9ba5bf9ef904fa2fec04789a79/devito/symbolics/extended_sympy.py#L370C1-L400C33 and _base_typ is not an instance attribute. Is there a particular reason for this?
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 it's a leftover from code that has been refactorer multiple times. You may probably tweak that too !
devito/symbolics/extended_sympy.py
Outdated
func = Pickable._rebuild | ||
|
||
@property | ||
def _op(self): |
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.
shouldn't this just be __str__
(== __repr__
)
Also, how about a first tiny tiny PR that only ships
THe first merge into devito master is big milestone :-) |
# need to check this? | ||
# __rkwargs__ = ('name', 'dtype', 'is_const', 'grid', 'shape', 'dimensions') | ||
|
||
def __new__(cls, *args, **kwargs): |
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.
This still looks like there is a quite large amount of overlap with AbstractFunction
so I'm not sure why this is needed.
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.
Hi, I forgot to ask about this in the meeting. @FabioLuporini do you have any comments on this, because I am unsure?
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.
@mloubout AbstractObject doesn't inherit from AbstractFunction, so unless we lift some of the construction logic to the closest common ancestor (as in, Basic
), this needs to stay here, I think
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.
But this doesn't need to inheriting from AbstractObject
if there is already an existing type that does all of it. This just redefines AbstractFunction
with a new calss name and _const
it should be a 2 liners inheriting from AbstractFunction
9d73c8e
to
a9fd0c2
Compare
devito/passes/iet/petsc.py
Outdated
# __rkwargs__ = (AbstractObjectWithShape.__rkwargs__ + | ||
# ('petsc_type',)) | ||
|
||
def __init__(self, name, petsc_type, **kwargs): |
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.
Should implement _init_finalize_
not __init__
to follow AbstractObjectWithShape
construction
return obj | ||
|
||
def __str__(self): | ||
return "(%s (%s)(%s))%s" % (self.return_type, '*', |
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.
Could this be simplified to return "(%s (*)(%s))%s" % (self.return_type, self.parameter_type, self.func_name)
?
devito/tools/dtypes_lowering.py
Outdated
|
||
# this probably shouldn't be in this file | ||
def petsc_type_to_ctype(petsc_type): | ||
"Map Petsc types to ctypes type" |
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.
Triple quotes on the docstring
devito/symbolics/extended_sympy.py
Outdated
@@ -400,6 +401,37 @@ def _op(self): | |||
return '(%s)' % self.typ | |||
|
|||
|
|||
class FunctionPointer(sympy.Expr, Pickable): | |||
|
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.
Remove this whitespace?
afdfd2f
to
43f1f07
Compare
43f1f07
to
e9e5bb2
Compare
Playing around with PR UI.