-
Notifications
You must be signed in to change notification settings - Fork 10
maintenance/improve test coverage #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
9
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
9 commits
Select commit
Hold shift + click to select a range
773d968
maintenance: Align coverage.sh with CI workflow
google-labs-jules[bot] de2d683
Improve test coverage of Python/C++ interface code
greenc-FNAL bb24aa4
Apply clang-format fixes
github-actions[bot] 636092a
Apply cmake-format fixes
github-actions[bot] b96133b
Improve Python list support and test coverage
greenc-FNAL 3d5372d
Fix CodeQL alert: Empty except block in verify_extended.py
greenc-FNAL 978b00e
Apply clang-format fixes
github-actions[bot] c35dfad
Improve Python test coverage
greenc-FNAL 34f38f6
Apply cmake-format fixes
github-actions[bot] 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| -P ubuntu-latest=catthehacker/ubuntu:act-latest |
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,55 @@ | ||
| # 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 `type_name() == "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). | ||
| - System/Spack `site-packages` (for dependencies like `numpy`). | ||
| - **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. |
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
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.
LaTeX syntax in markdown file may not render correctly in all contexts. Consider using the Unicode bidirectional arrow character (↔) or plain text description "to/from" instead of LaTeX math notation.