BDonnot / lightsim2grid

LightSim2grid implements a c++ backend targeting the Grid2Op (https://github.com/rte-france/grid2op) platform.
https://lightsim2grid.readthedocs.io/en/latest/
Mozilla Public License 2.0
46 stars 9 forks source link

Installation/Setup fails on macOS #59

Closed LucaCras closed 9 months ago

LucaCras commented 1 year ago

Environment

Note: If the bug concerns an installation issue, you have to provide us with the output of:

python3 setup.py build

output:

Building wheels for collected packages: lightsim2grid
  Building wheel for lightsim2grid (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Building wheel for lightsim2grid (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [42 lines of output]
      <string>:93: UserWarning: SuiteSparse is not available on your system, or has not been compiled. The faster "KLU" linear algebra solver will not be available. The "SparseLU" solver will however be available, which is maybe ~30% slower than "KLU". If you are using grid2op there will still be a huge benefit.
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.macosx-10.9-x86_64-cpython-310
      creating build/lib.macosx-10.9-x86_64-cpython-310/lightsim2grid
      copying lightsim2grid/__init__.py -> build/lib.macosx-10.9-x86_64-cpython-310/lightsim2grid
      copying lightsim2grid/securityAnalysis.py -> build/lib.macosx-10.9-x86_64-cpython-310/lightsim2grid
      copying lightsim2grid/lightSimBackend.py -> build/lib.macosx-10.9-x86_64-cpython-310/lightsim2grid
      copying lightsim2grid/timeSerie.py -> build/lib.macosx-10.9-x86_64-cpython-310/lightsim2grid
      copying lightsim2grid/physical_law_checker.py -> build/lib.macosx-10.9-x86_64-cpython-310/lightsim2grid
      creating build/lib.macosx-10.9-x86_64-cpython-310/lightsim2grid/solver
      copying lightsim2grid/solver/__init__.py -> build/lib.macosx-10.9-x86_64-cpython-310/lightsim2grid/solver
      creating build/lib.macosx-10.9-x86_64-cpython-310/lightsim2grid/newtonpf
      copying lightsim2grid/newtonpf/__init__.py -> build/lib.macosx-10.9-x86_64-cpython-310/lightsim2grid/newtonpf
      copying lightsim2grid/newtonpf/newtonpf.py -> build/lib.macosx-10.9-x86_64-cpython-310/lightsim2grid/newtonpf
      creating build/lib.macosx-10.9-x86_64-cpython-310/lightsim2grid/elements
      copying lightsim2grid/elements/__init__.py -> build/lib.macosx-10.9-x86_64-cpython-310/lightsim2grid/elements
      creating build/lib.macosx-10.9-x86_64-cpython-310/lightsim2grid/gridmodel
      copying lightsim2grid/gridmodel/_aux_add_shunt.py -> build/lib.macosx-10.9-x86_64-cpython-310/lightsim2grid/gridmodel
      copying lightsim2grid/gridmodel/_aux_add_slack.py -> build/lib.macosx-10.9-x86_64-cpython-310/lightsim2grid/gridmodel
      copying lightsim2grid/gridmodel/initGridModel.py -> build/lib.macosx-10.9-x86_64-cpython-310/lightsim2grid/gridmodel
      copying lightsim2grid/gridmodel/_aux_add_sgen.py -> build/lib.macosx-10.9-x86_64-cpython-310/lightsim2grid/gridmodel
      copying lightsim2grid/gridmodel/_aux_add_gen.py -> build/lib.macosx-10.9-x86_64-cpython-310/lightsim2grid/gridmodel
      copying lightsim2grid/gridmodel/_aux_add_storage.py -> build/lib.macosx-10.9-x86_64-cpython-310/lightsim2grid/gridmodel
      copying lightsim2grid/gridmodel/_aux_add_line.py -> build/lib.macosx-10.9-x86_64-cpython-310/lightsim2grid/gridmodel
      copying lightsim2grid/gridmodel/__init__.py -> build/lib.macosx-10.9-x86_64-cpython-310/lightsim2grid/gridmodel
      copying lightsim2grid/gridmodel/_aux_add_trafo.py -> build/lib.macosx-10.9-x86_64-cpython-310/lightsim2grid/gridmodel
      copying lightsim2grid/gridmodel/_aux_add_load.py -> build/lib.macosx-10.9-x86_64-cpython-310/lightsim2grid/gridmodel
      copying lightsim2grid/gridmodel/_aux_check_legit.py -> build/lib.macosx-10.9-x86_64-cpython-310/lightsim2grid/gridmodel
      running build_ext
      clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /Users/luca/opt/anaconda3/envs/idmp/include -fPIC -O2 -isystem /Users/luca/opt/anaconda3/envs/idmp/include -I/Users/luca/opt/anaconda3/envs/idmp/include/python3.10 -c flagcheck.cpp -o flagcheck.o -std=c++17
      building 'lightsim2grid_cpp' extension
      creating build/temp.macosx-10.9-x86_64-cpython-310
      creating build/temp.macosx-10.9-x86_64-cpython-310/src
      clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /Users/luca/opt/anaconda3/envs/idmp/include -fPIC -O2 -isystem /Users/luca/opt/anaconda3/envs/idmp/include -I/private/var/folders/yb/r9d2wh593cs_d4rdycvq35080000gn/T/pip-install-80hkctug/lightsim2grid_fdb8430a33344d21a9ae0ff5dffbb173/eigen -I/private/var/folders/yb/r9d2wh593cs_d4rdycvq35080000gn/T/pip-build-env-n12lcf1f/overlay/lib/python3.10/site-packages/pybind11/include -I/Users/luca/opt/anaconda3/envs/idmp/include/python3.10 -c src/BaseConstants.cpp -o build/temp.macosx-10.9-x86_64-cpython-310/src/BaseConstants.o -std=c++17 -mmacosx-version-min=10.14 -fvisibility=hidden -g0 -stdlib=libc++ -DNDEBUG -DVERSION_MAJOR=0 -DVERSION_MEDIUM=7 -DVERSION_MINOR=1
      src/BaseConstants.cpp:9:10: fatal error: 'BaseConstants.h' file not found
      #include "BaseConstants.h"
               ^~~~~~~~~~~~~~~~~
      1 error generated.
      error: command '/usr/bin/clang' failed with exit code 1
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for lightsim2grid
Failed to build lightsim2grid
ERROR: Could not build wheels for lightsim2grid, which is required to install pyproject.toml-based projects

Bug description

Cannot install lightsim2grid on macOS...

How to reproduce

  1. run: pip install lightsim2grid
  2. build fails
BDonnot commented 1 year ago

Hello,

Thanks for reporting this issue.

Did you clone it from github ? Or just typed "pip install lightsim2grid" ?

The error you sent does not look like it came from "python3 setup.py build" but rather from "pip install lightsim2grid". It would help if you could send it to me.

Otherwise, you can install the "whl" you find here : https://github.com/BDonnot/lightsim2grid/suites/12553865846/artifacts/670809515 (it will be the same file as the one used when you install lightsim2grid through pip). To install it from there unzip it, and type pip install LightSim2Grid-0.7.2.dev1-cp310-cp310-macosx_11_0_x86_64.whl (for the version I sent)

LucaCras commented 1 year ago

I, indeed, tried installing through pip.

I also tried your workaround, but I get the following error (maybe I need a different build wheel, but I don't know where to find them): ERROR: LightSim2Grid-0.7.2.dev1-cp310-cp310-macosx_11_0_x86_64.whl is not a supported wheel on this platform.

LucaCras commented 1 year ago

Installation through github cloning worked.

BDonnot commented 1 year ago

Hello,

Thanks for the answers. Glad to see it worked from source. I'll try to find out why your system does not like the whl provided.

Are you running a 32bits system?

MuhaoGuo commented 11 months ago

I have tried "pip install lightsim2grid" and I got the same error as the author. I have tried installing the wheel from the link you have shared and I got the same error as the author. I have tried "installation from source" like the author mentioned which includes git clone, git submodule init, git submodule update, pip install -U pybind11, pip install -U . . However, I got the following error for git submodule update: fatal: unable to access 'https://github.com/DrTimothyAldenDavis/SuiteSparse/': Recv failure: Operation timed out fatal: clone of 'https://github.com/DrTimothyAldenDavis/SuiteSparse' into submodule path '/Users

Please help install lightsim2grid so I can install l2rpn_baselines following that.

BDonnot commented 11 months ago

Hello,

Github might have been experiencing some bugs when you ran the "git submodule init" or "got submodule update" have you tried multiple times? Can you retry now?

Sorry for the issue, when I'll be back from holiday I'll try to find a more permanent solutions for arm build (I suspect your computer has an M1 or M2 chip with is arm64 and not a "regular" x32 or x86_x64 processor).

MuhaoGuo commented 11 months ago

Yes, I did it another time, and it works. Thank you! My computer has an M2 chip.

BDonnot commented 11 months ago

Hello @LucaCras @MuhaoGuo

Can you try to download the appropriate wheel that you can find here: https://github.com/BDonnot/lightsim2grid/actions/runs/5939654212 (if using python 3.10 then download the wheels-darwin-cp310 - cp310 stands for "c python 3.10"-, unzip it and then use the LightSim2Grid-0.7.3-cp3xx-cp3xx-macosx_11_0_arm64.whl - important part is arm64 here) (replace cp310 with eg cp39 if using python 3.9 or cp311 if using python 3.11 etc.)

And then install it on your Mac, eg with (if using python 3.10 on your mac)

pip install LightSim2Grid-0.7.3-cp310-cp310-macosx_11_0_arm64.whl

and let me know if this works for you ? If so i'll add it to pypi for next lightsim2grid version (coming soon)

Thanks a lot :-)

BDonnot commented 11 months ago

Also, I leave it here if problem like this arises again, Apple provide a way to use a x86 (64 bits) package on their machine with the "Rosetta 2 emulation" as said here https://cibuildwheel.readthedocs.io/en/stable/faq/#apple-silicon (paragraph x86_64) and with a way to activate it here https://stackoverflow.com/questions/71691598/how-to-run-python-as-x86-with-rosetta2-on-arm-macos-machine:

Conda can create x86 environments on Mac Arm.

    Install [miniconda](https://docs.conda.io/en/main/miniconda.html)
    Create an environment configured for x86

    conda create -n my_x86_env -y
    conda activate my_x86_env
    conda config --env --set subdir osx-64

    Install whichever version of Python you want

    conda install python=3.10

    Install packages using conda or pip

    conda install numpy
    pip install networkx

For this environment (my_x86_env), python and pip are x86 versions so they will only grab x86 versions from anaconda, conda-forge, and pypi. Any environments you create without running conda config --env --set subdir osx-64 will be arm64 environments. So you can get the native speed when you want it and the compatibility with x86-only packages when you need it.

(I just copy pasted the best answer there, did not tested it...)

BDonnot commented 9 months ago

Let me know if latest version (0.7.5) solves this issue, i made some change in the continuous integration in hope it fixes the issue. As I don't own a Mac debugging this is really slow.

In the mean time i'll close this.