feat: Add backend availability API for runtime backend detection#16
feat: Add backend availability API for runtime backend detection#16
Conversation
Implements Phase 5 of the v0.1.6 migration plan: - Add BACKEND_SCALAR, BACKEND_SIMD, BACKEND_OMP, BACKEND_CUDA constants - Add backend_is_available() to check if a backend is available - Add backend_get_name() to get backend name string - Add list_solvers_by_backend() to get solvers for a specific backend - Add get_available_backends() to list all available backends - Update __init__.py with new exports and fix version to v0.1.6+ - Add comprehensive test suite for backend availability API
There was a problem hiding this comment.
Pull request overview
This PR implements Phase 5 of the v0.1.6 migration plan, adding a comprehensive backend availability API for runtime backend detection. This enables Python code to query which solver backends (scalar, SIMD, OpenMP, CUDA) are available at runtime, supporting the CFD library's new modular backend architecture in v0.1.6.
Key changes:
- Added four backend type constants (BACKEND_SCALAR, BACKEND_SIMD, BACKEND_OMP, BACKEND_CUDA) mapped to the C library's ns_solver_backend_t enum
- Implemented four new API functions:
backend_is_available(),backend_get_name(),list_solvers_by_backend(), andget_available_backends() - Added comprehensive test suite with 17 tests covering constants, availability checking, name queries, and solver listing
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/test_backend_availability.py | New comprehensive test suite with 17 tests validating backend constants, availability checks, name queries, and function exports |
| src/cfd_python.c | Adds four Python wrapper functions (backend_is_available_py, backend_get_name_py, list_solvers_by_backend_py, get_available_backends_py) with proper error handling and memory management, plus module initialization for backend constants |
| cfd_python/init.py | Updates module docstring to v0.1.6+, adds backend availability section to documentation, and exports new constants and functions in all |
| MIGRATION_PLAN.md | Marks Phase 5 as completed, updates timeline estimates, and documents the implemented features with completion date |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Functions: | ||
|
|
There was a problem hiding this comment.
The "Functions:" header on this line appears to be incomplete or misplaced. It's followed by an empty line and then the "Solver backend availability (v0.1.6):" section starts. This creates a confusing documentation structure.
Either remove this line entirely (since "Boundary condition functions:" on line 66 provides the actual function listing), or restructure the documentation to make it clear what falls under this "Functions:" heading.
| Functions: |
PyList_SET_ITEM is a macro not available in the limited/stable API. Replace with PyList_SetItem function which is available in abi3.
The backend availability functions and constants were added to the C extension but not exported through _loader.py, which is required for the module namespace population.
- BACKEND_OMP returns "openmp" not "omp" - Invalid backend returns "unknown" not None
Move BC functions under the Boundary conditions section and remove the duplicate/empty Functions header.
Implements Phase 5 of the v0.1.6 migration plan: