-
Notifications
You must be signed in to change notification settings - Fork 4
Clean up: warn when functionality is not available #638
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
Conversation
Warning Rate limit exceeded@jan-janssen has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 23 minutes and 21 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (1)
WalkthroughThis change moves the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant MainModule
participant StandaloneCache
participant HDF5File
User->>MainModule: Call get_cache_data(cache_directory)
MainModule->>StandaloneCache: get_cache_data(cache_directory)
StandaloneCache->>HDF5File: Open and read cache.h5out files
HDF5File-->>StandaloneCache: Return deserialized data
StandaloneCache-->>MainModule: Return list of cache data dicts
MainModule-->>User: Return cache data
Possibly related PRs
Poem
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #638 +/- ##
==========================================
+ Coverage 96.67% 96.82% +0.14%
==========================================
Files 29 30 +1
Lines 1293 1291 -2
==========================================
Hits 1250 1250
+ Misses 43 41 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
# Conflicts: # executorlib/__init__.py
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.
Actionable comments posted: 0
🧹 Nitpick comments (4)
executorlib/task_scheduler/file/cache.py (4)
19-19
: Consider moving import to module level.The
h5py
import is placed inside the function body rather than at the module level like other imports. This creates inconsistency in the import style. Unless there's a specific reason for lazy loading, consider moving this import to the top of the file with other imports.
22-25
: Reconsider directory creation logic.The current implementation creates directories for every task key regardless of whether the file already exists:
file_name = os.path.join(cache_directory, task_key, "cache.h5out") os.makedirs(os.path.join(cache_directory, task_key), exist_ok=True) if os.path.exists(file_name): # Process file...This seems inefficient. Consider only creating directories when necessary or reordering these operations for better clarity:
- file_name = os.path.join(cache_directory, task_key, "cache.h5out") - os.makedirs(os.path.join(cache_directory, task_key), exist_ok=True) - if os.path.exists(file_name): + file_name = os.path.join(cache_directory, task_key, "cache.h5out") + if os.path.exists(file_name):
9-34
: Consider adding error handling for file operations.The function performs file I/O operations without any error handling for cases like:
- Permission issues when accessing directories or files
- Corrupted HDF5 files
- Unexpected file formats
Consider adding try-except blocks to gracefully handle these scenarios and provide meaningful error messages.
Example:
def get_cache_data(cache_directory: str) -> list[dict]: import h5py file_lst = [] try: for task_key in os.listdir(cache_directory): file_name = os.path.join(cache_directory, task_key, "cache.h5out") if os.path.exists(file_name): try: with h5py.File(file_name, "r") as hdf: file_content_dict = { key: cloudpickle.loads(np.void(hdf["/" + key])) for key in group_dict.values() if key in hdf } file_content_dict["filename"] = file_name file_lst.append(file_content_dict) except (IOError, OSError) as e: # Log the error or handle it appropriately print(f"Error reading file {file_name}: {str(e)}") except (IOError, OSError) as e: # Log the error or handle it appropriately print(f"Error accessing directory {cache_directory}: {str(e)}") return file_lst
17-17
: Fix typo in docstring.There's a small typo in the docstring return description:
- list[dict]: List of dictionaries each representing on of the HDF5 files in the cache directory. + list[dict]: List of dictionaries each representing one of the HDF5 files in the cache directory.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
executorlib/__init__.py
(1 hunks)executorlib/standalone/hdf.py
(1 hunks)executorlib/task_scheduler/file/cache.py
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- executorlib/init.py
⏰ Context from checks skipped due to timeout of 90000ms (16)
- GitHub Check: unittest_flux_openmpi
- GitHub Check: notebooks_integration
- GitHub Check: unittest_openmpi (ubuntu-latest, 3.12)
- GitHub Check: unittest_openmpi (ubuntu-latest, 3.13)
- GitHub Check: unittest_openmpi (macos-latest, 3.13)
- GitHub Check: unittest_mpich (ubuntu-latest, 3.13)
- GitHub Check: unittest_mpich (macos-latest, 3.13)
- GitHub Check: unittest_old
- GitHub Check: unittest_openmpi (ubuntu-latest, 3.11)
- GitHub Check: unittest_mpich (ubuntu-latest, 3.12)
- GitHub Check: unittest_mpich (ubuntu-latest, 3.11)
- GitHub Check: unittest_win
- GitHub Check: notebooks
- GitHub Check: benchmark (ubuntu-latest, 3.13, .ci_support/environment-openmpi.yml)
- GitHub Check: unittest_flux_mpich
- GitHub Check: benchmark (ubuntu-latest, 3.13, .ci_support/environment-mpich.yml)
🔇 Additional comments (1)
executorlib/standalone/hdf.py (1)
100-108
: Good improvement to documentation.The addition of a detailed docstring for
get_queue_id
improves code readability and maintains consistency with the documentation style of other functions in this file.
for more information, see https://pre-commit.ci
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.
Actionable comments posted: 1
🧹 Nitpick comments (1)
executorlib/standalone/cache.py (1)
32-32
: Directory creation in a read function could have side effects.This function primarily reads cache data, but it's also creating directories with
os.makedirs()
. Creating directories in what appears to be a read-only function might have unintended side effects or be confusing to users.Consider separating directory creation from data reading functionality to maintain clear separation of concerns:
- os.makedirs(os.path.join(cache_directory, task_key), exist_ok=True) + if not os.path.exists(os.path.join(cache_directory, task_key)): + continue
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (9)
executorlib/__init__.py
(1 hunks)executorlib/standalone/cache.py
(1 hunks)executorlib/task_scheduler/file/backend.py
(1 hunks)executorlib/task_scheduler/file/hdf.py
(2 hunks)executorlib/task_scheduler/file/queue_spawner.py
(1 hunks)executorlib/task_scheduler/file/shared.py
(1 hunks)executorlib/task_scheduler/interactive/shared.py
(1 hunks)tests/test_cache_backend_execute.py
(1 hunks)tests/test_standalone_hdf.py
(1 hunks)
✅ Files skipped from review due to trivial changes (5)
- executorlib/task_scheduler/file/queue_spawner.py
- tests/test_standalone_hdf.py
- executorlib/task_scheduler/file/backend.py
- executorlib/task_scheduler/interactive/shared.py
- tests/test_cache_backend_execute.py
🚧 Files skipped from review as they are similar to previous changes (1)
- executorlib/init.py
🧰 Additional context used
🧬 Code Graph Analysis (1)
executorlib/task_scheduler/file/shared.py (1)
executorlib/task_scheduler/file/hdf.py (2)
dump
(10-25)get_output
(55-71)
⏰ Context from checks skipped due to timeout of 90000ms (17)
- GitHub Check: unittest_mpich (macos-latest, 3.13)
- GitHub Check: unittest_mpich (ubuntu-latest, 3.13)
- GitHub Check: unittest_openmpi (ubuntu-latest, 3.12)
- GitHub Check: unittest_mpich (ubuntu-latest, 3.11)
- GitHub Check: unittest_openmpi (ubuntu-latest, 3.11)
- GitHub Check: unittest_mpich (ubuntu-latest, 3.12)
- GitHub Check: unittest_openmpi (ubuntu-latest, 3.13)
- GitHub Check: unittest_openmpi (macos-latest, 3.13)
- GitHub Check: unittest_old
- GitHub Check: notebooks_integration
- GitHub Check: unittest_flux_openmpi
- GitHub Check: unittest_flux_mpich
- GitHub Check: benchmark (ubuntu-latest, 3.13, .ci_support/environment-openmpi.yml)
- GitHub Check: unittest_win
- GitHub Check: benchmark (ubuntu-latest, 3.13, .ci_support/environment-mpich.yml)
- GitHub Check: notebooks
- GitHub Check: minimal
🔇 Additional comments (5)
executorlib/task_scheduler/file/shared.py (1)
11-11
: Updated import path looks good.The import has been updated to use
executorlib.task_scheduler.file.hdf
instead of the previous location. This change is consistent with the refactoring strategy to centralize HDF-related functionality in this module.executorlib/task_scheduler/file/hdf.py (2)
7-7
: Import change forgroup_dict
is appropriate.The
group_dict
import now comes from the newly createdexecutorlib.standalone.cache
module, properly aligning with the refactoring strategy to centralize cache-related functionality.
92-100
: Good addition of detailed docstring.Adding a comprehensive docstring for the
get_queue_id
function improves code documentation and maintainability. The docstring clearly explains the function's purpose, parameters, and return value.executorlib/standalone/cache.py (2)
1-14
: Clean implementation of module and constants.The new module and
group_dict
definition look well-organized with clear naming conventions. Moving this dictionary to the cache module makes sense since it's used for cache data field mapping.
17-27
: Lazy import of h5py aligns with PR objective.The function docstring is clear, and importing
h5py
within the function body (rather than at the module level) is a good pattern that allows the module to be imported even whenh5py
is not available. This aligns with the PR objective to "warn when functionality is not available."
file_lst = [] | ||
for task_key in os.listdir(cache_directory): | ||
file_name = os.path.join(cache_directory, task_key, "cache.h5out") | ||
os.makedirs(os.path.join(cache_directory, task_key), exist_ok=True) | ||
if os.path.exists(file_name): | ||
with h5py.File(file_name, "r") as hdf: | ||
file_content_dict = { | ||
key: cloudpickle.loads(np.void(hdf["/" + key])) | ||
for key in group_dict.values() | ||
if key in hdf | ||
} | ||
file_content_dict["filename"] = file_name | ||
file_lst.append(file_content_dict) | ||
return file_lst |
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.
🛠️ Refactor suggestion
Missing error handling for file operations.
The function doesn't include error handling for scenarios like corrupted HDF5 files, permission issues, or other I/O errors that might occur when reading files.
Consider adding try-except blocks to handle potential exceptions:
for task_key in os.listdir(cache_directory):
file_name = os.path.join(cache_directory, task_key, "cache.h5out")
os.makedirs(os.path.join(cache_directory, task_key), exist_ok=True)
if os.path.exists(file_name):
- with h5py.File(file_name, "r") as hdf:
- file_content_dict = {
- key: cloudpickle.loads(np.void(hdf["/" + key]))
- for key in group_dict.values()
- if key in hdf
- }
- file_content_dict["filename"] = file_name
- file_lst.append(file_content_dict)
+ try:
+ with h5py.File(file_name, "r") as hdf:
+ file_content_dict = {
+ key: cloudpickle.loads(np.void(hdf["/" + key]))
+ for key in group_dict.values()
+ if key in hdf
+ }
+ file_content_dict["filename"] = file_name
+ file_lst.append(file_content_dict)
+ except (OSError, KeyError, ValueError) as e:
+ # Log or handle the error as appropriate
+ print(f"Error reading cache file {file_name}: {e}")
+ continue
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
file_lst = [] | |
for task_key in os.listdir(cache_directory): | |
file_name = os.path.join(cache_directory, task_key, "cache.h5out") | |
os.makedirs(os.path.join(cache_directory, task_key), exist_ok=True) | |
if os.path.exists(file_name): | |
with h5py.File(file_name, "r") as hdf: | |
file_content_dict = { | |
key: cloudpickle.loads(np.void(hdf["/" + key])) | |
for key in group_dict.values() | |
if key in hdf | |
} | |
file_content_dict["filename"] = file_name | |
file_lst.append(file_content_dict) | |
return file_lst | |
file_lst = [] | |
for task_key in os.listdir(cache_directory): | |
file_name = os.path.join(cache_directory, task_key, "cache.h5out") | |
os.makedirs(os.path.join(cache_directory, task_key), exist_ok=True) | |
if os.path.exists(file_name): | |
try: | |
with h5py.File(file_name, "r") as hdf: | |
file_content_dict = { | |
key: cloudpickle.loads(np.void(hdf["/" + key])) | |
for key in group_dict.values() | |
if key in hdf | |
} | |
file_content_dict["filename"] = file_name | |
file_lst.append(file_content_dict) | |
except (OSError, KeyError, ValueError) as e: | |
# Log or handle the error as appropriate | |
print(f"Error reading cache file {file_name}: {e}") | |
continue | |
return file_lst |
Summary by CodeRabbit
New Features
Bug Fixes
Documentation
Refactor