Skip to content
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

Fix issue with theta and add build for python 3.13 #95

Merged
merged 11 commits into from
Nov 29, 2024
64 changes: 49 additions & 15 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ jobs:
abi: cp312,
version: '3.12',
}
- {
name: cp313,
abi: cp313,
version: '3.13',
}

cont:
- {
Expand Down Expand Up @@ -101,7 +106,7 @@ jobs:
auditwheel repair dist/*.whl

- name: Build source archive
if: matrix.python.name == 'cp311'
if: matrix.python.name == 'cp312'
run: python3 setup.py sdist

- name: Install lightsim2grid wheel
Expand All @@ -122,7 +127,7 @@ jobs:
python3 -c "from lightsim2grid.gridmodel import GridModel"

- name: Check package can be imported (bare install, numpy < 2)
if: matrix.python.name != 'cp37' && matrix.python.name != 'cp38'
if: matrix.python.name != 'cp37' && matrix.python.name != 'cp38' && matrix.python.name != 'cp313'
run: |
python3 -m pip install "numpy<2"
cd tmp_for_import_checking
Expand All @@ -141,11 +146,13 @@ jobs:
# otherwise urllib3 v2.0 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'OpenSSL 1.0.2k-fips 26 Jan 2017'

- name: Install grid2op
if: matrix.python.name != 'cp313' # pandapower does not support 3.13, so grid2op does not so I cannot test that for 3.13
run: |
python3 -m pip install grid2op pandapower
python3 -m pip freeze

- name: Check extra can be imported can be imported (with grid2op)
if: matrix.python.name != 'cp313' # pandapower does not support 3.13, so grid2op does not so I cannot test that for 3.13
run: |
cd tmp_for_import_checking
python3 -v -c "from lightsim2grid import LightSimBackend"
Expand All @@ -156,19 +163,20 @@ jobs:
python3 -c "from lightsim2grid.gridmodel import init_from_pandapower"

- name: Check LightSimBackend can be used to create env
if: matrix.python.name != 'cp313' # pandapower does not support 3.13, so grid2op does not so I cannot test that for 3.13
run: |
cd tmp_for_import_checking
python3 -v -c "from lightsim2grid import LightSimBackend; import grid2op; env = grid2op.make('l2rpn_case14_sandbox', test=True, backend=LightSimBackend())"

- name: Upload wheel
uses: actions/upload-artifact@v4 # v4 broken
uses: actions/upload-artifact@v4
with:
name: lightsim2grid-wheel-linux-${{ matrix.python.name }}-${{ matrix.cont.name }}
path: wheelhouse/*.whl

- name: Upload source archive
uses: actions/upload-artifact@v4 # v4 broken
if: matrix.python.name == 'cp311'
uses: actions/upload-artifact@v4
if: matrix.python.name == 'cp312'
with:
name: lightsim2grid-sources
path: dist/*.tar.gz
Expand Down Expand Up @@ -204,6 +212,10 @@ jobs:
name: cp312,
version: '3.12',
}
- {
name: cp313,
version: '3.13',
}
win_arch:
- {
name: "AMD64",
Expand Down Expand Up @@ -275,7 +287,7 @@ jobs:
python3 -c "from lightsim2grid.gridmodel import GridModel"

- name: Check package can be imported (bare install, numpy < 2)
if: matrix.python.name != 'cp37' && matrix.python.name != 'cp38'
if: matrix.python.name != 'cp37' && matrix.python.name != 'cp38' && matrix.python.name != 'cp313'
run: |
python3 -m pip install "numpy<2"
cd tmp_for_import_checking
Expand All @@ -288,6 +300,7 @@ jobs:
python3 -c "from lightsim2grid.gridmodel import GridModel"

- name: Check LightSimBackend can be imported (with grid2op)
if: matrix.python.name != 'cp313' # pandapower does not support 3.13, so grid2op does not so I cannot test that for 3.13
run: |
python -m pip install grid2op
cd tmp_for_import_checking
Expand All @@ -299,12 +312,18 @@ jobs:
python -c "from lightsim2grid.securityAnalysis import SecurityAnalysis"
python -c "from lightsim2grid.gridmodel import init_from_pandapower"

- name: Check LightSimBackend can be used to create env
if: matrix.python.name != 'cp313' # pandapower does not support 3.13, so grid2op does not so I cannot test that for 3.13
run: |
cd tmp_for_import_checking
python3 -v -c "from lightsim2grid import LightSimBackend; import grid2op; env = grid2op.make('l2rpn_case14_sandbox', test=True, backend=LightSimBackend())"

# - name: Debug windows CI
# run: |
# python -m unittest lightsim2grid.tests.test_n1contingencyrewards.TestN1ContingencyReward_Base.test_do_nothing

- name: Upload wheel
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: lightsim2grid-wheel-win-${{ matrix.python.name }}-${{ matrix.win_arch.msvc}}
path: dist/*.whl
Expand Down Expand Up @@ -340,6 +359,10 @@ jobs:
name: cp312,
version: '3.12',
}
- {
name: cp313,
version: '3.13',
}
runner:
- {
name: macos-13,
Expand Down Expand Up @@ -418,7 +441,7 @@ jobs:
python3 -c "from lightsim2grid.gridmodel import GridModel"

- name: Check package can be imported (bare install, numpy < 2)
if: matrix.python.name != 'cp37' && matrix.python.name != 'cp38'
if: matrix.python.name != 'cp37' && matrix.python.name != 'cp38' && matrix.python.name != 'cp313'
run: |
python3 -m pip install "numpy<2"
cd tmp_for_import_checking
Expand All @@ -437,11 +460,13 @@ jobs:
# otherwise urllib3 v2.0 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'OpenSSL 1.0.2k-fips 26 Jan 2017'

- name: Install grid2op
if: matrix.python.name != 'cp313' # pandapower does not support 3.13, so grid2op does not so I cannot test that for 3.13
run: |
python -m pip install grid2op
python -m pip freeze

- name: Check extra can be imported can be imported (with grid2op)
if: matrix.python.name != 'cp313' # pandapower does not support 3.13, so grid2op does not so I cannot test that for 3.13
run: |
cd tmp_for_import_checking
python -v -c "from lightsim2grid import LightSimBackend"
Expand All @@ -452,12 +477,13 @@ jobs:
python -c "from lightsim2grid.gridmodel import init_from_pandapower"

- name: Check LightSimBackend can be used to create env
if: matrix.python.name != 'cp313' # pandapower does not support 3.13, so grid2op does not so I cannot test that for 3.13
run: |
cd tmp_for_import_checking
python -v -c "from lightsim2grid import LightSimBackend; import grid2op; env = grid2op.make('l2rpn_case14_sandbox', test=True, backend=LightSimBackend())"

- name: Upload wheel
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: lightsim2grid-wheel-darwin-${{ matrix.python.name }}-${{ matrix.runner.arch}}
path: dist/*.whl
Expand Down Expand Up @@ -506,6 +532,10 @@ jobs:
name: cp312,
version: '3.12',
}
- {
name: cp313,
version: '3.13',
}
exclude:
- python:
name: cp310 # because already done natively above
Expand All @@ -519,6 +549,10 @@ jobs:
name: cp312 # because already done natively above
runner:
name: macos-14
- python:
name: cp313 # because already done natively above
runner:
name: macos-14
- python:
name: cp38 # does not work
runner:
Expand All @@ -540,7 +574,7 @@ jobs:
platforms: all

- name: Compile with cibuildwheel
uses: pypa/cibuildwheel@v2.17.0
uses: pypa/cibuildwheel@v2.22.0
env:
CIBW_PLATFORM: "${{ matrix.runner.cibuildwheel}}"
CIBW_BUILD: "${{ matrix.python.name}}-*"
Expand All @@ -560,7 +594,7 @@ jobs:
cmake --build . --config Release &&
cmake --install . --prefix ..\built
CIBW_TEST_REQUIRES: grid2op pandapower "numpy<2"
CIBW_TEST_SKIP: "cp312-* *-macosx_arm64 *-win_arm64" # to silence warning "While arm64 wheels can be built on x86_64, they cannot be tested."
CIBW_TEST_SKIP: "cp312-* *-macosx_arm64 *-win_arm64 cp313-*" # to silence warning "While arm64 wheels can be built on x86_64, they cannot be tested."
CIBW_TEST_COMMAND: >
python -c "import lightsim2grid" &&
python -c "from lightsim2grid import *" &&
Expand All @@ -572,9 +606,9 @@ jobs:
python -c "from lightsim2grid import LightSimBackend" &&
python -c "from lightsim2grid.physical_law_checker import PhysicalLawChecker"
- name: Upload wheel
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: lightsim2grid-wheel-${{ matrix.runner.whl_nm}}-${{ matrix.python.name }}
name: lightsim2grid-wheel-exotic-${{ matrix.runner.whl_nm}}-${{ matrix.python.name }}
path: ./wheelhouse/*.whl

package:
Expand All @@ -584,12 +618,12 @@ jobs:

steps:
- name: Download wheels
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
path: download

- name: Upload wheels
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: lightsim2grid-wheels
path: |
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ TODO: in `main.cpp` check the returned policy of pybind11 and also the `py::call
TODO: a cpp class that is able to compute (DC powerflow) ContingencyAnalysis and TimeSeries using PTDF and LODF
TODO: integration test with pandapower (see `pandapower/contingency/contingency.py` and import `lightsim2grid_installed` and check it's True)

[0.9.2.post2] 2024-11-29
--------------------------
- [FIXED] The attribute `can_output_theta` (of base `Backend` class)
was not set to `True` if using the pypowsybl loader.
- [FIXED] the github CI to work properly on many linux buit image
- [IMPROVED] build on python 3.13

[0.9.2.post1] 2024-11-28
--------------------------
- [FIXED] There is still a bug with the pypowsybl 1.8.1 version with the
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ Pypi packages are available for linux (`x86_64` cpu architecture), windows (`x86
- 3.10 (lightsim2grid >= 0.6.1)
- 3.11 (lightsim2grid >= 0.7.1)
- 3.12 (lightsim2grid >= 0.7.5)
- 3.13 (lightsim2grid >= 0.9.2.post2)


As from version 0.8.2, we also distribute windows `arm64` and macos `arm64` binaries of lightsim2grid that can be installed
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
author = 'Benjamin DONNOT'

# The full version, including alpha/beta/rc tags
release = "0.9.2.post1"
release = "0.9.2.post2"
version = '0.9'

# -- General configuration ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion lightsim2grid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# SPDX-License-Identifier: MPL-2.0
# This file is part of LightSim2grid, LightSim2grid implements a c++ backend targeting the Grid2Op platform.

__version__ = "0.9.2.post1"
__version__ = "0.9.2.post2"

__all__ = ["newtonpf", "SolverType", "ErrorType", "solver", "compilation_options"]

Expand Down
4 changes: 3 additions & 1 deletion lightsim2grid/lightSimBackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ def __init__(self,
if not hasattr(self, "_can_be_copied"):
self._can_be_copied = can_be_copied

#: I can output the voltage angle
self.can_output_theta = True

#: .. versionadded:: 0.8.0
#:
#: Which type of grid format can be read by your backend.
Expand Down Expand Up @@ -836,7 +839,6 @@ def _load_grid_pandapower(self, path=None, filename=None):
self._aux_init_pandapower()

def _aux_init_pandapower(self):
self.can_output_theta = True # i can compute the "theta" and output it to grid2op
from lightsim2grid.gridmodel import init_from_pandapower
self._grid = init_from_pandapower(self.init_pp_backend._grid)
self.__nb_bus_before = self.init_pp_backend.get_nb_active_bus()
Expand Down
2 changes: 2 additions & 0 deletions lightsim2grid/tests/test_backend_pypowsybl.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def test_runpf(self):
# DC powerflow
conv, exc_ = backend.runpf(is_dc=True)
assert conv
assert backend.can_output_theta

class BackendTester2(unittest.TestCase):
"""issue is still not replicated and these tests pass"""
Expand Down Expand Up @@ -101,6 +102,7 @@ def test_runpf(self):
# DC powerflow
conv, exc_ = backend.runpf(is_dc=True)
assert conv
assert backend.can_output_theta

if CAN_DO_TEST_SUITE:
dir_path = os.path.dirname(os.path.realpath(__file__))
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from pybind11.setup_helpers import Pybind11Extension, build_ext


__version__ = "0.9.2.post1"
__version__ = "0.9.2.post2"
KLU_SOLVER_AVAILABLE = False

# Try to link against SuiteSparse (if available)
Expand Down
Loading