Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 1 addition & 51 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,8 @@ option(GRIDDYN_ENABLE_FMI_EXPORT "Enable construction of a binary fmi shared lib
OFF
)

option(GRIDDYN_BUILD_PYTHON_INTERFACE "Build Python extension" OFF)

option(GRIDDYN_BUILD_PYTHON_LIBRARY "Build nanobind Python library" OFF)

option(GRIDDYN_BUILD_MATLAB_INTERFACE "Build Matlab Extension" OFF)

option(GRIDDYN_BUILD_OCTAVE_INTERFACE "Build Octave extension (very experimental)" OFF)

option(GRIDDYN_BUILD_JAVA_INTERFACE "Build Java extension" OFF)

option(GRIDDYN_ENABLE_CODE_COVERAGE_TEST "Build a target for testing code coverage" OFF)

set(GRIDDYN_ENABLE_OPENMP AUTO CACHE STRING "Enable OpenMP support")
Expand Down Expand Up @@ -266,40 +258,15 @@ if(NOT DEFINED BUILD_SHARED_LIBS)
endif()

if(BUILD_SHARED_LIBS)
set(GRIDDYN_BUILD_C_SHARED_LIBRARY ON)
set(GRIDDYN_BUILD_CXX_SHARED_LIBRARY ON)
set(old_build_shared ON)
# we need this to prevent submodules from building shared libs
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
else()
option(GRIDDYN_BUILD_C_SHARED_LIBRARY OFF
"Enable construction of GridDyn binary C based shared library"
)
option(GRIDDYN_BUILD_CXX_SHARED_LIBRARY OFF "Build the GridDyn C++ shared library")
endif()

if(GRIDDYN_BUILD_PYTHON_INTERFACE
OR GRIDDYN_BUILD_MATLAB_INTERFACE
OR GRIDDYN_BUILD_JAVA_INTERFACE
OR GRIDDYN_BUILD_OCTAVE_INTERFACE
)
set(INTERFACE_BUILD ON)
hide_variable(BUILD_GRIDDYN_C_SHARED_LIBRARY)
show_variable(
DISABLE_SWIG BOOL "Disable the use of swig to generate interface code and use repo code"
OFF
)
else()
set(INTERFACE_BUILD OFF)
hide_variable(DISABLE_SWIG)
endif()

if(INTERFACE_BUILD
OR GRIDDYN_BUILD_CXX_SHARED_LIBRARY
OR GRIDDYN_BUILD_C_SHARED_LIBRARY
OR GRIDDYN_ENABLE_FMI_EXPORT
OR GRIDDYN_BUILD_PYTHON_LIBRARY
)
if(GRIDDYN_BUILD_CXX_SHARED_LIBRARY OR GRIDDYN_ENABLE_FMI_EXPORT OR GRIDDYN_BUILD_PYTHON_LIBRARY)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()

Expand Down Expand Up @@ -735,9 +702,6 @@ endif(GRIDDYN_ENABLE_CLANG_TOOLS)
if(GRIDDYN_BUILD_TESTS AND BUILD_TESTING)
# message(STATUS "otcf:${optional_component_test_files}")
add_subdirectory(test)
if(GRIDDYN_BUILD_C_SHARED_LIBRARY)
add_subdirectory(test/testSharedLibrary)
endif()
enable_testing()
# add_test(NAME gridDynTest COMMAND testCore)
endif()
Expand Down Expand Up @@ -783,20 +747,6 @@ if(GRIDDYN_BUILD_TESTS AND BUILD_TESTING)
)
set_property(TEST Example179BusDynamicTest PROPERTY LABELS Quick Continuous Nightly)

if(GRIDDYN_BUILD_C_SHARED_LIBRARY)
add_test(NAME testSharedLibrary COMMAND shared_library_tests)
set_property(TEST testSharedLibrary PROPERTY LABELS Nightly Release)

add_test(NAME testSharedLibraryQuick COMMAND shared_library_tests --run_test=@quick)
set_property(TEST testSharedLibraryQuick PROPERTY LABELS Quick Continuous Valgrind)
endif()
endif()

# ------------------------------------------------------------
# swig interface builds
# ------------------------------------------------------------
if(INTERFACE_BUILD)
add_subdirectory(interfaces)
endif()

if(GRIDDYN_BUILD_PYTHON_LIBRARY)
Expand Down
4 changes: 1 addition & 3 deletions config/cmake/addlibSuiteSparse.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ else()
set(klu_primary_target klu)
endif()

if(${PROJECT_NAME}_BUILD_CXX_SHARED_LIB OR NOT ${PROJECT_NAME}_DISABLE_C_SHARED_LIB)

if(${PROJECT_NAME}_BUILD_CXX_SHARED_LIBRARY)
if(NOT ${PROJECT_NAME}_USE_SUITESPARSE_STATIC_LIBRARY)
set_target_properties(${klu_primary_target} PROPERTIES PUBLIC_HEADER "")
#[[ if(NOT CMAKE_VERSION VERSION_LESS "3.13")
Expand Down Expand Up @@ -98,5 +97,4 @@ if(${PROJECT_NAME}_BUILD_CXX_SHARED_LIB OR NOT ${PROJECT_NAME}_DISABLE_C_SHARED_
endif()
]]
endif()

endif()
4 changes: 1 addition & 3 deletions config/cmake/addlibzmq.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ else()
set(zmq_target_output "libzmq")
endif()

if(${PROJECT_NAME}_BUILD_CXX_SHARED_LIB OR NOT ${PROJECT_NAME}_DISABLE_C_SHARED_LIB)

if(${PROJECT_NAME}_BUILD_CXX_SHARED_LIBRARY)
if(NOT ${PROJECT_NAME}_USE_ZMQ_STATIC_LIBRARY AND NOT ${PROJECT_NAME}_SKIP_ZMQ_INSTALL)
set_target_properties(${zmq_target_output} PROPERTIES PUBLIC_HEADER "")
install(
Expand All @@ -143,5 +142,4 @@ if(${PROJECT_NAME}_BUILD_CXX_SHARED_LIB OR NOT ${PROJECT_NAME}_DISABLE_C_SHARED_
endif()

endif()

endif()
7 changes: 2 additions & 5 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,8 @@ GridDyn uses C++11 extensively and will make use of some C++14 features in the n
- **ENABLE_TESTS** enable building of the testSuites
- **ENABLE_MULTITHREADING** not used at preset but will eventually enable threaded execution in some models
- **ENABLE_EXTRA_COMPILER_WARNINGS** enable more compiler warnings (full list in config/cmake/compiler_flags.cmake)
- **BUILD_PYTHON_INTERFACE** enable the python swig interface
- **BUILD_MATLAB_INTERFACE** enable the matlab swig interface
- **BUILD_OCTAVE_INTERFACE** enable the octave swig interface
- **BUILD_JAVA_INTERFACE** enable the java swig interface
- **BUILD_CXX_SHARED_LIB** build `libgriddyn_shared_lib.so`, the c++ interface
- **GRIDDYN_BUILD_PYTHON_LIBRARY** build the nanobind Python package
- **GRIDDYN_BUILD_CXX_SHARED_LIBRARY** build the GridDyn C++ shared library
- **ENABLE_CODE_COVERAGE_TEST** enable code coverage tools
- **ENABLE_PLUGINS** build libpluginLibrary
- **ENABLE_EXTRA_SOLVERS** enable additional solvers (including braid, paradae)
Expand Down
67 changes: 17 additions & 50 deletions docs/python-nanobind-migration-plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ simulation API. It is intended to stay current as the work progresses.

## Summary

GridDyn currently exposes Python through SWIG wrappers over the C API in
`interfaces/python`. The new direction is to build a Pythonic interface with
GridDyn previously exposed Python through SWIG wrappers over the C API in
`interfaces/python`. The replacement is a Pythonic interface built with
nanobind that calls GridDyn C++ directly. The C API and SWIG-generated wrappers
should not be part of the new Python implementation.
are no longer part of the maintained Python implementation.

The first milestone is deliberately narrow: expose the simulation object and the
minimum surface needed to load, initialize, solve, and run a GridDyn model from
Expand Down Expand Up @@ -41,8 +41,8 @@ access can follow after the simulation workflow is stable.

## Current State

The existing Python interface is generated from `interfaces/griddyn.i` and
`interfaces/python/griddynPython.i`. It exposes the C API from
The retired Python interface was generated from `interfaces/griddyn.i` and
`interfaces/python/griddynPython.i`. It exposed the C API from
`src/griddyn_shared/griddyn_export.h` and
`src/griddyn_shared/griddyn_export_advanced.h`.

Expand Down Expand Up @@ -238,58 +238,26 @@ Use the `rtunits` Python package as the local model:
- CMake-driven extension build
- package-local compiled extension

Likely CMake options:
Python library CMake option:

```cmake
GRIDDYN_BUILD_PYTHON_LIBRARY=ON
GRIDDYN_BUILD_SWIG_INTERFACE=OFF
```

The current `GRIDDYN_BUILD_PYTHON_INTERFACE` name is ambiguous because it points
to the SWIG interface today. As the new work lands, the CMake option names
should make the distinction clear:

- `GRIDDYN_BUILD_PYTHON_LIBRARY` for the nanobind package
- `GRIDDYN_BUILD_SWIG_INTERFACES` or similar for the legacy SWIG bindings

The nanobind target should link to internal C++ targets needed by
`GriddynRunner` and `GridDynSimulation`, not to `griddyn_shared_lib`.

## SWIG Deprecation And Removal

There are currently no known users relying on the SWIG bindings. That means
SWIG can likely be removed sooner rather than carried through a long
compatibility period.

Proposed policy:

1. Do not add new SWIG typemaps, generated files, or SWIG-based language
interfaces.
2. Add deprecation messaging to the SWIG CMake path once the nanobind
`Simulation` API can load and run a model.
3. Disable SWIG Python builds by default as soon as the nanobind package covers
the basic simulation workflow.
4. Remove SWIG Python sources after a short transition period if no users
appear.
5. Remove Matlab/Octave/Java SWIG paths unless a concrete user need appears.
6. If Matlab support is needed later, prefer a command-line, file-based, or
purpose-built interface rather than reviving SWIG.

## C API Removal Direction

The nanobind migration should not depend on the C API. Once the Python package
and any other required workflows no longer need it, the C API can be retired.
## SWIG Removal

Removal should be a separate cleanup phase because the C API currently packages
several useful concepts:
The SWIG-generated language interfaces have been removed. Do not add new SWIG
typemaps, generated files, or SWIG-based language interfaces. If Matlab or
another language needs support later, prefer a command-line, file-based, or
purpose-built interface rather than reviving SWIG.

- opaque object handles
- centralized exception-to-error-code translation
- shared-library export boundaries
- raw-array math and solver access
## C API Removal

Those concepts should either disappear from the public surface or be replaced
by clearer C++/Python mechanisms before the C API is deleted.
The nanobind migration does not depend on the C API. The old C shared-library
target and its export headers have been removed from the maintained build.

## Future API Phases

Expand Down Expand Up @@ -367,7 +335,7 @@ publish to TestPyPI or PyPI until the Python API is more complete.

## Working Checklist

- [ ] Choose final package location.
- [x] Choose final package location.
- [x] Add `pyproject.toml` for scikit-build-core.
- [x] Add nanobind CMake discovery and extension target.
- [x] Add `griddyn` Python package directory.
Expand All @@ -378,6 +346,5 @@ publish to TestPyPI or PyPI until the Python API is more complete.
- [x] Add CI wheel build and smoke test without package-index publishing.
- [ ] Add load and powerflow smoke test.
- [ ] Add documentation for the first Python API.
- [ ] Add SWIG deprecation messaging.
- [ ] Disable SWIG Python by default once the nanobind smoke tests pass.
- [ ] Decide whether to remove Matlab/Octave/Java SWIG build paths.
- [x] Remove SWIG interface sources and CMake build paths.
- [x] Remove the C shared-library target.
55 changes: 0 additions & 55 deletions interfaces/CMakeLists.txt

This file was deleted.

25 changes: 0 additions & 25 deletions interfaces/griddyn.i

This file was deleted.

Loading
Loading