-
Notifications
You must be signed in to change notification settings - Fork 36
Enable Cache in ICON4Py checks #493
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,6 +3,8 @@ | |||||||||||||||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||||||||||||||||
| # SPDX-License-Identifier: BSD-3-Clause | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| import os | ||||||||||||||||||||||||||||||||||||||||||
| import re | ||||||||||||||||||||||||||||||||||||||||||
| import reframe as rfm | ||||||||||||||||||||||||||||||||||||||||||
| import reframe.utility.sanity as sn | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -28,16 +30,28 @@ class ICON4PyBenchmarks(rfm.RunOnlyRegressionTest): | |||||||||||||||||||||||||||||||||||||||||
| 'HUGETLB_MORECORE': 'no', | ||||||||||||||||||||||||||||||||||||||||||
| 'GT4PY_UNSTRUCTURED_HORIZONTAL_HAS_UNIT_STRIDE': '1', | ||||||||||||||||||||||||||||||||||||||||||
| 'PYTHONOPTIMIZE': '2', | ||||||||||||||||||||||||||||||||||||||||||
| # GT4Py cache does not work properly for dace backend yet | ||||||||||||||||||||||||||||||||||||||||||
| # 'GT4PY_BUILD_CACHE_LIFETIME': 'persistent', | ||||||||||||||||||||||||||||||||||||||||||
| # 'GT4PY_BUILD_CACHE_DIR': '...', | ||||||||||||||||||||||||||||||||||||||||||
| 'GT4PY_BUILD_CACHE_LIFETIME': 'persistent', | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| executable = './_run.sh' | ||||||||||||||||||||||||||||||||||||||||||
| executable_opts = ['2>&1'] | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| @run_before('run') | ||||||||||||||||||||||||||||||||||||||||||
| def prepare_env(self): | ||||||||||||||||||||||||||||||||||||||||||
| gpu_arch = self.current_partition.select_devices('gpu')[0].arch | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| cache_folder = ( | ||||||||||||||||||||||||||||||||||||||||||
| f"{os.environ.get('SCRATCH')}/" | ||||||||||||||||||||||||||||||||||||||||||
| f".cache/reframe_bencher_icon4py/" | ||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||
| sub_folder = ( | ||||||||||||||||||||||||||||||||||||||||||
| f"{self.current_system.name}=" | ||||||||||||||||||||||||||||||||||||||||||
| f"{gpu_arch}=" | ||||||||||||||||||||||||||||||||||||||||||
| f"{self.current_environ}" | ||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+46
to
+50
|
||||||||||||||||||||||||||||||||||||||||||
| sub_folder = ( | |
| f"{self.current_system.name}=" | |
| f"{gpu_arch}=" | |
| f"{self.current_environ}" | |
| ) | |
| # Normalize components used in cache subfolder to avoid None/empty values | |
| system_name = getattr(self.current_system, 'name', '') | |
| if not system_name: | |
| system_name = 'unknownsystem' | |
| if not gpu_arch: | |
| gpu_arch = 'unknowngpu' | |
| if self.current_environ not in (None, ''): | |
| env_name = str(self.current_environ) | |
| else: | |
| env_name = 'unknownenv' | |
| sub_folder = f"{system_name}={gpu_arch}={env_name}" |
Copilot
AI
Jan 12, 2026
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.
The regex pattern uses [\s\S]? which matches any character (including newlines) in a non-greedy manner. This is a less readable way to match multi-line content. Consider using the re.DOTALL flag (or (?s) flag in the pattern) with .? instead, or ensure the regex pattern is well-tested, as pytest output between the test name and PASSED could vary significantly.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,7 +7,7 @@ unset PYTHONPATH | |||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| git clone https://github.com/C2SM/icon4py.git | ||||||||||||||||||||||||||||||||||||||
| cd icon4py | ||||||||||||||||||||||||||||||||||||||
| git checkout 5485bcacb1dbc7688b1e7d276d4e2e28362c5444 # Commit: Update to GT4Py v1.1.0 (#933) | ||||||||||||||||||||||||||||||||||||||
| git checkout 15b7406d9385a189abaaa71b14851d1491b231f1 # Commit: Update to GT4Py v1.1.2 (#969) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| # Install uv locally | ||||||||||||||||||||||||||||||||||||||
| curl -LsSf https://astral.sh/uv/install.sh | UV_UNMANAGED_INSTALL="$PWD/bin" sh | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -25,6 +25,54 @@ mpi4py_ver=$(uv pip show mpi4py | awk '/Version:/ {print $2}') | |||||||||||||||||||||||||||||||||||||
| uv pip uninstall mpi4py && uv pip install --no-binary mpi4py "mpi4py==$mpi4py_ver" | ||||||||||||||||||||||||||||||||||||||
| uv pip install git+https://github.com/cupy/cupy.git | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| # Patch Gt4Py to avoid cache issues | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
| # Patch Gt4Py to avoid cache issues | |
| # Patch GT4Py to avoid cache issues |
Copilot
AI
Jan 12, 2026
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.
The Python script does not validate that the gt4py directory was successfully cloned before attempting to read and patch the file. If the git clone operation fails (e.g., due to network issues), the script will fail with a confusing error about the file not existing rather than a clear indication that the clone operation failed.
| git clone --branch v1.1.2 https://github.com/GridTools/gt4py.git | |
| python3 -c ' | |
| import sys | |
| from pathlib import Path | |
| file_path = Path("gt4py/src/gt4py/next/otf/stages.py") | |
| if ! git clone --branch v1.1.2 https://github.com/GridTools/gt4py.git; then | |
| echo "Error: failed to clone gt4py repository." >&2 | |
| exit 1 | |
| fi | |
| python3 -c ' | |
| import sys | |
| from pathlib import Path | |
| file_path = Path("gt4py/src/gt4py/next/otf/stages.py") | |
| if not file_path.is_file(): | |
| print(f"Error: expected file '{file_path}' does not exist. gt4py repository may not have been cloned correctly.", file=sys.stderr) | |
| sys.exit(1) |
Copilot
AI
Jan 12, 2026
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.
The Python script uses next(iterator) in a while True loop without handling potential StopIteration exceptions. If the "column_axis," line is not found in the file after detecting the "program_hash" line, this will raise an uncaught StopIteration exception instead of providing a helpful error message.
| while True: | |
| skipped_line = next(iterator) | |
| if "column_axis," in skipped_line: | |
| new_lines.append(skipped_line) # Add column_axis line back | |
| break | |
| column_line_found = False | |
| for skipped_line in iterator: | |
| if "column_axis," in skipped_line: | |
| new_lines.append(skipped_line) # Add column_axis line back | |
| column_line_found = True | |
| break | |
| if not column_line_found: | |
| print( | |
| '"column_axis," line not found after program_hash block; ' | |
| "patch cannot be safely applied." | |
| ) | |
| sys.exit(1) |
Copilot
AI
Jan 12, 2026
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.
The inline Python script is performing a brittle file patching operation by searching for specific text patterns and modifying source code. This approach is fragile and could easily break if the GT4Py library structure changes slightly (e.g., whitespace changes, code reformatting). Consider using a more robust patching mechanism such as applying a unified diff patch file, or checking if this fix has been upstreamed to GT4Py v1.1.2 or a later version.
Copilot
AI
Jan 12, 2026
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 block clones the third-party gt4py repository from GitHub using --branch v1.1.2 and then installs it editable with uv pip install -e ./gt4py, which pins a critical dependency only to a mutable Git ref rather than an immutable commit or verified release artifact. If the GridTools/gt4py repo or its v1.1.2 ref is compromised or retagged, an attacker could inject arbitrary code into this check pipeline and potentially access CI secrets or tamper with produced artifacts. To reduce supply-chain risk, pin gt4py to an immutable commit SHA or a verified release artifact (e.g., a PyPI release with hashes) instead of a branch/tag, and avoid editable installs from mutable Git references in automated environments.
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.
The cache directory is constructed using environment variables that may not be set. If the SCRATCH environment variable is not set, os.environ.get('SCRATCH') will return None, resulting in a cache path starting with "None/" which is likely not the intended behavior. Consider adding validation or a fallback value.