-
Notifications
You must be signed in to change notification settings - Fork 10
Improve test coverage for Python support #213
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
Open
greenc-FNAL
wants to merge
67
commits into
Framework-R-D:main
Choose a base branch
from
greenc-FNAL:maintenance/improve-test-coverage
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
67 commits
Select commit
Hold shift + click to select a range
5e7a2d8
Improve test coverage of Python/C++ interface code
greenc-FNAL 7d05a72
Initial plan
Copilot c78727b
Add Variant helper and address review comments
Copilot bc59038
Fix code review comments
Copilot d35075e
Apply cmake-format fixes
github-actions[bot] 057df66
Apply Python linting fixes
github-actions[bot] 96bf0a3
Initial plan
Copilot d7c00b1
Fix ruff F722 and mypy errors in vectypes.py by using type aliases wi…
Copilot 38dbad1
Simplify metaclass implementation per code review feedback
Copilot 3fe4d99
Fix CodeQL alert
greenc-FNAL 3c4772b
Apply clang-format fixes
github-actions[bot] 68b5d8c
Fix Python tests and enforce NumPy requirement
greenc-FNAL 76a4809
Apply cmake-format fixes
github-actions[bot] 4aaf980
More tests to fill gaps
greenc-FNAL b3d6d3c
Apply cmake-format fixes
github-actions[bot] 3e608dd
Apply Python linting fixes
github-actions[bot] de56d99
Address remaining `ruff` issues
greenc-FNAL 4a81f83
Per Gemini 3 Pro, get GIL when updating ref count
greenc-FNAL 2278e96
Attempt to address CI hangs in `py:badbool` and `py:raise` tests
greenc-FNAL ab94c6d
More coverage improvement
greenc-FNAL a404ce8
Apply Python linting fixes
github-actions[bot] 2bd47f0
Apply cmake-format fixes
github-actions[bot] 2382eae
Silence inapposite complaints; remove unused class
greenc-FNAL a32effa
More hang protection
greenc-FNAL 232e0be
Extra diagnostics to debug hangs during testing
greenc-FNAL 0306eb5
More debug logging
greenc-FNAL 2ca9b29
Remove `failing_test_wrap.sh` as unnecessary
greenc-FNAL a308e40
Replace unsafe macro call with safe equivalent
greenc-FNAL 3b80187
Remove all diagnostics to see if problems return
greenc-FNAL b1a82de
Remove diagnostic deadends and other unneeded code
greenc-FNAL 9bc8a6e
Apply clang-format fixes
github-actions[bot] db1f9a6
Apply cmake-format fixes
github-actions[bot] 72a3edd
Armor-plate `WILL_FAIL` tests against false pass
greenc-FNAL f0608d8
Remove possibly-problematic initialization check
greenc-FNAL 1a863f5
Apply cmake-format fixes
github-actions[bot] 4738de5
Further attempts to prevent stalls
greenc-FNAL 0b256a8
Remove diagnostic invocations from coverage workflow
greenc-FNAL 719ed3f
Encourage `ctest --test-timeout` to limit impact of stalling tests
greenc-FNAL a33df63
First pass at addressing review comments
greenc-FNAL 04d144c
Restore array-bounds warning deactivation for GCC 15
greenc-FNAL 8753d90
Improve Python argument ordering stability
greenc-FNAL 913d67b
Apply clang-format fixes
github-actions[bot] bb7818c
Make sure types agree with what's in vectypes.py (#10)
knoepfel 9a6da2b
Apply cmake-format fixes
github-actions[bot] 0db5964
Revert unwanted change per review
greenc-FNAL d337661
Have CMake report module check results
greenc-FNAL 0f45d93
Python AdjustAnnotations class improvements
greenc-FNAL 9bccd37
Apply cmake-format fixes
github-actions[bot] b08db20
Include Python files in coverage change detection
greenc-FNAL 3ee4dd0
Make sure non-test Python code is tested
greenc-FNAL 31dc61f
Apply Python linting fixes
github-actions[bot] 0a77fb8
Apply cmake-format fixes
github-actions[bot] 3699c26
Address `ruff` issues
greenc-FNAL b5e868a
Resolve issues with Python testing and coverage
greenc-FNAL 76cffeb
Enable FORM by default in presets
greenc-FNAL ee6d4ee
Temporarily restore packaging workaround pending reconciliation
greenc-FNAL 574cf0a
Rename AdjustAnnotations to Variant
google-labs-jules[bot] e513cc5
Remove diagnostics
greenc-FNAL 17fef7e
Revert architectural churn while preserving test improvements and fixes
google-labs-jules[bot] d786cc2
Apply markdownlint fixes
github-actions[bot] 95d866d
Apply clang-format fixes
github-actions[bot] e5d69b8
Fix Jsonnet workflow and handle-fix-commit SHA reporting
google-labs-jules[bot] e4dcf87
Resolve `actionlint` issue with `jsonnet-format-fix.yaml`
google-labs-jules[bot] 743287a
Fix Jsonnet format issues
greenc-FNAL 5e7ef4b
Fix NumPy array matching for PEP 604 union types in modulewrap.cpp
google-labs-jules[bot] 9ada41c
Add diagnostics for test segfault
google-labs-jules[bot] 267cbb5
Incorporate @wlav's use of `OrderedDict` into `Variant`
greenc-FNAL File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,6 +62,7 @@ jobs: | |
| file-type: | | ||
| cpp | ||
| cmake | ||
| python | ||
|
|
||
| - name: Report detection outcome | ||
| run: | | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| # Phlex Python Plugin Architecture | ||
|
|
||
| This directory contains the C++ source code for the Phlex Python plugin, which enables Phlex to execute Python code as part of its computation graph. | ||
|
|
||
| ## Architecture Overview | ||
|
|
||
| The integration is built on the **Python C API** (not `pybind11`) to maintain strict control over the interpreter lifecycle and memory management. | ||
|
|
||
| ### 1. The "Type Bridge" (`modulewrap.cpp`) | ||
|
|
||
| The core of the integration is the type conversion layer in `src/modulewrap.cpp`. This layer is responsible for: | ||
|
|
||
| - Converting Phlex `Product` objects (C++) into Python objects (e.g., `PyObject*`, `numpy.ndarray`). | ||
| - Converting Python return values back into Phlex `Product` objects. | ||
|
|
||
| **Critical Implementation Detail:** | ||
| The type mapping relies on **string comparison** of type names. | ||
|
|
||
| - **Mechanism**: The C++ code checks whether `type_name()` contains `"float64]]"` to identify a 2D array of doubles. | ||
| - **Brittleness**: This is a fragile contract. If the type name changes (e.g., `numpy` changes its string representation) or if a user provides a slightly different type (e.g., `float` vs `np.float32`), the bridge may fail. | ||
| - **Extension**: When adding support for new types, you must explicitly add converters in `modulewrap.cpp` for both scalar and vector/array versions. | ||
|
|
||
| ### 2. Hybrid Configuration | ||
|
|
||
| Phlex uses a hybrid configuration model involving three languages: | ||
|
|
||
| 1. **Jsonnet** (`*.jsonnet`): Defines the computation graph structure. It specifies: | ||
| - The nodes in the graph. | ||
| - The Python module/class to load for specific nodes. | ||
| - Configuration parameters passed to the Python object. | ||
| 2. **C++ Driver**: The executable that: | ||
| - Parses the Jsonnet configuration. | ||
| - Initializes the Phlex core. | ||
| - Loads the Python interpreter and the specified plugin. | ||
| 3. **Python Code** (`*.py`): Implements the algorithmic logic. | ||
|
|
||
| ### 3. Environment & Testing | ||
|
|
||
| Because the Python interpreter is embedded within the C++ application, the runtime environment is critical. | ||
|
|
||
| - **PYTHONPATH**: Must be set correctly to include: | ||
| - The build directory (for generated modules). | ||
| - The source directory (for user scripts). | ||
| - Do not append system/Spack `site-packages`; `pymodule.cpp` adjusts `sys.path` based on `CMAKE_PREFIX_PATH` and active virtual environments. | ||
| - **Naming Collisions**: | ||
| - **Warning**: Do not name test files `types.py`, `test.py`, `code.py`, or other names that shadow standard library modules. | ||
| - **Consequence**: Shadowing can cause obscure failures in internal libraries (e.g., `numpy` failing to import because it tries to import `types` from the standard library but gets your local file instead). | ||
|
|
||
| ## Development Guidelines | ||
|
|
||
| 1. **Adding New Types**: | ||
| - Update `src/modulewrap.cpp` to handle the new C++ type. | ||
| - Add a corresponding test case in `test/python/` to verify the round-trip conversion. | ||
| 2. **Testing**: | ||
| - Use `ctest` to run tests. | ||
| - Tests are integration tests: they run the full C++ application which loads the Python script. | ||
| - Debugging: Use `ctest --output-on-failure` to see Python exceptions. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Don't some of these changes suggest the build directory may be at
/? Is this ever the case?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.
It pegs the ignore expression to the top-level directory, otherwise it matches in subdirectories also.