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

feat: Allow users to configure the internal thread pool (#11) #54

Closed
wants to merge 7 commits into from

Conversation

alhridoy
Copy link

@alhridoy alhridoy commented Oct 8, 2023

This PR introduces a new feature that allows users to configure the internal thread pool used in the _raw_indexing_method function of the EarthEngineBackendArray class.

A new optional parameter executor_kwargs has been added to the function. This parameter is a dictionary that can be used to pass configuration options to the ThreadPoolExecutor. If executor_kwargs is not provided, an empty dictionary is used, preserving the current behavior.

This feature provides users with more flexibility and control over the execution of the function, especially in scenarios where specific thread pool configurations are needed.

Changes:

  • Added executor_kwargs parameter to _raw_indexing_method function in xee/ext.py.

Please review and let me know if any changes are required.

@google-cla
Copy link

google-cla bot commented Oct 8, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
Collaborator

@alxmrs alxmrs left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution, @alhridoy! I have some initial feedback.

A couple more high-level notes:

  • Make sure that users can set this from open_dataset(). To accomplish this, the new keyword arg needs to be accepted in EarthEngineBackendEntrypoint().
  • Please update our integration tests to prove that everything is working.

@@ -0,0 +1 @@
Branch 'configurable-thread-pool' set up to track remote branch 'main' from 'origin'.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove this file.

xee/ext.py Outdated
@@ -634,7 +634,7 @@ def reduce_bands(x, acc):
return target_image

def _raw_indexing_method(
self, key: tuple[Union[int, slice], ...]
self, key: tuple[Union[int, slice], ...], executor_kwargs: Optional[dict] = None
Copy link
Collaborator

Choose a reason for hiding this comment

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

This extra argument is named well, but I think it should be set in the constructor.

xee/ext.py Outdated
Comment on lines 686 to 687
if executor_kwargs is None:
executor_kwargs = {}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's do this bit of logic in the constructor, too.

# If executor_kwargs is None, use an empty dictionary
if executor_kwargs is None:
executor_kwargs = {}
# Pass executor_kwargs to ThreadPoolExecutor
Copy link
Collaborator

Choose a reason for hiding this comment

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

Comment is a bit too verbose for my taste.

@alhridoy
Copy link
Author

Hi @alxmrs when i run the test file, this error pops up.

Could not import runpy module Traceback (most recent call last): File "<frozen runpy>", line 15, in <module> File "<frozen importlib.util>", line 16, in <module> File "/Users/hridoy/Desktop/open_source/Xee/xee/types.py", line 16, in <module> from typing import Union, TypedDict File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/typing.py", line 27, in <module> import contextlib File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/contextlib.py", line 7, in <module> from functools import wraps File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/functools.py", line 22, in <module> from types import GenericAlias ImportError: cannot import name 'GenericAlias' from partially initialized module 'types' (most likely due to a circular import) (/Users/hridoy/Desktop/open_source/Xee/xee/types.py)
I renamed the types.py to type.py then I run the test again, it runs but no output is shown in the terminal. any guidance to run the ext_integration_test.py file?

@alhridoy
Copy link
Author

@alxmrs Thanks for your guidance. Would you check if these changes are working properly? if not, Please let me necessary the changes I need to make. Thanks

xee/ext.py Outdated
@@ -89,6 +89,12 @@ class EarthEngineStore(common.AbstractDataStore):

DEFAULT_MASK_VALUE = np.iinfo(np.int32).max

def __init__(self, executor_kwargs=None):
Copy link
Collaborator

Choose a reason for hiding this comment

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

There already is a constructor.

@@ -358,6 +358,18 @@ def test_data_sanity_check(self):
self.assertNotEqual(temperature_2m.min(), 0.0)
self.assertNotEqual(temperature_2m.max(), 0.0)

def test_open_dataset_with_executor_kwargs(self):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for the test!

@alxmrs
Copy link
Collaborator

alxmrs commented Oct 12, 2023

Please fix the merge conflicts in this branch.

@alhridoy
Copy link
Author

Hi @alxmrs . Thanks for the feedback. ,I added a new parameter executor_kwargs has been added to the init method also resolved merge conflict.

Copy link
Collaborator

@alxmrs alxmrs left a comment

Choose a reason for hiding this comment

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

Definitely looking better. Here are a few more additional suggestions.

Comment on lines +208 to +212
# Initialize executor_kwargs
if executor_kwargs is None:
self.executor_kwargs = {}
else:
self.executor_kwargs = executor_kwargs
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# Initialize executor_kwargs
if executor_kwargs is None:
self.executor_kwargs = {}
else:
self.executor_kwargs = executor_kwargs
if executor_kwargs is None:
executor_kwargs = {}
self.executor_kwargs = executor_kwargs

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please initialize this at the top or bottom of the __init__.

xee/ext.py Outdated
@@ -706,7 +714,7 @@ def reduce_bands(x, acc):
return target_image

def _raw_indexing_method(
self, key: tuple[Union[int, slice], ...]
self, key: tuple[Union[int, slice], ...]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove extra space (to minimize the diff).

@@ -845,6 +854,7 @@ def open_dataset(
primary_dim_name: Optional[str] = None,
primary_dim_property: Optional[str] = None,
ee_mask_value: Optional[float] = None,
executor_kwargs: Optional[dict] = None,
Copy link
Collaborator

Choose a reason for hiding this comment

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

In addition to adding it to the arguments, please update the docstring.

@alhridoy
Copy link
Author

Hi @alxmrs , Would you check the new commits address your comments? If there is still any issue I would be happy to work on that.

@alxmrs
Copy link
Collaborator

alxmrs commented Oct 15, 2023

It feels like you are using a bot to make this patch. I'll be happy to work with you to add this feature. First, please do a self review before I make any additional reviews.

@alhridoy
Copy link
Author

alhridoy commented Nov 9, 2023

Thanks! Please give me couple of weeks.

@alxmrs alxmrs closed this Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants