Skip to content

Commit

Permalink
changed setup, updated readme, added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ddceruti committed Sep 27, 2024
1 parent a388acb commit c90770f
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 61 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,10 @@ This can also be done with venv or equivalent.

We recommend to install the dependencies with anaconda or mamba:

```conda
```mamba
cd topotherm
conda create -n topotherm python
conda activate topotherm
pip install -e .
mamba env create -f environment.yml -n topotherm
mamba activate topotherm
```

## Solver
Expand All @@ -112,9 +111,9 @@ the documentation [here](https://support.gurobi.com/hc/en-us/articles/3600442902
You can try the code on smaller benchmarks with several open source solvers,
such as SCIP. Other popular open-source options are COIN-OR's cbc or HiGHS.

```conda
conda activate topotherm
conda install -c conda-forge pyscipopt
```mamba
mamba activate topotherm
mamba install -c conda-forge pyscipopt
```

## Usage
Expand All @@ -137,6 +136,7 @@ changes, please open an issue first to discuss what you would like to change.
To run the tests, use pytest.

```Python
pip install .[dev]
pytest tests
```

Expand Down
18 changes: 5 additions & 13 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
name: topotherm
name: topotherm>
channels:
- defaults
- conda-forge
- defaults
dependencies:
- python>=3.9
- numpy<2.0
- pandas
- scipy
- networkx
- matplotlib
- pyomo
- pyarrow>=14.0.1
- Pillow>=10.2.0
- pytest
- pydantic
- pyyaml
- pip
- pip:
- -r requirements.txt
58 changes: 58 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[build-system]
requires = ["setuptools >= 64"]
build-backend = "setuptools.build_meta"

[project]

name = "topotherm"
version = "0.2.0"
description = "A package to design district heating networks"
readme = "README.md"

authors = [
{ name = "Jerry Lambert", email = "jerry.lambert@tum.de"},
{ name = "Amedeo Ceruti", email = "amedeo.ceruti@tum.de"}
]

classifiers=[
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Topic :: Scientific/Engineering :: District Heating",
]

keywords = [
"district heating",
"optimization",
"Linear Programming",
"Mixed Integer Linear Programming"
]

license = {file = "LICENSE"}

requires-python = ">=3.9"
dependencies = [
"numpy",
"pandas",
"scipy",
"networkx",
"matplotlib",
"pyomo > 6.0",
"pyarrow >= 14.0.1",
"Pillow >= 10.2.0",
"pyyaml",
"pydantic",
]

[tool.setuptools]
packages = { find = { where = ["topotherm"], exclude = ["tests", "docs"] } }

[project.optional-dependencies]
dev = [
"pytest",
]
docs = [
"sphinx",
"sphinx-rtd-theme",
"sphinx-autodoc",
"sphinx-viewcode"
]
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
numpy<2.0
numpy
pandas
scipy
networkx
matplotlib
pyomo
pyomo>6.0
pyarrow>=14.0.1
Pillow>=10.2.0
pytest
Expand Down
39 changes: 3 additions & 36 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,5 @@
"""Set up topotherm from requirements."""
from setuptools import setup

import os
from setuptools import setup, find_packages


# The directory containing this file
here = os.path.dirname(os.path.realpath(__file__))

# The text of the README file
with open(os.path.join(here, "README.md"), encoding='utf-8') as fid:
readme = fid.read()

with open(os.path.join(here, "requirements.txt"), encoding='utf-8') as fid:
reqs = fid.read().splitlines()

# This call to setup() does all the work
setup(
name="topotherm",
version="0.1.0",
description="A package to design district heating networks",
long_description=readme,
long_description_content_type="text/markdown",
url="https://github.com/jylambert/topotherm",
author="Jerry Lambert, Amedeo Ceruti",
author_email="jerry.lambert@tum.de, amedeo.ceruti@tum.de",
license="MIT",
classifiers=[
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Topic :: Scientific/Engineering :: District Heating",
],
packages=find_packages(exclude=("tests", "docs")),
include_package_data=True,
install_requires=reqs,
keywords=["district heating", "optimization", "Linear Programming",
"Mixed Integer Linear Programming"]
)
if __name__ == "__main__":
setup()
3 changes: 3 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://stackoverflow.com/questions/54895002/modulenotfounderror-with-pytest
import sys
sys.path.append('.')
7 changes: 5 additions & 2 deletions tests/sts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pyomo.environ as pyo
import pandas as pd
from pytest import approx

import topotherm as tt

Expand Down Expand Up @@ -54,7 +55,8 @@ def test_sts_forced(request):
assert result.solver.status == pyo.SolverStatus.ok
# assert that the objective value is less than 2% away from the expected
# value
assert (abs(pyo.value(model.obj)) - 4.6259e+06) < 0.02 * 4.6259e+06
assert abs(pyo.value(model.obj)) == approx(4.6259e+06, rel=0.02)
# assert (abs(pyo.value(model.obj)) - 4.6259e+06) < 0.02 * 4.6259e+06


def test_sts_eco(request):
Expand Down Expand Up @@ -86,4 +88,5 @@ def test_sts_eco(request):

result = opt.solve(model, tee=True)
assert result.solver.status == pyo.SolverStatus.ok
assert (abs(pyo.value(model.obj)) - 4.01854e+04) < 0.02 * 4.01854e+04
assert abs(pyo.value(model.obj)) == approx(4.01854e+04, rel=0.02)
# assert (abs(pyo.value(model.obj)) - 4.01854e+04) < 0.02 * 4.01854e+04
11 changes: 11 additions & 0 deletions tests/test_setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""test_setup.py tests the correct setup of topotherm."""

from pytest import approx

def test_import():
import topotherm


def test_functionality():
from topotherm import single_timestep
assert single_timestep.annuity(c_i=0.01, n=10) == approx(0.1055820766, rel=1e-2)
2 changes: 1 addition & 1 deletion topotherm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from . import plotting
from . import utils
from . import fileio
from . import precalculation_hydraulic
Expand All @@ -8,3 +7,4 @@
from . import multiple_timestep
from . import sets
from . import model_old
from . import plotting

0 comments on commit c90770f

Please sign in to comment.