From eefd001b5c0970a842ed3e5ba83502f214622c05 Mon Sep 17 00:00:00 2001 From: DONNOT Benjamin Date: Mon, 21 Aug 2023 15:42:49 +0200 Subject: [PATCH 01/22] some improvements --- CHANGELOG.rst | 8 ++++++-- lightsim2grid/lightSimBackend.py | 31 ++++++++++++++++++++++++++----- setup.py | 2 +- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 7ea2691..e7ee146 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -19,12 +19,16 @@ Change Log - easier building (get rid of the "make" part) - code NR with dense matrices -[0.7.3] 2023-07-xx +[0.7.3] 2023-08-xx -------------------- - [FIXED] a bug where, when you disconnect a load (or gen), the next action cannot be performed if it modifies the load (or gen), because you "cannot change the value of a disconnected load (or gen)" +- [FIXED] read-the-docs template is not compatible with latest sphinx version (7.0.0) + see https://github.com/readthedocs/sphinx_rtd_theme/issues/1463 - [IMPROVED] initialize the underlying "PandaPowerBackend" without numba -- [IMPROVED] grid2op import to be more compliant with renaming of +- [IMPROVED] grid2op import to be more compliant with renaming of uppercased file names +- [IMPROVED] decoupling of the PandapowerBackend class and the class "internally" used by LightSimBackend + when loading the grid. This caused some issue, *eg* https://github.com/rte-france/Grid2Op/issues/508 [0.7.2] 2023-06-06 -------------------- diff --git a/lightsim2grid/lightSimBackend.py b/lightsim2grid/lightSimBackend.py index 3118613..be0488d 100644 --- a/lightsim2grid/lightSimBackend.py +++ b/lightsim2grid/lightSimBackend.py @@ -85,12 +85,17 @@ def __init__(self, self.topo_vect = None self.shunt_topo_vect = None + class _DoNotUseANywherePandaPowerBackend(PandaPowerBackend): + """used to duplicate the class attr of PandaPowerBackend""" + pass + _DoNotUseANywherePandaPowerBackend = PandaPowerBackend + try: - self.init_pp_backend = PandaPowerBackend(with_numba=False) + self.init_pp_backend = _DoNotUseANywherePandaPowerBackend(with_numba=False) except TypeError as exc_: # oldest version of grid2op do not support the kwargs "with_numba" # (before 1.9.1) - self.init_pp_backend = PandaPowerBackend() + self.init_pp_backend = _DoNotUseANywherePandaPowerBackend() self.V = None self.max_it = max_iter @@ -174,6 +179,22 @@ def __init__(self, # add the static gen to the list of controlable gen in grid2Op self._use_static_gen = use_static_gen # TODO implement it + # storage data for this object (otherwise it's in the class) + self.n_storage = None + self.storage_to_subid = None + self.storage_pu_to_kv = None + self.name_storage = None + self.storage_to_sub_pos = None + self.storage_type = None + self.storage_Emin = None + self.storage_Emax = None + self.storage_max_p_prod = None + self.storage_max_p_absorb = None + self.storage_marginal_cost = None + self.storage_loss = None + self.storage_discharging_efficiency = None + self.storage_charging_efficiency = None + def turnedoff_no_pv(self): self._turned_off_pv = False self._grid.turnedoff_no_pv() @@ -439,7 +460,7 @@ def load_grid(self, path=None, filename=None): self.storage_loss = self.init_pp_backend.storage_loss self.storage_discharging_efficiency = self.init_pp_backend.storage_discharging_efficiency self.storage_charging_efficiency = self.init_pp_backend.storage_charging_efficiency - + self.nb_bus_total = self.init_pp_backend._grid.bus.shape[0] self.thermal_limit_a = copy.deepcopy(self.init_pp_backend.thermal_limit_a) @@ -477,7 +498,7 @@ def load_grid(self, path=None, filename=None): tmp.reshape(-1, 1)), axis=-1) self._big_topo_to_obj = [(None, None) for _ in range(self.dim_topo)] - + self._compute_pos_big_topo() # set up the "lightsim grid" accordingly @@ -591,7 +612,7 @@ def assert_grid_correct_after_powerflow(self): """ # test the results gives the proper size super().assert_grid_correct_after_powerflow() - self.init_pp_backend.__class__ = self.init_pp_backend.init_grid(self) + # self.init_pp_backend.__class__ = self.init_pp_backend.init_grid(self) self._backend_action_class = _BackendAction.init_grid(self) self._init_action_to_set = self._backend_action_class() try: diff --git a/setup.py b/setup.py index 0359640..dbe1a27 100644 --- a/setup.py +++ b/setup.py @@ -327,7 +327,7 @@ "extras": { "docs": [ "numpydoc>=0.9.2", - "sphinx>=2.4.4", + "sphinx>=2.4.4,<7", "sphinx-rtd-theme>=0.4.3", "sphinxcontrib-trio>=1.1.0", "autodocsumm>=0.1.13", From 22a608cfdb888216e35cc81c15df1a2bc404a7e1 Mon Sep 17 00:00:00 2001 From: DONNOT Benjamin Date: Mon, 21 Aug 2023 15:44:30 +0200 Subject: [PATCH 02/22] some improvements --- lightsim2grid/lightSimBackend.py | 1 - 1 file changed, 1 deletion(-) diff --git a/lightsim2grid/lightSimBackend.py b/lightsim2grid/lightSimBackend.py index be0488d..f3802c2 100644 --- a/lightsim2grid/lightSimBackend.py +++ b/lightsim2grid/lightSimBackend.py @@ -88,7 +88,6 @@ def __init__(self, class _DoNotUseANywherePandaPowerBackend(PandaPowerBackend): """used to duplicate the class attr of PandaPowerBackend""" pass - _DoNotUseANywherePandaPowerBackend = PandaPowerBackend try: self.init_pp_backend = _DoNotUseANywherePandaPowerBackend(with_numba=False) From cf33b485b2f196ba208b9185d11afe17662bac96 Mon Sep 17 00:00:00 2001 From: DONNOT Benjamin Date: Mon, 21 Aug 2023 16:16:19 +0200 Subject: [PATCH 03/22] try to compile for M1 and M2 apple using cibuildwheel --- .circleci/{config.yml => old_config.yml} | 0 .github/workflows/main.yml | 16 ++++++++++++++-- README.md | 1 + lightsim2grid/lightSimBackend.py | 6 +++--- 4 files changed, 18 insertions(+), 5 deletions(-) rename .circleci/{config.yml => old_config.yml} (100%) diff --git a/.circleci/config.yml b/.circleci/old_config.yml similarity index 100% rename from .circleci/config.yml rename to .circleci/old_config.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bd576c0..fa022d2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -143,13 +143,25 @@ jobs: python -m pip install --upgrade pip python -m pip install -r requirements.txt - - name: Compile SuiteSparse make - if: matrix.config.name == 'darwin' + - name: Compile SuiteSparse make (3.7 or 3.11+) + if: (matrix.config.name == 'darwin') && ((matrix.python.version == 3.7) || (matrix.python.version >= 3.11) ) run: | make export __O3_OPTIM=1 python3 setup.py build + - name: Compile SuiteSparse make (3.8, 3.9, 3.10) + if: (matrix.config.name == 'darwin') && (matrix.python.version == 3.7) + uses: pypa/cibuildwheel@v2.15.0 + env: + # configure cibuildwheel to build native archs ('auto'), and some + # emulated ones + CIBW_ARCHS_LINUX: x86_64 arm64 + run: | + make + export __O3_OPTIM=1 + python3 -m cibuildwheel --output-dir wheelhouse + - name: Compile SuiteSparse cmake if: matrix.config.name == 'windows' run: | diff --git a/README.md b/README.md index b94f0c2..e3db132 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,7 @@ Pypi packages are available for linux, windows and macos with python versions: - 3.8 - 3.9 - 3.10 (lightsim2grid >= 0.6.1) +- 3.11 (lightsim2grid >= 0.7.1) ## Installation (from source, for more advanced user) diff --git a/lightsim2grid/lightSimBackend.py b/lightsim2grid/lightSimBackend.py index f3802c2..6d38fad 100644 --- a/lightsim2grid/lightSimBackend.py +++ b/lightsim2grid/lightSimBackend.py @@ -85,16 +85,16 @@ def __init__(self, self.topo_vect = None self.shunt_topo_vect = None - class _DoNotUseANywherePandaPowerBackend(PandaPowerBackend): + class _DoNotUseAnywherePandaPowerBackend(PandaPowerBackend): """used to duplicate the class attr of PandaPowerBackend""" pass try: - self.init_pp_backend = _DoNotUseANywherePandaPowerBackend(with_numba=False) + self.init_pp_backend = _DoNotUseAnywherePandaPowerBackend(with_numba=False) except TypeError as exc_: # oldest version of grid2op do not support the kwargs "with_numba" # (before 1.9.1) - self.init_pp_backend = _DoNotUseANywherePandaPowerBackend() + self.init_pp_backend = _DoNotUseAnywherePandaPowerBackend() self.V = None self.max_it = max_iter From 6146ca66c2ce33f9cb0fe65ba7452edbee373349 Mon Sep 17 00:00:00 2001 From: DONNOT Benjamin Date: Mon, 21 Aug 2023 16:23:59 +0200 Subject: [PATCH 04/22] try to compile for M1 and M2 apple using cibuildwheel --- .github/workflows/main.yml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fa022d2..f365b99 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -138,6 +138,12 @@ jobs: with: python-version: ${{ matrix.python.version }} + - name: Get CIBUILDWHEEL FOR python 3.8, 3.9, 3.10 + if: (matrix.config.name == 'darwin') && ((matrix.python.version != 3.7) || (matrix.python.version < 3.11) ) + uses: pypa/cibuildwheel@v2.15.0 + env: + CIBW_ARCHS_LINUX: x86_64 arm64 + - name: Install Python dependencies run: | python -m pip install --upgrade pip @@ -150,13 +156,8 @@ jobs: export __O3_OPTIM=1 python3 setup.py build - - name: Compile SuiteSparse make (3.8, 3.9, 3.10) - if: (matrix.config.name == 'darwin') && (matrix.python.version == 3.7) - uses: pypa/cibuildwheel@v2.15.0 - env: - # configure cibuildwheel to build native archs ('auto'), and some - # emulated ones - CIBW_ARCHS_LINUX: x86_64 arm64 + - name: Compile SuiteSparse make (3.7 or 3.11+) + if: (matrix.config.name == 'darwin') && ((matrix.python.version >= 3.8) || (matrix.python.version < 3.11) ) run: | make export __O3_OPTIM=1 From e5861fc024808be14a4b25fb5e7df914a496f86e Mon Sep 17 00:00:00 2001 From: DONNOT Benjamin Date: Mon, 21 Aug 2023 16:51:26 +0200 Subject: [PATCH 05/22] still trying to build lightsim for M1 chip --- .github/workflows/main.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f365b99..7ffc768 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -138,7 +138,7 @@ jobs: with: python-version: ${{ matrix.python.version }} - - name: Get CIBUILDWHEEL FOR python 3.8, 3.9, 3.10 + - name: Get CIBUILDWHEEL for python 3.8, 3.9, 3.10 if: (matrix.config.name == 'darwin') && ((matrix.python.version != 3.7) || (matrix.python.version < 3.11) ) uses: pypa/cibuildwheel@v2.15.0 env: @@ -156,7 +156,7 @@ jobs: export __O3_OPTIM=1 python3 setup.py build - - name: Compile SuiteSparse make (3.7 or 3.11+) + - name: Compile SuiteSparse make for python 3.8, 3.9, 3.10 if: (matrix.config.name == 'darwin') && ((matrix.python.version >= 3.8) || (matrix.python.version < 3.11) ) run: | make @@ -179,6 +179,7 @@ jobs: python setup.py build - name: Build wheel + if: ! ( (matrix.config.name == 'darwin') && ((matrix.python.version >= 3.8) || (matrix.python.version < 3.11) ) ) run: python setup.py bdist_wheel - name: Build source archive From 99a2d8c69d3f81602d8d13da5d04fd2186add9a2 Mon Sep 17 00:00:00 2001 From: DONNOT Benjamin Date: Mon, 21 Aug 2023 16:53:40 +0200 Subject: [PATCH 06/22] still trying to build lightsim for M1 chip --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7ffc768..562c7bc 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -156,7 +156,7 @@ jobs: export __O3_OPTIM=1 python3 setup.py build - - name: Compile SuiteSparse make for python 3.8, 3.9, 3.10 + - name: Compile SuiteSparse make for python 3.8, 3.9, 3.10, and build wheel if: (matrix.config.name == 'darwin') && ((matrix.python.version >= 3.8) || (matrix.python.version < 3.11) ) run: | make @@ -179,7 +179,7 @@ jobs: python setup.py build - name: Build wheel - if: ! ( (matrix.config.name == 'darwin') && ((matrix.python.version >= 3.8) || (matrix.python.version < 3.11) ) ) + if: (matrix.config.name == 'windows') || ((matrix.config.name == 'darwin') && ((matrix.python.version == 3.7) || (matrix.python.version >= 3.11) )) run: python setup.py bdist_wheel - name: Build source archive From bc77479e647e21cbcd1d36b818601bce3125a602 Mon Sep 17 00:00:00 2001 From: DONNOT Benjamin Date: Mon, 21 Aug 2023 17:18:00 +0200 Subject: [PATCH 07/22] still trying to build lightsim for M1 chip --- .github/workflows/main.yml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 562c7bc..32ff017 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -100,10 +100,10 @@ jobs: name: darwin, os: macos-latest, } - - { - name: windows, - os: windows-2019, - } + # - { + # name: windows, + # os: windows-2019, + # } python: - { name: cp37, @@ -142,7 +142,9 @@ jobs: if: (matrix.config.name == 'darwin') && ((matrix.python.version != 3.7) || (matrix.python.version < 3.11) ) uses: pypa/cibuildwheel@v2.15.0 env: - CIBW_ARCHS_LINUX: x86_64 arm64 + CIBW_ARCHS_LINUX: auto aarch64 # not used I believe + CIBW_ARCHS_MACOS: x86_64 universal2 + CIBW_BUILD: "{{matrix.python.name}}-*" - name: Install Python dependencies run: | @@ -218,7 +220,8 @@ jobs: package: name: Package wheels runs-on: ubuntu-latest - needs: [manylinux_build, macos_windows_build] + # needs: [manylinux_build, macos_windows_build] + needs: [macos_windows_build] steps: - name: Download wheels From 1bd1eab3e50189e17946cdf838926343d9a85ea9 Mon Sep 17 00:00:00 2001 From: DONNOT Benjamin Date: Mon, 21 Aug 2023 17:25:06 +0200 Subject: [PATCH 08/22] still trying to build lightsim for M1 chip --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 32ff017..ae00476 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -144,7 +144,7 @@ jobs: env: CIBW_ARCHS_LINUX: auto aarch64 # not used I believe CIBW_ARCHS_MACOS: x86_64 universal2 - CIBW_BUILD: "{{matrix.python.name}}-*" + CIBW_BUILD: ${{matrix.python.name}}"-*" - name: Install Python dependencies run: | From 80e88b8fb1d3d86cdabcf5b6cf7554a51f94e458 Mon Sep 17 00:00:00 2001 From: DONNOT Benjamin Date: Mon, 21 Aug 2023 17:27:30 +0200 Subject: [PATCH 09/22] still trying to build lightsim for M1 chip --- .github/workflows/main.yml | 167 ++++++++++++++++++------------------- 1 file changed, 83 insertions(+), 84 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ae00476..03d3f8d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,87 +8,87 @@ on: - 'v*.*.*' jobs: - manylinux_build: - name: Build linux ${{ matrix.python.name }} wheel - runs-on: ubuntu-latest - container: quay.io/pypa/manylinux2014_x86_64 - strategy: - matrix: - python: - - { - name: cp37, - abi: cp37m, - version: '3.7', - } - - { - name: cp38, - abi: cp38, - version: '3.8', - } - - { - name: cp39, - abi: cp39, - version: '3.9', - } - - { - name: cp310, - abi: cp310, - version: '3.10', - } - - { - name: cp311, - abi: cp311, - version: '3.11', - } - - steps: - - - name: Checkout sources - uses: actions/checkout@v1 - with: - submodules: true - - - name: Setup path - run: echo "/opt/python/${{ matrix.python.name }}-${{ matrix.python.abi }}/bin/" >> $GITHUB_PATH - - - name: Install Python dependencies - run: | - python -m pip install --upgrade pip - python -m pip install -r requirements.txt - - - name: Compile SuiteSparse - run: make - - - name: Build wheel - run: | - # export __O3_OPTIM=1 - python3 setup.py bdist_wheel - auditwheel repair dist/*.whl - - - name: Install wheel - run: pip3 install wheelhouse/*.whl --user - - - name: Install GDB - run: yum install -y gdb - - - name: Check package can be imported - run: | - # python3 -c "import lightsim2grid" - # python3 -c "from lightsim2grid import *" - # python3 -c "from lightsim2grid.newtonpf import newtonpf" - gdb -batch -ex r --args python3 -c "from lightsim2grid import *" -ex backtrace - - - name: Check LightSimBackend can be imported - run: | - python3 -m pip install grid2op - python3 -c "from lightsim2grid import LightSimBackend" - python3 -c "from lightsim2grid import LightSimBackend; import grid2op; env = grid2op.make('l2rpn_case14_sandbox', test=True, backend=LightSimBackend())" - - - name: Upload wheel - uses: actions/upload-artifact@v2 - with: - name: lightsim2grid-wheel-linux-${{ matrix.python.name }} - path: wheelhouse/*.whl + # manylinux_build: + # name: Build linux ${{ matrix.python.name }} wheel + # runs-on: ubuntu-latest + # container: quay.io/pypa/manylinux2014_x86_64 + # strategy: + # matrix: + # python: + # - { + # name: cp37, + # abi: cp37m, + # version: '3.7', + # } + # - { + # name: cp38, + # abi: cp38, + # version: '3.8', + # } + # - { + # name: cp39, + # abi: cp39, + # version: '3.9', + # } + # - { + # name: cp310, + # abi: cp310, + # version: '3.10', + # } + # - { + # name: cp311, + # abi: cp311, + # version: '3.11', + # } + + # steps: + + # - name: Checkout sources + # uses: actions/checkout@v1 + # with: + # submodules: true + + # - name: Setup path + # run: echo "/opt/python/${{ matrix.python.name }}-${{ matrix.python.abi }}/bin/" >> $GITHUB_PATH + + # - name: Install Python dependencies + # run: | + # python -m pip install --upgrade pip + # python -m pip install -r requirements.txt + + # - name: Compile SuiteSparse + # run: make + + # - name: Build wheel + # run: | + # # export __O3_OPTIM=1 + # python3 setup.py bdist_wheel + # auditwheel repair dist/*.whl + + # - name: Install wheel + # run: pip3 install wheelhouse/*.whl --user + + # - name: Install GDB + # run: yum install -y gdb + + # - name: Check package can be imported + # run: | + # # python3 -c "import lightsim2grid" + # # python3 -c "from lightsim2grid import *" + # # python3 -c "from lightsim2grid.newtonpf import newtonpf" + # gdb -batch -ex r --args python3 -c "from lightsim2grid import *" -ex backtrace + + # - name: Check LightSimBackend can be imported + # run: | + # python3 -m pip install grid2op + # python3 -c "from lightsim2grid import LightSimBackend" + # python3 -c "from lightsim2grid import LightSimBackend; import grid2op; env = grid2op.make('l2rpn_case14_sandbox', test=True, backend=LightSimBackend())" + + # - name: Upload wheel + # uses: actions/upload-artifact@v2 + # with: + # name: lightsim2grid-wheel-linux-${{ matrix.python.name }} + # path: wheelhouse/*.whl macos_windows_build: name: Build ${{ matrix.config.name }} ${{ matrix.python.name }} wheel @@ -144,7 +144,7 @@ jobs: env: CIBW_ARCHS_LINUX: auto aarch64 # not used I believe CIBW_ARCHS_MACOS: x86_64 universal2 - CIBW_BUILD: ${{matrix.python.name}}"-*" + CIBW_BUILD: ${{matrix.python.name}}-* - name: Install Python dependencies run: | @@ -220,8 +220,7 @@ jobs: package: name: Package wheels runs-on: ubuntu-latest - # needs: [manylinux_build, macos_windows_build] - needs: [macos_windows_build] + needs: [manylinux_build, macos_windows_build] steps: - name: Download wheels From 0f32fa8a53c969ccfd1e1f2e36bff7389ede7f03 Mon Sep 17 00:00:00 2001 From: DONNOT Benjamin Date: Mon, 21 Aug 2023 17:28:05 +0200 Subject: [PATCH 10/22] still trying to build lightsim for M1 chip --- .github/workflows/main.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 03d3f8d..b4bbdc3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -220,7 +220,8 @@ jobs: package: name: Package wheels runs-on: ubuntu-latest - needs: [manylinux_build, macos_windows_build] + # needs: [manylinux_build, macos_windows_build] + needs: [macos_windows_build] steps: - name: Download wheels From e85f5faeac2d0ad250a1528e7cfc709f7fbcec14 Mon Sep 17 00:00:00 2001 From: DONNOT Benjamin Date: Tue, 22 Aug 2023 09:14:36 +0200 Subject: [PATCH 11/22] trying to cross compile on macos for M1 --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b4bbdc3..ff3e3c2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -161,6 +161,7 @@ jobs: - name: Compile SuiteSparse make for python 3.8, 3.9, 3.10, and build wheel if: (matrix.config.name == 'darwin') && ((matrix.python.version >= 3.8) || (matrix.python.version < 3.11) ) run: | + python3 -m pip install cibuildwheel make export __O3_OPTIM=1 python3 -m cibuildwheel --output-dir wheelhouse From bea28ecf9f835ae3a7baae8f0a73689016b905ed Mon Sep 17 00:00:00 2001 From: DONNOT Benjamin Date: Tue, 22 Aug 2023 13:55:33 +0200 Subject: [PATCH 12/22] trying to cross compile on macos for M1 / M2 chip --- .github/workflows/main.yml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ff3e3c2..279a210 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -125,6 +125,9 @@ jobs: name: cp311, version: '3.11', } + env: + RUNNER_OS: ${{ matrix.config.os }} + PYTHON_VERSION: ${{ matrix.python.version }} steps: @@ -138,13 +141,19 @@ jobs: with: python-version: ${{ matrix.python.version }} + - name: Set Additional Envs + shell: bash + run: | + echo "PYTHON_SUBVERSION=$(echo $PYTHON_VERSION | cut -c 3-)" >> $GITHUB_ENV + echo "DEPLOY=$( [[ $GITHUB_EVENT_NAME == 'push' && $GITHUB_REF == 'refs/tags'* ]] && echo 'True' || echo 'False' )" >> $GITHUB_ENV + - name: Get CIBUILDWHEEL for python 3.8, 3.9, 3.10 if: (matrix.config.name == 'darwin') && ((matrix.python.version != 3.7) || (matrix.python.version < 3.11) ) uses: pypa/cibuildwheel@v2.15.0 env: + CIBW_BUILD: "cp3${{env.PYTHON_SUBVERSION}}-*" # see https://github.com/cvxpy/cvxpy/blob/master/.github/workflows/build.yml CIBW_ARCHS_LINUX: auto aarch64 # not used I believe CIBW_ARCHS_MACOS: x86_64 universal2 - CIBW_BUILD: ${{matrix.python.name}}-* - name: Install Python dependencies run: | From 27937888031038fad20c2253052d3e7443c10ab7 Mon Sep 17 00:00:00 2001 From: DONNOT Benjamin Date: Tue, 22 Aug 2023 14:26:23 +0200 Subject: [PATCH 13/22] trying to cross compile on macos for M1 / M2 chip --- .github/workflows/main.yml | 169 ++++++++++++++++++++++++------------- 1 file changed, 110 insertions(+), 59 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 279a210..5b0c507 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -65,6 +65,10 @@ jobs: # python3 setup.py bdist_wheel # auditwheel repair dist/*.whl + # - name: Build source archive + # if: matrix.python.name == 'cp311' + # run: python setup.py sdist + # - name: Install wheel # run: pip3 install wheelhouse/*.whl --user @@ -90,7 +94,105 @@ jobs: # name: lightsim2grid-wheel-linux-${{ matrix.python.name }} # path: wheelhouse/*.whl - macos_windows_build: + # - name: Upload source archive + # uses: actions/upload-artifact@v2 + # if: matrix.python.name == 'cp311' + # with: + # name: lightsim2grid-sources + # path: dist/*.tar.gz + + # windows_build: + # name: Build ${{ matrix.config.name }} ${{ matrix.python.name }} wheel + # runs-on: ${{ matrix.config.os }} + # strategy: + # matrix: + # config: + # - { + # name: windows, + # os: windows-2019, + # } + # python: + # - { + # name: cp37, + # version: '3.7', + # } + # - { + # name: cp38, + # version: '3.8', + # } + # - { + # name: cp39, + # version: '3.9', + # } + # - { + # name: cp310, + # version: '3.10', + # } + # - { + # name: cp311, + # version: '3.11', + # } + # env: + # RUNNER_OS: ${{ matrix.config.os }} + # PYTHON_VERSION: ${{ matrix.python.version }} + + # steps: + + # - name: Checkout sources + # uses: actions/checkout@v1 + # with: + # submodules: true + + # - name: Setup Python + # uses: actions/setup-python@v2 + # with: + # python-version: ${{ matrix.python.version }} + + # - name: Install Python dependencies + # run: | + # python -m pip install --upgrade pip + # python -m pip install -r requirements.txt + + # - name: Compile SuiteSparse cmake + # run: | + # cd build_cmake + # python generate_c_files.py + # mkdir build + # cd build + # cmake -DCMAKE_INSTALL_PREFIX=..\built -DCMAKE_BUILD_TYPE=Release .. + # cmake --build . --config Release + # cmake --install . --prefix ..\built + # cd .. + # cd .. + # set __O3_OPTIM=1 + # python setup.py build + + # - name: Build wheel + # run: python setup.py bdist_wheel + + # - name: Install wheel + # shell: bash + # run: python -m pip install dist/*.whl --user + + # - name: Check package can be imported + # run: | + # python -c "import lightsim2grid" + # python -c "from lightsim2grid import *" + # python -c "from lightsim2grid.newtonpf import newtonpf" + + # - name: Check LightSimBackend can be imported + # run: | + # python -m pip install grid2op + # python -c "from lightsim2grid import LightSimBackend" + # python -c "from lightsim2grid import LightSimBackend; import grid2op; env = grid2op.make('l2rpn_case14_sandbox', test=True, backend=LightSimBackend())" + + # - name: Upload wheel + # uses: actions/upload-artifact@v2 + # with: + # name: lightsim2grid-wheel-${{ matrix.config.name }}-${{ matrix.python.name }} + # path: dist/*.whl + + macos_build: name: Build ${{ matrix.config.name }} ${{ matrix.python.name }} wheel runs-on: ${{ matrix.config.os }} strategy: @@ -100,10 +202,6 @@ jobs: name: darwin, os: macos-latest, } - # - { - # name: windows, - # os: windows-2019, - # } python: - { name: cp37, @@ -148,55 +246,15 @@ jobs: echo "DEPLOY=$( [[ $GITHUB_EVENT_NAME == 'push' && $GITHUB_REF == 'refs/tags'* ]] && echo 'True' || echo 'False' )" >> $GITHUB_ENV - name: Get CIBUILDWHEEL for python 3.8, 3.9, 3.10 - if: (matrix.config.name == 'darwin') && ((matrix.python.version != 3.7) || (matrix.python.version < 3.11) ) + if: (matrix.config.name == 'darwin') && ((matrix.python.version != 3.7) || (matrix.python.version < '3.11') ) uses: pypa/cibuildwheel@v2.15.0 env: CIBW_BUILD: "cp3${{env.PYTHON_SUBVERSION}}-*" # see https://github.com/cvxpy/cvxpy/blob/master/.github/workflows/build.yml CIBW_ARCHS_LINUX: auto aarch64 # not used I believe - CIBW_ARCHS_MACOS: x86_64 universal2 - - - name: Install Python dependencies - run: | - python -m pip install --upgrade pip - python -m pip install -r requirements.txt - - - name: Compile SuiteSparse make (3.7 or 3.11+) - if: (matrix.config.name == 'darwin') && ((matrix.python.version == 3.7) || (matrix.python.version >= 3.11) ) - run: | - make - export __O3_OPTIM=1 - python3 setup.py build - - - name: Compile SuiteSparse make for python 3.8, 3.9, 3.10, and build wheel - if: (matrix.config.name == 'darwin') && ((matrix.python.version >= 3.8) || (matrix.python.version < 3.11) ) - run: | - python3 -m pip install cibuildwheel - make - export __O3_OPTIM=1 - python3 -m cibuildwheel --output-dir wheelhouse - - - name: Compile SuiteSparse cmake - if: matrix.config.name == 'windows' - run: | - cd build_cmake - python generate_c_files.py - mkdir build - cd build - cmake -DCMAKE_INSTALL_PREFIX=..\built -DCMAKE_BUILD_TYPE=Release .. - cmake --build . --config Release - cmake --install . --prefix ..\built - cd .. - cd .. - set __O3_OPTIM=1 - python setup.py build - - - name: Build wheel - if: (matrix.config.name == 'windows') || ((matrix.config.name == 'darwin') && ((matrix.python.version == 3.7) || (matrix.python.version >= 3.11) )) - run: python setup.py bdist_wheel - - - name: Build source archive - if: matrix.config.name == 'darwin' && matrix.python.name == 'cp39' - run: python setup.py sdist + CIBW_ARCHS_MACOS: x86_64 universal2 arm64 + CIBW_BEFORE_ALL: > + make && + export __O3_OPTIM=1 - name: Install wheel shell: bash @@ -220,18 +278,11 @@ jobs: name: lightsim2grid-wheel-${{ matrix.config.name }}-${{ matrix.python.name }} path: dist/*.whl - - name: Upload source archive - uses: actions/upload-artifact@v2 - if: matrix.config.name == 'darwin' && matrix.python.name == 'cp39' - with: - name: lightsim2grid-sources - path: dist/*.tar.gz - package: name: Package wheels runs-on: ubuntu-latest - # needs: [manylinux_build, macos_windows_build] - needs: [macos_windows_build] + # needs: [manylinux_build, windows_build] + needs: [macos_build] steps: - name: Download wheels From e84426b1072227acda7a86141e1cd6fda9b2bcd5 Mon Sep 17 00:00:00 2001 From: DONNOT Benjamin Date: Tue, 22 Aug 2023 14:35:14 +0200 Subject: [PATCH 14/22] trying to cross compile on macos for M1 / M2 chip --- .github/workflows/main.yml | 102 ++++++++++++++++++++++++++----------- 1 file changed, 72 insertions(+), 30 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5b0c507..a90ee86 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -102,15 +102,10 @@ jobs: # path: dist/*.tar.gz # windows_build: - # name: Build ${{ matrix.config.name }} ${{ matrix.python.name }} wheel - # runs-on: ${{ matrix.config.os }} + # name: Build windows ${{ matrix.python.name }} wheel + # runs-on: windows-2019 # strategy: # matrix: - # config: - # - { - # name: windows, - # os: windows-2019, - # } # python: # - { # name: cp37, @@ -133,7 +128,7 @@ jobs: # version: '3.11', # } # env: - # RUNNER_OS: ${{ matrix.config.os }} + # RUNNER_OS: windows-2019 # PYTHON_VERSION: ${{ matrix.python.version }} # steps: @@ -192,21 +187,73 @@ jobs: # name: lightsim2grid-wheel-${{ matrix.config.name }}-${{ matrix.python.name }} # path: dist/*.whl - macos_build: - name: Build ${{ matrix.config.name }} ${{ matrix.python.name }} wheel - runs-on: ${{ matrix.config.os }} + # macos_build_37_311: + # name: Build macos ${{ matrix.python.name }} wheel + # runs-on: macos-latest + # strategy: + # matrix: + # python: + # - { + # name: cp37, + # version: '3.7', + # } + # - { + # name: cp311, + # version: '3.11', + # } + # steps: + # - name: Checkout sources + # uses: actions/checkout@v1 + # with: + # submodules: true + + # - name: Setup Python + # uses: actions/setup-python@v2 + # with: + # python-version: ${{ matrix.python.version }} + + # - name: Install Python dependencies + # run: | + # python -m pip install --upgrade pip + # python -m pip install -r requirements.txt + + # - name: Compile SuiteSparse make + # run: | + # make + # export __O3_OPTIM=1 + # python3 setup.py build + + # - name: Build wheel + # run: python setup.py bdist_wheel + + # - name: Install wheel + # shell: bash + # run: python -m pip install dist/*.whl --user + + # - name: Check package can be imported + # run: | + # python -c "import lightsim2grid" + # python -c "from lightsim2grid import *" + # python -c "from lightsim2grid.newtonpf import newtonpf" + + # - name: Check LightSimBackend can be imported + # run: | + # python -m pip install grid2op + # python -c "from lightsim2grid import LightSimBackend" + # python -c "from lightsim2grid import LightSimBackend; import grid2op; env = grid2op.make('l2rpn_case14_sandbox', test=True, backend=LightSimBackend())" + + # - name: Upload wheel + # uses: actions/upload-artifact@v2 + # with: + # name: lightsim2grid-wheel-darwin-${{ matrix.python.name }} + # path: dist/*.whl + + macos_build_38_39_310: + name: Build darwin ${{ matrix.python.name }} wheel + runs-on: macos-latest strategy: matrix: - config: - - { - name: darwin, - os: macos-latest, - } python: - - { - name: cp37, - version: '3.7', - } - { name: cp38, version: '3.8', @@ -219,12 +266,8 @@ jobs: name: cp310, version: '3.10', } - - { - name: cp311, - version: '3.11', - } env: - RUNNER_OS: ${{ matrix.config.os }} + RUNNER_OS: macos-latest PYTHON_VERSION: ${{ matrix.python.version }} steps: @@ -245,8 +288,7 @@ jobs: echo "PYTHON_SUBVERSION=$(echo $PYTHON_VERSION | cut -c 3-)" >> $GITHUB_ENV echo "DEPLOY=$( [[ $GITHUB_EVENT_NAME == 'push' && $GITHUB_REF == 'refs/tags'* ]] && echo 'True' || echo 'False' )" >> $GITHUB_ENV - - name: Get CIBUILDWHEEL for python 3.8, 3.9, 3.10 - if: (matrix.config.name == 'darwin') && ((matrix.python.version != 3.7) || (matrix.python.version < '3.11') ) + - name: Compile with cibuildwheel uses: pypa/cibuildwheel@v2.15.0 env: CIBW_BUILD: "cp3${{env.PYTHON_SUBVERSION}}-*" # see https://github.com/cvxpy/cvxpy/blob/master/.github/workflows/build.yml @@ -275,14 +317,14 @@ jobs: - name: Upload wheel uses: actions/upload-artifact@v2 with: - name: lightsim2grid-wheel-${{ matrix.config.name }}-${{ matrix.python.name }} + name: lightsim2grid-wheel-darwin-${{ matrix.python.name }} path: dist/*.whl package: name: Package wheels runs-on: ubuntu-latest - # needs: [manylinux_build, windows_build] - needs: [macos_build] + # needs: [manylinux_build, windows_build, macos_build_37_311, macos_build_38_39_310] + needs: [macos_build_38_39_310] steps: - name: Download wheels From 7661b1e652eb8f0694ede0ccfb0af574dbc0ca92 Mon Sep 17 00:00:00 2001 From: DONNOT Benjamin Date: Tue, 22 Aug 2023 14:47:25 +0200 Subject: [PATCH 15/22] trying to cross compile on macos for M1 / M2 chip --- .github/workflows/main.yml | 28 +++++++++------------------- lightsim2grid/_utils/__init__.py | 11 +++++++++++ lightsim2grid/lightSimBackend.py | 6 +----- 3 files changed, 21 insertions(+), 24 deletions(-) create mode 100644 lightsim2grid/_utils/__init__.py diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a90ee86..44c8071 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -294,25 +294,15 @@ jobs: CIBW_BUILD: "cp3${{env.PYTHON_SUBVERSION}}-*" # see https://github.com/cvxpy/cvxpy/blob/master/.github/workflows/build.yml CIBW_ARCHS_LINUX: auto aarch64 # not used I believe CIBW_ARCHS_MACOS: x86_64 universal2 arm64 - CIBW_BEFORE_ALL: > - make && - export __O3_OPTIM=1 - - - name: Install wheel - shell: bash - run: python -m pip install dist/*.whl --user - - - name: Check package can be imported - run: | - python -c "import lightsim2grid" - python -c "from lightsim2grid import *" - python -c "from lightsim2grid.newtonpf import newtonpf" - - - name: Check LightSimBackend can be imported - run: | - python -m pip install grid2op - python -c "from lightsim2grid import LightSimBackend" - python -c "from lightsim2grid import LightSimBackend; import grid2op; env = grid2op.make('l2rpn_case14_sandbox', test=True, backend=LightSimBackend())" + CIBW_ENVIRONMENT: __O3_OPTIM=1 + CIBW_BEFORE_BUILD: make # and not CIBW_BEFORE_ALL ! + CIBW_TEST_REQUIRES: grid2op numba pandapower packaging + CIBW_TEST_COMMAND: > + python -c "import lightsim2grid" && + python -c "from lightsim2grid import *" && + python -c "from lightsim2grid.newtonpf import newtonpf" && + python -c "from lightsim2grid import LightSimBackend" && + python -c "from lightsim2grid import LightSimBackend; import grid2op; env = grid2op.make('l2rpn_case14_sandbox', test=True, backend=LightSimBackend())" - name: Upload wheel uses: actions/upload-artifact@v2 diff --git a/lightsim2grid/_utils/__init__.py b/lightsim2grid/_utils/__init__.py new file mode 100644 index 0000000..a1b43c0 --- /dev/null +++ b/lightsim2grid/_utils/__init__.py @@ -0,0 +1,11 @@ +# this class is defined to avoid circular references when using grid2op -> pandapower -> lightsim2grid -> grid2op +# this module is lazily imported by the LightSimBackend and should not be used anywhere else, +# as the name states +try: + from grid2op.Backend import PandaPowerBackend + class _DoNotUseAnywherePandaPowerBackend(PandaPowerBackend): + """used to duplicate the class attributes of PandaPowerBackend""" + pass +except ImportError as exc_: + # grid2op is not installed, we do not use it. + pass \ No newline at end of file diff --git a/lightsim2grid/lightSimBackend.py b/lightsim2grid/lightSimBackend.py index 6d38fad..d6b094d 100644 --- a/lightsim2grid/lightSimBackend.py +++ b/lightsim2grid/lightSimBackend.py @@ -58,7 +58,7 @@ def __init__(self, detailed_infos_for_cascading_failures=detailed_infos_for_cascading_failures) # lazy loading because it crashes... - from grid2op.Backend import PandaPowerBackend + from lightsim2grid._utils import _DoNotUseAnywherePandaPowerBackend from grid2op.Space import GridObjects # lazy import self.__has_storage = hasattr(GridObjects, "n_storage") if not self.__has_storage: @@ -85,10 +85,6 @@ def __init__(self, self.topo_vect = None self.shunt_topo_vect = None - class _DoNotUseAnywherePandaPowerBackend(PandaPowerBackend): - """used to duplicate the class attr of PandaPowerBackend""" - pass - try: self.init_pp_backend = _DoNotUseAnywherePandaPowerBackend(with_numba=False) except TypeError as exc_: From c16f1902ceb44dc5d1db74f89f533abbb5de33cb Mon Sep 17 00:00:00 2001 From: DONNOT Benjamin Date: Tue, 22 Aug 2023 14:58:24 +0200 Subject: [PATCH 16/22] trying to cross compile on macos for M1 / M2 chip --- .github/workflows/main.yml | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 44c8071..7c5fc0b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -187,7 +187,7 @@ jobs: # name: lightsim2grid-wheel-${{ matrix.config.name }}-${{ matrix.python.name }} # path: dist/*.whl - # macos_build_37_311: + # macos_build_37: # name: Build macos ${{ matrix.python.name }} wheel # runs-on: macos-latest # strategy: @@ -197,10 +197,6 @@ jobs: # name: cp37, # version: '3.7', # } - # - { - # name: cp311, - # version: '3.11', - # } # steps: # - name: Checkout sources # uses: actions/checkout@v1 @@ -248,7 +244,7 @@ jobs: # name: lightsim2grid-wheel-darwin-${{ matrix.python.name }} # path: dist/*.whl - macos_build_38_39_310: + macos_build_38_: name: Build darwin ${{ matrix.python.name }} wheel runs-on: macos-latest strategy: @@ -266,6 +262,10 @@ jobs: name: cp310, version: '3.10', } + - { + name: cp311, + version: '3.11', + } env: RUNNER_OS: macos-latest PYTHON_VERSION: ${{ matrix.python.version }} @@ -295,12 +295,13 @@ jobs: CIBW_ARCHS_LINUX: auto aarch64 # not used I believe CIBW_ARCHS_MACOS: x86_64 universal2 arm64 CIBW_ENVIRONMENT: __O3_OPTIM=1 - CIBW_BEFORE_BUILD: make # and not CIBW_BEFORE_ALL ! + CIBW_BEFORE_BUILD: make clean && make # and not CIBW_BEFORE_ALL ! CIBW_TEST_REQUIRES: grid2op numba pandapower packaging CIBW_TEST_COMMAND: > python -c "import lightsim2grid" && python -c "from lightsim2grid import *" && python -c "from lightsim2grid.newtonpf import newtonpf" && + python -c "from lightsim2grid.solver import KLUSolver" && python -c "from lightsim2grid import LightSimBackend" && python -c "from lightsim2grid import LightSimBackend; import grid2op; env = grid2op.make('l2rpn_case14_sandbox', test=True, backend=LightSimBackend())" @@ -313,8 +314,8 @@ jobs: package: name: Package wheels runs-on: ubuntu-latest - # needs: [manylinux_build, windows_build, macos_build_37_311, macos_build_38_39_310] - needs: [macos_build_38_39_310] + # needs: [manylinux_build, windows_build, macos_build_37, macos_build_38_] + needs: [macos_build_38_] steps: - name: Download wheels From 33e208ee42a8fefe44ffb7d5c17f61b175b551cc Mon Sep 17 00:00:00 2001 From: DONNOT Benjamin Date: Tue, 22 Aug 2023 15:20:32 +0200 Subject: [PATCH 17/22] trying to cross compile on macos for M1 / M2 chip --- .github/workflows/main.yml | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7c5fc0b..ccd0f49 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -250,18 +250,18 @@ jobs: strategy: matrix: python: - - { - name: cp38, - version: '3.8', - } - - { - name: cp39, - version: '3.9', - } - - { - name: cp310, - version: '3.10', - } + # - { + # name: cp38, + # version: '3.8', + # } + # - { + # name: cp39, + # version: '3.9', + # } + # - { + # name: cp310, + # version: '3.10', + # } - { name: cp311, version: '3.11', @@ -296,7 +296,7 @@ jobs: CIBW_ARCHS_MACOS: x86_64 universal2 arm64 CIBW_ENVIRONMENT: __O3_OPTIM=1 CIBW_BEFORE_BUILD: make clean && make # and not CIBW_BEFORE_ALL ! - CIBW_TEST_REQUIRES: grid2op numba pandapower packaging + CIBW_TEST_REQUIRES: grid2op pandapower CIBW_TEST_COMMAND: > python -c "import lightsim2grid" && python -c "from lightsim2grid import *" && @@ -306,10 +306,10 @@ jobs: python -c "from lightsim2grid import LightSimBackend; import grid2op; env = grid2op.make('l2rpn_case14_sandbox', test=True, backend=LightSimBackend())" - name: Upload wheel - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: - name: lightsim2grid-wheel-darwin-${{ matrix.python.name }} - path: dist/*.whl + name: wheels + path: ./wheelhouse/*.whl package: name: Package wheels From 477a804dd417e26e079b7a07aac7b71906ecca39 Mon Sep 17 00:00:00 2001 From: DONNOT Benjamin Date: Tue, 22 Aug 2023 15:41:40 +0200 Subject: [PATCH 18/22] trying to cross compile on macos for M1 / M2 chip --- .github/workflows/main.yml | 40 +++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ccd0f49..e13ca5a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -44,7 +44,7 @@ jobs: # steps: # - name: Checkout sources - # uses: actions/checkout@v1 + # uses: actions/checkout@v3 # with: # submodules: true @@ -134,12 +134,12 @@ jobs: # steps: # - name: Checkout sources - # uses: actions/checkout@v1 + # uses: actions/checkout@v3 # with: # submodules: true # - name: Setup Python - # uses: actions/setup-python@v2 + # uses: actions/setup-python@v4 # with: # python-version: ${{ matrix.python.version }} @@ -199,12 +199,12 @@ jobs: # } # steps: # - name: Checkout sources - # uses: actions/checkout@v1 + # uses: actions/checkout@v3 # with: # submodules: true # - name: Setup Python - # uses: actions/setup-python@v2 + # uses: actions/setup-python@v4 # with: # python-version: ${{ matrix.python.version }} @@ -250,18 +250,18 @@ jobs: strategy: matrix: python: - # - { - # name: cp38, - # version: '3.8', - # } - # - { - # name: cp39, - # version: '3.9', - # } - # - { - # name: cp310, - # version: '3.10', - # } + - { + name: cp38, + version: '3.8', + } + - { + name: cp39, + version: '3.9', + } + - { + name: cp310, + version: '3.10', + } - { name: cp311, version: '3.11', @@ -273,12 +273,12 @@ jobs: steps: - name: Checkout sources - uses: actions/checkout@v1 + uses: actions/checkout@v3 with: submodules: true - name: Setup Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: ${{ matrix.python.version }} @@ -308,7 +308,7 @@ jobs: - name: Upload wheel uses: actions/upload-artifact@v3 with: - name: wheels + name: wheels-darwin-${{ matrix.python.name }} path: ./wheelhouse/*.whl package: From 9d784511b2d4479a0a4b793dcb0124e4a4154351 Mon Sep 17 00:00:00 2001 From: DONNOT Benjamin Date: Tue, 22 Aug 2023 16:12:57 +0200 Subject: [PATCH 19/22] re evaluating the full ci pipeline again --- .circleci/{old_config.yml => config.yml} | 0 .github/workflows/main.yml | 476 ++++++++++++----------- README.md | 3 + 3 files changed, 243 insertions(+), 236 deletions(-) rename .circleci/{old_config.yml => config.yml} (100%) diff --git a/.circleci/old_config.yml b/.circleci/config.yml similarity index 100% rename from .circleci/old_config.yml rename to .circleci/config.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e13ca5a..346fc30 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,243 +8,247 @@ on: - 'v*.*.*' jobs: - # manylinux_build: - # name: Build linux ${{ matrix.python.name }} wheel - # runs-on: ubuntu-latest - # container: quay.io/pypa/manylinux2014_x86_64 - # strategy: - # matrix: - # python: - # - { - # name: cp37, - # abi: cp37m, - # version: '3.7', - # } - # - { - # name: cp38, - # abi: cp38, - # version: '3.8', - # } - # - { - # name: cp39, - # abi: cp39, - # version: '3.9', - # } - # - { - # name: cp310, - # abi: cp310, - # version: '3.10', - # } - # - { - # name: cp311, - # abi: cp311, - # version: '3.11', - # } - - # steps: - - # - name: Checkout sources - # uses: actions/checkout@v3 - # with: - # submodules: true - - # - name: Setup path - # run: echo "/opt/python/${{ matrix.python.name }}-${{ matrix.python.abi }}/bin/" >> $GITHUB_PATH - - # - name: Install Python dependencies - # run: | - # python -m pip install --upgrade pip - # python -m pip install -r requirements.txt - - # - name: Compile SuiteSparse - # run: make - - # - name: Build wheel - # run: | - # # export __O3_OPTIM=1 - # python3 setup.py bdist_wheel - # auditwheel repair dist/*.whl - - # - name: Build source archive - # if: matrix.python.name == 'cp311' - # run: python setup.py sdist - - # - name: Install wheel - # run: pip3 install wheelhouse/*.whl --user - - # - name: Install GDB - # run: yum install -y gdb - - # - name: Check package can be imported - # run: | - # # python3 -c "import lightsim2grid" - # # python3 -c "from lightsim2grid import *" - # # python3 -c "from lightsim2grid.newtonpf import newtonpf" - # gdb -batch -ex r --args python3 -c "from lightsim2grid import *" -ex backtrace - - # - name: Check LightSimBackend can be imported - # run: | - # python3 -m pip install grid2op - # python3 -c "from lightsim2grid import LightSimBackend" - # python3 -c "from lightsim2grid import LightSimBackend; import grid2op; env = grid2op.make('l2rpn_case14_sandbox', test=True, backend=LightSimBackend())" - - # - name: Upload wheel - # uses: actions/upload-artifact@v2 - # with: - # name: lightsim2grid-wheel-linux-${{ matrix.python.name }} - # path: wheelhouse/*.whl - - # - name: Upload source archive - # uses: actions/upload-artifact@v2 - # if: matrix.python.name == 'cp311' - # with: - # name: lightsim2grid-sources - # path: dist/*.tar.gz - - # windows_build: - # name: Build windows ${{ matrix.python.name }} wheel - # runs-on: windows-2019 - # strategy: - # matrix: - # python: - # - { - # name: cp37, - # version: '3.7', - # } - # - { - # name: cp38, - # version: '3.8', - # } - # - { - # name: cp39, - # version: '3.9', - # } - # - { - # name: cp310, - # version: '3.10', - # } - # - { - # name: cp311, - # version: '3.11', - # } - # env: - # RUNNER_OS: windows-2019 - # PYTHON_VERSION: ${{ matrix.python.version }} - - # steps: - - # - name: Checkout sources - # uses: actions/checkout@v3 - # with: - # submodules: true - - # - name: Setup Python - # uses: actions/setup-python@v4 - # with: - # python-version: ${{ matrix.python.version }} - - # - name: Install Python dependencies - # run: | - # python -m pip install --upgrade pip - # python -m pip install -r requirements.txt - - # - name: Compile SuiteSparse cmake - # run: | - # cd build_cmake - # python generate_c_files.py - # mkdir build - # cd build - # cmake -DCMAKE_INSTALL_PREFIX=..\built -DCMAKE_BUILD_TYPE=Release .. - # cmake --build . --config Release - # cmake --install . --prefix ..\built - # cd .. - # cd .. - # set __O3_OPTIM=1 - # python setup.py build - - # - name: Build wheel - # run: python setup.py bdist_wheel - - # - name: Install wheel - # shell: bash - # run: python -m pip install dist/*.whl --user - - # - name: Check package can be imported - # run: | - # python -c "import lightsim2grid" - # python -c "from lightsim2grid import *" - # python -c "from lightsim2grid.newtonpf import newtonpf" + manylinux_build: + # build wheels for some linux + name: Build linux ${{ matrix.python.name }} wheel + runs-on: ubuntu-latest + container: quay.io/pypa/manylinux2014_x86_64 + strategy: + matrix: + python: + - { + name: cp37, + abi: cp37m, + version: '3.7', + } + - { + name: cp38, + abi: cp38, + version: '3.8', + } + - { + name: cp39, + abi: cp39, + version: '3.9', + } + - { + name: cp310, + abi: cp310, + version: '3.10', + } + - { + name: cp311, + abi: cp311, + version: '3.11', + } + + steps: + + - name: Checkout sources + uses: actions/checkout@v3 + with: + submodules: true + + - name: Setup path + run: echo "/opt/python/${{ matrix.python.name }}-${{ matrix.python.abi }}/bin/" >> $GITHUB_PATH + + - name: Install Python dependencies + run: | + python -m pip install --upgrade pip + python -m pip install -r requirements.txt + + - name: Compile SuiteSparse + run: make + + - name: Build wheel + run: | + # export __O3_OPTIM=1 + python3 setup.py bdist_wheel + auditwheel repair dist/*.whl + + - name: Build source archive + if: matrix.python.name == 'cp311' + run: python setup.py sdist + + - name: Install wheel + run: pip3 install wheelhouse/*.whl --user + + - name: Install GDB + run: yum install -y gdb + + - name: Check package can be imported + run: | + # python3 -c "import lightsim2grid" + # python3 -c "from lightsim2grid import *" + # python3 -c "from lightsim2grid.newtonpf import newtonpf" + gdb -batch -ex r --args python3 -c "from lightsim2grid import *" -ex backtrace + + - name: Check LightSimBackend can be imported + run: | + python3 -m pip install grid2op + python3 -c "from lightsim2grid import LightSimBackend" + python3 -c "from lightsim2grid import LightSimBackend; import grid2op; env = grid2op.make('l2rpn_case14_sandbox', test=True, backend=LightSimBackend())" + + - name: Upload wheel + uses: actions/upload-artifact@v2 + with: + name: lightsim2grid-wheel-linux-${{ matrix.python.name }} + path: wheelhouse/*.whl + + - name: Upload source archive + uses: actions/upload-artifact@v2 + if: matrix.python.name == 'cp311' + with: + name: lightsim2grid-sources + path: dist/*.tar.gz + + windows_build: + # build wheels for windows + name: Build windows ${{ matrix.python.name }} wheel + runs-on: windows-2019 + strategy: + matrix: + python: + - { + name: cp37, + version: '3.7', + } + - { + name: cp38, + version: '3.8', + } + - { + name: cp39, + version: '3.9', + } + - { + name: cp310, + version: '3.10', + } + - { + name: cp311, + version: '3.11', + } + env: + RUNNER_OS: windows-2019 + PYTHON_VERSION: ${{ matrix.python.version }} + + steps: + + - name: Checkout sources + uses: actions/checkout@v3 + with: + submodules: true + + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python.version }} + + - name: Install Python dependencies + run: | + python -m pip install --upgrade pip + python -m pip install -r requirements.txt + + - name: Compile SuiteSparse cmake + run: | + cd build_cmake + python generate_c_files.py + mkdir build + cd build + cmake -DCMAKE_INSTALL_PREFIX=..\built -DCMAKE_BUILD_TYPE=Release .. + cmake --build . --config Release + cmake --install . --prefix ..\built + cd .. + cd .. + set __O3_OPTIM=1 + python setup.py build + + - name: Build wheel + run: python setup.py bdist_wheel + + - name: Install wheel + shell: bash + run: python -m pip install dist/*.whl --user + + - name: Check package can be imported + run: | + python -c "import lightsim2grid" + python -c "from lightsim2grid import *" + python -c "from lightsim2grid.newtonpf import newtonpf" - # - name: Check LightSimBackend can be imported - # run: | - # python -m pip install grid2op - # python -c "from lightsim2grid import LightSimBackend" - # python -c "from lightsim2grid import LightSimBackend; import grid2op; env = grid2op.make('l2rpn_case14_sandbox', test=True, backend=LightSimBackend())" - - # - name: Upload wheel - # uses: actions/upload-artifact@v2 - # with: - # name: lightsim2grid-wheel-${{ matrix.config.name }}-${{ matrix.python.name }} - # path: dist/*.whl - - # macos_build_37: - # name: Build macos ${{ matrix.python.name }} wheel - # runs-on: macos-latest - # strategy: - # matrix: - # python: - # - { - # name: cp37, - # version: '3.7', - # } - # steps: - # - name: Checkout sources - # uses: actions/checkout@v3 - # with: - # submodules: true - - # - name: Setup Python - # uses: actions/setup-python@v4 - # with: - # python-version: ${{ matrix.python.version }} - - # - name: Install Python dependencies - # run: | - # python -m pip install --upgrade pip - # python -m pip install -r requirements.txt - - # - name: Compile SuiteSparse make - # run: | - # make - # export __O3_OPTIM=1 - # python3 setup.py build - - # - name: Build wheel - # run: python setup.py bdist_wheel - - # - name: Install wheel - # shell: bash - # run: python -m pip install dist/*.whl --user - - # - name: Check package can be imported - # run: | - # python -c "import lightsim2grid" - # python -c "from lightsim2grid import *" - # python -c "from lightsim2grid.newtonpf import newtonpf" + - name: Check LightSimBackend can be imported + run: | + python -m pip install grid2op + python -c "from lightsim2grid import LightSimBackend" + python -c "from lightsim2grid import LightSimBackend; import grid2op; env = grid2op.make('l2rpn_case14_sandbox', test=True, backend=LightSimBackend())" + + - name: Upload wheel + uses: actions/upload-artifact@v2 + with: + name: lightsim2grid-wheel-${{ matrix.config.name }}-${{ matrix.python.name }} + path: dist/*.whl + + macos_build_37: + # build wheel for python 3.7 for macos + name: Build macos ${{ matrix.python.name }} wheel + runs-on: macos-latest + strategy: + matrix: + python: + - { + name: cp37, + version: '3.7', + } + steps: + - name: Checkout sources + uses: actions/checkout@v3 + with: + submodules: true + + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python.version }} + + - name: Install Python dependencies + run: | + python -m pip install --upgrade pip + python -m pip install -r requirements.txt + + - name: Compile SuiteSparse make + run: | + make + export __O3_OPTIM=1 + python3 setup.py build + + - name: Build wheel + run: python setup.py bdist_wheel + + - name: Install wheel + shell: bash + run: python -m pip install dist/*.whl --user + + - name: Check package can be imported + run: | + python -c "import lightsim2grid" + python -c "from lightsim2grid import *" + python -c "from lightsim2grid.newtonpf import newtonpf" - # - name: Check LightSimBackend can be imported - # run: | - # python -m pip install grid2op - # python -c "from lightsim2grid import LightSimBackend" - # python -c "from lightsim2grid import LightSimBackend; import grid2op; env = grid2op.make('l2rpn_case14_sandbox', test=True, backend=LightSimBackend())" - - # - name: Upload wheel - # uses: actions/upload-artifact@v2 - # with: - # name: lightsim2grid-wheel-darwin-${{ matrix.python.name }} - # path: dist/*.whl + - name: Check LightSimBackend can be imported + run: | + python -m pip install grid2op + python -c "from lightsim2grid import LightSimBackend" + python -c "from lightsim2grid import LightSimBackend; import grid2op; env = grid2op.make('l2rpn_case14_sandbox', test=True, backend=LightSimBackend())" + + - name: Upload wheel + uses: actions/upload-artifact@v2 + with: + name: lightsim2grid-wheel-darwin-${{ matrix.python.name }} + path: dist/*.whl macos_build_38_: + # build wheel for python 3.8 and above for macos name: Build darwin ${{ matrix.python.name }} wheel runs-on: macos-latest strategy: @@ -293,10 +297,11 @@ jobs: env: CIBW_BUILD: "cp3${{env.PYTHON_SUBVERSION}}-*" # see https://github.com/cvxpy/cvxpy/blob/master/.github/workflows/build.yml CIBW_ARCHS_LINUX: auto aarch64 # not used I believe - CIBW_ARCHS_MACOS: x86_64 universal2 arm64 + CIBW_ARCHS_MACOS: x86_64 arm64 CIBW_ENVIRONMENT: __O3_OPTIM=1 CIBW_BEFORE_BUILD: make clean && make # and not CIBW_BEFORE_ALL ! CIBW_TEST_REQUIRES: grid2op pandapower + CIBW_TEST_SKIP: "*-macosx_arm64" # 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 *" && @@ -314,8 +319,7 @@ jobs: package: name: Package wheels runs-on: ubuntu-latest - # needs: [manylinux_build, windows_build, macos_build_37, macos_build_38_] - needs: [macos_build_38_] + needs: [manylinux_build, windows_build, macos_build_37, macos_build_38_] steps: - name: Download wheels diff --git a/README.md b/README.md index e3db132..57cb87d 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,9 @@ Pypi packages are available for linux, windows and macos with python versions: - 3.10 (lightsim2grid >= 0.6.1) - 3.11 (lightsim2grid >= 0.7.1) +**NB** on some version of MacOs (thanks Apple !), especially the one using M1 or M2 chip, lightsim2grid is only available +on pypi starting from version 0.7.3 + ## Installation (from source, for more advanced user) See the official documentation at [Install from source](https://lightsim2grid.readthedocs.io/en/latest/install_from_source.html) for more information From 635b84dab0579c579c8e198f024074eab626656b Mon Sep 17 00:00:00 2001 From: DONNOT Benjamin Date: Tue, 22 Aug 2023 16:46:42 +0200 Subject: [PATCH 20/22] bump to actions/upload-artifact@v3 [skip ci] --- .github/workflows/main.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 346fc30..f361d22 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -90,13 +90,13 @@ jobs: python3 -c "from lightsim2grid import LightSimBackend; import grid2op; env = grid2op.make('l2rpn_case14_sandbox', test=True, backend=LightSimBackend())" - name: Upload wheel - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: lightsim2grid-wheel-linux-${{ matrix.python.name }} path: wheelhouse/*.whl - name: Upload source archive - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 if: matrix.python.name == 'cp311' with: name: lightsim2grid-sources @@ -184,7 +184,7 @@ jobs: python -c "from lightsim2grid import LightSimBackend; import grid2op; env = grid2op.make('l2rpn_case14_sandbox', test=True, backend=LightSimBackend())" - name: Upload wheel - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: lightsim2grid-wheel-${{ matrix.config.name }}-${{ matrix.python.name }} path: dist/*.whl @@ -242,7 +242,7 @@ jobs: python -c "from lightsim2grid import LightSimBackend; import grid2op; env = grid2op.make('l2rpn_case14_sandbox', test=True, backend=LightSimBackend())" - name: Upload wheel - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: lightsim2grid-wheel-darwin-${{ matrix.python.name }} path: dist/*.whl @@ -323,12 +323,12 @@ jobs: steps: - name: Download wheels - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v3 with: path: download - name: Upload wheels - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: lightsim2grid-wheels path: | From b318a3825016b0c48b7dd201bd9c8b14f84ac9e5 Mon Sep 17 00:00:00 2001 From: DONNOT Benjamin Date: Thu, 24 Aug 2023 09:10:14 +0200 Subject: [PATCH 21/22] ready for version 0.7.4 --- CHANGELOG.rst | 2 +- docs/conf.py | 2 +- lightsim2grid/__init__.py | 2 +- setup.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index e7ee146..bda46b0 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -19,7 +19,7 @@ Change Log - easier building (get rid of the "make" part) - code NR with dense matrices -[0.7.3] 2023-08-xx +[0.7.3] 2023-08-24 -------------------- - [FIXED] a bug where, when you disconnect a load (or gen), the next action cannot be performed if it modifies the load (or gen), because you "cannot change the value of a disconnected load (or gen)" diff --git a/docs/conf.py b/docs/conf.py index 62b0f0d..8b64a4f 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -22,7 +22,7 @@ author = 'Benjamin DONNOT' # The full version, including alpha/beta/rc tags -release = "0.7.3" +release = "0.7.4" version = '0.7' # -- General configuration --------------------------------------------------- diff --git a/lightsim2grid/__init__.py b/lightsim2grid/__init__.py index c99bdce..f7d6d89 100644 --- a/lightsim2grid/__init__.py +++ b/lightsim2grid/__init__.py @@ -9,7 +9,7 @@ import faulthandler faulthandler.enable() -__version__ = "0.7.3" +__version__ = "0.7.4" __all__ = ["newtonpf", "SolverType", "ErrorType", "solver"] diff --git a/setup.py b/setup.py index dbe1a27..2025432 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ from pybind11.setup_helpers import Pybind11Extension, build_ext -__version__ = "0.7.3" +__version__ = "0.7.4" KLU_SOLVER_AVAILABLE = False # Try to link against SuiteSparse (if available) From 69d81281b226ed60e6efa2f62861fd3f67225964 Mon Sep 17 00:00:00 2001 From: DONNOT Benjamin Date: Thu, 24 Aug 2023 09:30:39 +0200 Subject: [PATCH 22/22] small modification to fix issue spotted in sim2real in grid2op --- lightsim2grid/lightSimBackend.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lightsim2grid/lightSimBackend.py b/lightsim2grid/lightSimBackend.py index d6b094d..7a0ce86 100644 --- a/lightsim2grid/lightSimBackend.py +++ b/lightsim2grid/lightSimBackend.py @@ -84,7 +84,6 @@ def __init__(self, self.topo_vect = None self.shunt_topo_vect = None - try: self.init_pp_backend = _DoNotUseAnywherePandaPowerBackend(with_numba=False) except TypeError as exc_: @@ -607,8 +606,8 @@ def assert_grid_correct_after_powerflow(self): """ # test the results gives the proper size super().assert_grid_correct_after_powerflow() - # self.init_pp_backend.__class__ = self.init_pp_backend.init_grid(self) - self._backend_action_class = _BackendAction.init_grid(self) + self.init_pp_backend.__class__ = type(self.init_pp_backend).init_grid(type(self)) + self._backend_action_class = _BackendAction.init_grid(type(self)) self._init_action_to_set = self._backend_action_class() try: # feature added in grid2op 1.4 or 1.5