Skip to content
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

Get OverloadType PETSc.vec #157

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pyadjoint/adjfloat.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,16 @@ def _ad_str(self):
"""Return the string of the taped value of this variable."""
return str(self.block_variable.saved_output)

def _ad_petsc_vec_write_only(self):
raise NotImplementedError(
"It requires more thought to write only a PETSc Vec from `AdjFloat`."
)

def _ad_petsc_vec_read_only(self):
raise NotImplementedError(
"It requires more thought to read only a PETSc Vec from `AdjFloat`."
)


_exp = math.exp
_log = math.log
Expand Down
36 changes: 36 additions & 0 deletions pyadjoint/overloaded_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,42 @@ def _ad_str(self):
"""
return str(self)

def _ad_petsc_vec_read_only(self):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I consider adding an optional argument like with_halos? Or does it not make sense?

"""This method should be overwritten by types which can return a PETSc Vec.

This method must be used as a context manager.

Usage:

.. code-block:: python

with OverloadedType._ad_petsc_vec_read_only() as vec:
# Do something with vec

Returns:
PETSc.Vec: A PETSc Vec object containing the read-only data of the overloaded
instance, excluding halo data.
"""
raise NotImplementedError

def _ad_petsc_vec_write_only(self):
"""This method should be overwritten by types which can return a PETSc Vec.

This method must be used as a context manager.

Usage:

.. code-block:: python

with OverloadedType._ad_petsc_vec_write_only() as vec:
# Do something with vec

Returns:
PETSc.Vec: A PETSc Vec object containing the write-only data of the overloaded
instance, excluding halo data.
"""
raise NotImplementedError


class FloatingType(OverloadedType):
def __init__(self, *args, **kwargs):
Expand Down