Skip to content

Commit

Permalink
pyproject, etc: Migrate MESMO to poetry & update installation instruc…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
stroitzsch committed Oct 9, 2023
1 parent f20ff4b commit 76af995
Show file tree
Hide file tree
Showing 14 changed files with 2,821 additions and 268 deletions.
58 changes: 29 additions & 29 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,34 @@ jobs:
runs-on: ubuntu-latest
defaults:
run:
shell: bash -l {0} # Required for conda commands.
shell: bash -l {0} # Required for conda commands.

steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
ref: develop # Checkout `develop` branch to build documentation instead of using current branch / commit.
fetch-depth: 0 # Fetch all branches and tags, to build documentation for all branches and tags.
submodules: false # Not needed to build documentation.
- name: Set up Python
uses: conda-incubator/setup-miniconda@v2
with:
python-version: 3.8
- name: Install dependencies
run: |
conda install sphinx
pip install -r docs/requirements.txt
- name: Build documentation HTML with Sphinx
run: |
sphinx-multiversion docs docs/_build/html
cp docs/assets/gh-pages_index.html docs/_build/html/index.html
- name: Deploy documentation HTML to Github Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: docs/_build/html/
keep_files: false
force_orphan: true
full_commit_message: Deploy documentation for ${{ github.sha }}
user_name: MESMO Bot
user_email: bot@mesmo.dev
- name: Checkout repository
uses: actions/checkout@v2
with:
ref: develop # Checkout `develop` branch to build documentation instead of using current branch / commit.
fetch-depth: 0 # Fetch all branches and tags, to build documentation for all branches and tags.
submodules: false # Not needed to build documentation.
- name: Set up Python
uses: conda-incubator/setup-miniconda@v2
with:
python-version: 3.8
- name: Install dependencies
run: |
conda install sphinx
pip install -r docs/requirements.txt
- name: Build documentation HTML with Sphinx
run: |
sphinx-multiversion docs docs/_build/html
cp docs/assets/gh-pages_index.html docs/_build/html/index.html
- name: Deploy documentation HTML to Github Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: docs/_build/html/
keep_files: false
force_orphan: true
full_commit_message: Deploy documentation for ${{ github.sha }}
user_name: MESMO Bot
user_email: bot@mesmo.dev
108 changes: 52 additions & 56 deletions .github/workflows/maintenance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,32 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [
windows-latest,
macos-latest,
ubuntu-latest
]
os: [windows-latest, macos-latest, ubuntu-latest]
defaults:
run:
shell: bash -l {0} # Required for conda commands.
shell: bash -l {0} # Required for conda commands.

steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
submodules: recursive
- name: Set up Python
uses: conda-incubator/setup-miniconda@v2
- name: Install dependencies
run: |
conda create -n mesmo -c conda-forge python=3.10 contextily cvxpy numpy pandas scipy
conda activate mesmo
python development_setup.py
- name: Get new environment-${{ matrix.os }}.yml
run: |
rm -f environment-*
conda env export -n mesmo --no-builds | grep -v "^prefix: " > environment-${{ matrix.os }}.yml
- name: Store environment-${{ matrix.os }}.yml
uses: actions/upload-artifact@v2
with:
name: environment-${{ matrix.os }}.yml
path: environment-${{ matrix.os }}.yml
- name: Checkout repository
uses: actions/checkout@v2
with:
submodules: recursive
- name: Set up Python
uses: conda-incubator/setup-miniconda@v2
- name: Install dependencies
run: |
conda create -n mesmo -c conda-forge python=3.10 contextily
conda activate mesmo
python development_setup.py
- name: Get new environment-${{ matrix.os }}.yml
run: |
rm -f environment-*
conda env export -n mesmo --no-builds | grep -v "^prefix: " > environment-${{ matrix.os }}.yml
- name: Store environment-${{ matrix.os }}.yml
uses: actions/upload-artifact@v2
with:
name: environment-${{ matrix.os }}.yml
path: environment-${{ matrix.os }}.yml

run-maintenance:
needs: get-environment
Expand All @@ -51,33 +47,33 @@ jobs:
shell: bash -l {0}

steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
token: ${{ secrets.MESMO_BOT_PAT }}
- name: Remove old environment files
run: |
rm -f environment-*
- name: Get cached environment-windows-latest.yml
uses: actions/download-artifact@v2
with:
name: environment-windows-latest.yml
- name: Get cached environment-macos-latest.yml
uses: actions/download-artifact@v2
with:
name: environment-macos-latest.yml
- name: Get cached environment-ubuntu-latest.yml
uses: actions/download-artifact@v2
with:
name: environment-ubuntu-latest.yml
- name: Run automatic code formatting
uses: psf/black@stable
with:
options: "--line-length 120"
# For future reference: Exclude submodules if this runs too long.
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Automated maintenance for ${{ github.sha }}
commit_user_name: MESMO Bot
commit_user_email: bot@mesmo.dev
- name: Checkout repository
uses: actions/checkout@v2
with:
token: ${{ secrets.MESMO_BOT_PAT }}
- name: Remove old environment files
run: |
rm -f environment-*
- name: Get cached environment-windows-latest.yml
uses: actions/download-artifact@v2
with:
name: environment-windows-latest.yml
- name: Get cached environment-macos-latest.yml
uses: actions/download-artifact@v2
with:
name: environment-macos-latest.yml
- name: Get cached environment-ubuntu-latest.yml
uses: actions/download-artifact@v2
with:
name: environment-ubuntu-latest.yml
- name: Run automatic code formatting
uses: psf/black@stable
with:
options: "--line-length 120"
# For future reference: Exclude submodules if this runs too long.
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Automated maintenance for ${{ github.sha }}
commit_user_name: MESMO Bot
commit_user_email: bot@mesmo.dev
62 changes: 29 additions & 33 deletions .github/workflows/pythontests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,37 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [
windows-latest,
macos-latest,
ubuntu-latest
]
os: [windows-latest, macos-latest, ubuntu-latest]
python-version: ["3.10"]
defaults:
run:
shell: bash -l {0} # Required for conda commands.
shell: bash -l {0} # Required for conda commands.

steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
submodules: recursive
- name: Set up Python
uses: conda-incubator/setup-miniconda@v2
- name: Install dependencies
run: |
conda create -n mesmo -c conda-forge python=${{ matrix.python-version }} contextily cvxpy numpy pandas scipy
conda activate mesmo
python development_setup.py
- name: Run tests with coverage report
run: |
conda activate mesmo
coverage run -m unittest discover tests
coverage xml
- name: Report coverage to Codecov
if: always()
continue-on-error: true
uses: codecov/codecov-action@v2
- name: Report coverage to Codacy
if: always()
continue-on-error: true
uses: codacy/codacy-coverage-reporter-action@v1
with:
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
coverage-reports: coverage.xml
- name: Checkout repository
uses: actions/checkout@v2
with:
submodules: recursive
- name: Set up Python
uses: conda-incubator/setup-miniconda@v2
- name: Install dependencies
run: |
conda create -n mesmo -c conda-forge python=${{ matrix.python-version }} contextily
conda activate mesmo
python development_setup.py
- name: Run tests with coverage report
run: |
conda activate mesmo
coverage run -m unittest discover tests
coverage xml
- name: Report coverage to Codecov
if: always()
continue-on-error: true
uses: codecov/codecov-action@v2
- name: Report coverage to Codacy
if: always()
continue-on-error: true
uses: codacy/codacy-coverage-reporter-action@v1
with:
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
coverage-reports: coverage.xml
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,19 @@ The documentation is located at [mesmo-dev.github.io/mesmo](https://mesmo-dev.gi

## Installation

MESMO has not yet been deployed to Python `pip` / `conda` package indexes, but can be installed in a local development environment as follows:
MESMO has not yet been deployed to Python package indexes, but can be installed in a local development environment as follows:

1. Install `conda`-based Python distribution¹ such as [Anaconda](https://www.anaconda.com/distribution/) or [Miniconda](https://docs.conda.io/en/latest/miniconda.html) or [Miniforge](https://github.com/conda-forge/miniforge).
2. Clone or download the repository. Ensure that the `cobmo` submodule directory is loaded as well.
3. In `conda`-enabled shell (e.g. Anaconda Prompt), run:
- `cd path_to_mesmo_repository`
- `conda create -n mesmo -c conda-forge python=3.10 contextily cvxpy numpy pandas scipy`
- `conda create -n mesmo -c conda-forge python=3.10 contextily`
- `conda activate mesmo`
- `python development_setup.py`
- On Intel CPUs²: `conda install -c conda-forge "libblas=*=*mkl"`

MESMO ships with [HiGHS](https://highs.dev/) as default optimization solver³, but also supports [Gurobi](http://www.gurobi.com/) and [any CVXPY-supported solvers](https://www.cvxpy.org/tutorial/advanced/index.html#choosing-a-solver).
MESMO ships with [HiGHS](https://highs.dev/) as default optimization solver², but also supports [Gurobi](http://www.gurobi.com/) and [any CVXPY-supported solvers](https://www.cvxpy.org/tutorial/advanced/index.html#choosing-a-solver).

For notes ¹/² and alternative installation guide, see [docs/installation.md](docs/installation.md).
For notes ¹/² and alternative installation guide, see [docs/installation.md](docs/installation.md).

## Contributing

Expand Down
2 changes: 1 addition & 1 deletion cobmo
14 changes: 5 additions & 9 deletions development_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,16 @@ def main():
subprocess.check_call(["git", "-C", f"{base_path}", "submodule", "update", "--init", "--recursive"])
except FileNotFoundError as exception:
raise FileNotFoundError(
f"ERROR: No setup file found for submodule `{submodule}`. "
f"No setup file found for submodule `{submodule}`. "
f"Please check if the submodule is loaded correctly."
) from exception

# Install submodules in develop mode.
if run_all:
print("Installing submodules in development mode.")
for submodule in submodules:
subprocess.check_call([sys.executable, "-m", "pip", "install", "-e", f"{base_path / submodule}"])

# Install MESMO.
# Install MESMO and submodules in develop mode.
if run_all:
print("Installing poetry package management tool.")
subprocess.check_call([sys.executable, "-m", "pip", "install", "poetry"])
print("Installing MESMO in development mode.")
subprocess.check_call([sys.executable, "-m", "pip", "install", "-e", f"{base_path}[tests]"])
subprocess.check_call([sys.executable, "-m", "poetry", "install"], cwd=base_path)

# Install HiGHS solver.
if run_all or run_highs:
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"plotly",
"pyyaml",
"pyomo", # Deprecated.
"ray",
"ray", # Deprecated.
"scipy",
"tqdm",
]
Expand Down
13 changes: 5 additions & 8 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,23 @@

## Recommended installation

MESMO has not yet been deployed to Python `pip` / `conda` package indexes, but can be installed in a local development environment as follows:
MESMO has not yet been deployed to Python package indexes, but can be installed in a local development environment as follows:

1. Install `conda`-based Python distribution¹ such as [Anaconda](https://www.anaconda.com/distribution/) or [Miniconda](https://docs.conda.io/en/latest/miniconda.html) or [Miniforge](https://github.com/conda-forge/miniforge).
2. Clone or download the repository. Ensure that the `cobmo` submodule directory is loaded as well.
3. In `conda`-enabled shell (e.g. Anaconda Prompt), run:
- `cd path_to_mesmo_repository`
- `conda create -n mesmo -c conda-forge python=3.10 contextily cvxpy numpy pandas scipy`
- `conda create -n mesmo -c conda-forge python=3.10 contextily`
- `conda activate mesmo`
- `python development_setup.py`
- On Intel CPUs²: `conda install -c conda-forge "libblas=*=*mkl"`

MESMO ships with [HiGHS](https://highs.dev/) as default optimization solver³, but also supports [Gurobi](http://www.gurobi.com/) and [any CVXPY-supported solvers](https://www.cvxpy.org/tutorial/advanced/index.html#choosing-a-solver).
MESMO ships with [HiGHS](https://highs.dev/) as default optimization solver², but also supports [Gurobi](http://www.gurobi.com/) and [any CVXPY-supported solvers](https://www.cvxpy.org/tutorial/advanced/index.html#choosing-a-solver).

### Notes

¹ The installation via `conda` is recommended, because it sets up a dedicated Python environment and supports the performant Intel MKL math library on Intel CPUs for `numpy` / `scipy`. It also allows installing the `contextily` package on Windows, which is required for some geographical plots. The direct installation via `pip` in a non-`conda` environment is also possible, but is currently not tested.
¹ The installation via `conda` is recommended, because it also allows installing the `contextily` package on Windows, which is required for some geographical plots. The direct installation via `pip` in a non-`conda` environment is also possible, but is currently not tested.

² On Intel CPUs, using the Intel MKL math library enables better performance in `numpy` / `scipy` over the default OpenBLAS library. With conda-forge, these libraries can be configured via [`conda install` command](https://conda-forge.org/docs/maintainer/knowledge_base.html#switching-blas-implementation).

³ HiGHS is currently MESMO's default optimization solver and the HiGHS binaries are automatically fetched during MESMO setup. Other solvers can be selected via [MESMO configuration](configuration_reference.md#optimization-solver-configuration). For better performance, MESMO implements direct solver interfaces to HiGHS and Gurobi. Other solvers are indirectly supported [via CVXPY](https://www.cvxpy.org/tutorial/advanced/index.html#choosing-a-solver). CVXPY comes bundled with several open-source solvers and supports additional solvers via manual installation (see "Install with ... support" sections in [CVPXY installation guide](https://www.cvxpy.org/install/index.html)). Note that interfacing solvers via CVXPY currently has [performance limitations](https://github.com/cvxpy/cvxpy/issues/704) for large-scale scenarios.
² HiGHS is currently MESMO's default optimization solver and the HiGHS binaries are automatically fetched during MESMO setup. Other solvers can be selected via [MESMO configuration](configuration_reference.md#optimization-solver-configuration). For better performance, MESMO implements direct solver interfaces to HiGHS and Gurobi. Other solvers are indirectly supported [via CVXPY](https://www.cvxpy.org/tutorial/advanced/index.html#choosing-a-solver). CVXPY comes bundled with several open-source solvers and supports additional solvers via manual installation (see "Install with ... support" sections in [CVPXY installation guide](https://www.cvxpy.org/install/index.html)). Note that interfacing solvers via CVXPY currently has [performance limitations](https://github.com/cvxpy/cvxpy/issues/704) for large-scale scenarios.

## Alternative installation

Expand Down
11 changes: 5 additions & 6 deletions mesmo/config.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"""Configuration module."""

import dynaconf
import logging
import multiprocessing
import pathlib

import dynaconf
import matplotlib
import matplotlib.pyplot as plt
import multiprocessing
import numpy as np
import pandas as pd
import pathlib
import plotly.graph_objects as go
import plotly.io as pio

Expand Down Expand Up @@ -91,9 +92,7 @@ def get_parallel_pool() -> multiprocessing.Pool:
"""

# Obtain multiprocessing pool.
import ray.util.multiprocessing

return ray.util.multiprocessing.Pool()
return multiprocessing.Pool()


# Obtain repository base directory path.
Expand Down
Loading

0 comments on commit 76af995

Please sign in to comment.