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

[DOC] Add docstrings to functions, classes, and methods in api_context_managers.py #5544

Closed
wants to merge 2 commits into from
Closed

Conversation

theaaravmakadia
Copy link

Report needed documentation
While the estimator guide offers a great breakdown of how to use many of the tools in api_context_managers.py, it would be helpful to have information right in the docstring during development to more easily understand what is actually going on in each of the provided functions/classes/methods. This is particularly important for other developers who are trying to make changes to api_context_managers.py itself.

Describe the documentation you'd like
It would be great if each function/class/method had at least a brief docstring description for its intended behavior so that developers making changes have greater confidence that their changes are going in the appropriate place for the intended usage of each function/class/method. Even better would be a full docstring with parameter descriptions, etc.

Steps taken to search for needed documentation
Read the estimator guide and all documentation it links to.

@csadorf @wphicks --> PR related to #3470.

@theaaravmakadia theaaravmakadia requested a review from a team as a code owner August 3, 2023 15:23
@rapids-bot
Copy link

rapids-bot bot commented Aug 3, 2023

Pull requests from external contributors require approval from a rapidsai organization member with write permissions or greater before CI can begin.

@github-actions github-actions bot added the Cython / Python Cython or Python issue label Aug 3, 2023
@theaaravmakadia theaaravmakadia marked this pull request as draft August 3, 2023 15:26
@csadorf csadorf added doc Documentation improvement Improvement / enhancement to an existing function non-breaking Non-breaking change and removed improvement Improvement / enhancement to an existing function labels Aug 3, 2023
@csadorf csadorf requested a review from wphicks August 3, 2023 16:32
@csadorf csadorf changed the base branch from branch-23.08 to branch-23.10 August 3, 2023 16:34
@csadorf csadorf changed the base branch from branch-23.10 to branch-23.08 August 3, 2023 16:35
Copy link
Contributor

@wphicks wphicks left a comment

Choose a reason for hiding this comment

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

I've begun review, but can you comment on what happened here before we continue review?

@@ -66,10 +66,31 @@ def _using_mirror_output_type():


def in_internal_api():
"""
Checks if the code is currently executing within an internal API context.
Copy link
Contributor

Choose a reason for hiding this comment

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

For this kind of call, it would be good to provide some context on exactly what this means. The name of the method is already fairly descriptive, so it is more important to emphasize why we care about this. For this particular case, it is important because once we are making calls internal to a cuML API call, we have already performed the necessary conversion to a CumlArray, and we want to avoid extra copies to device.

return GlobalSettings().root_cm is not None


def set_api_output_type(output_type: str):
"""
Sets the output type for the current internal API context.
Copy link
Contributor

Choose a reason for hiding this comment

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

Explain what the output type is and what the impact is of setting this.

@@ -87,6 +108,19 @@ def set_api_output_type(output_type: str):


def set_api_memory_type(mem_type):
"""
Sets the memory type for the current internal API context.
Copy link
Contributor

Choose a reason for hiding this comment

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

Explain what the memory type is and the impact of changing it.

Raises
------
AssertionError
If the root context manager is not set.
Copy link
Contributor

Choose a reason for hiding this comment

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

In general, we do not want developers to have to dig too deeply into the internals of this, especially worrying about what the "root context manager" is or why it is important. Instead, let's describe under what circumstances the root context manager might not be set.

@@ -100,6 +134,19 @@ def set_api_memory_type(mem_type):


def set_api_output_dtype(output_dtype):
"""
Sets the output data type for the current internal API context.
Copy link
Contributor

Choose a reason for hiding this comment

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

Explain the impact of setting this and what is meant by data type. I would actually stick to the word dtype, since it will be clearer to those familiar with numpy/cupy what this is.

for cb in self._process_enter_cbs:
cb()


class ProcessReturn(object):
def __init__(self, context: "InternalAPIContextBase"):
"""
Constructor for the ProcessReturn class.
Copy link
Contributor

Choose a reason for hiding this comment

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

It should already be obvious that this is a constructor. Explain what this class does and why it is necessary.

@@ -238,7 +336,19 @@ def __init__(self, context: "InternalAPIContextBase"):
] = deque()

def process_return(self, ret_val):

"""
Execute the registered process return callbacks on the given return value.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you rephrase this to give a bit more of an intuitive sense of what is going on here? An internal call returns a value, and then the callbacks are executed on that value in order to do what?

"""
Base class for the internal API context.

This class provides a context manager for managing the internal API context
Copy link
Contributor

Choose a reason for hiding this comment

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

What does this mean?


ProcessEnter_Type: typing.Type[EnterT] = None
ProcessReturn_Type: typing.Type[ProcessT] = None

def __init__(self, func=None, args=None):
"""
Constructor for the InternalAPIContextBase class.
Copy link
Contributor

Choose a reason for hiding this comment

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

It should already be obvious that this is a constructor. Explain what this class does and why it is necessary.

int
The count of how many times this context has been entered.
"""
# ... (Details not shown in the provided code snippet)
Copy link
Contributor

Choose a reason for hiding this comment

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

What happened here?

@rapidsai rapidsai deleted a comment from dantegd Aug 7, 2023
@csadorf
Copy link
Contributor

csadorf commented Aug 21, 2023

@theaaravmakadia Can you respond to the review comments, please?

@wphicks
Copy link
Contributor

wphicks commented Aug 29, 2023

Going to close this PR due to inactivity, especially given that it has fallen out of date with the current development branch. @theaaravmakadia, please do feel free to reopen or update if you have time/interest later on.

@wphicks wphicks closed this Aug 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cython / Python Cython or Python issue doc Documentation non-breaking Non-breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants