Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into 137.update-doc
Browse files Browse the repository at this point in the history
  • Loading branch information
sajith committed Aug 7, 2024
2 parents a4ccdaa + 85705d9 commit a7728af
Show file tree
Hide file tree
Showing 48 changed files with 2,410 additions and 2,436 deletions.
32 changes: 0 additions & 32 deletions .flake8

This file was deleted.

14 changes: 7 additions & 7 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,24 @@ jobs:
steps:

- name: Check out sources
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Python 3.9
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.9"
cache: 'pip' # cache pip dependencies
cache-dependency-path: setup.cfg
cache-dependency-path: pyproject.toml

- name: Install dependencies
- name: Install tools
run: |
python -m pip install --upgrade pip
python -m pip install black isort
python -m pip install .[lint]
- name: Run "black --check"
run: |
python -m black --check .
python -m black --check $(git ls-files "*.py")
- name: Run "isort --check"
run: |
python -m isort --check --profile black .
python -m isort --check $(git ls-files "*.py")
65 changes: 24 additions & 41 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ name: Test

on:
push:
branches: [ "main", "develop" ]
branches:
- main
pull_request:
branches: [ "main", "develop" ]
branches:
- main

permissions:
contents: read
Expand All @@ -31,69 +33,50 @@ jobs:

steps:
- name: Check out code
uses: actions/checkout@v3
uses: actions/checkout@v4

# See https://github.com/marketplace/actions/setup-python
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip' # caching pip dependencies
cache-dependency-path: setup.cfg
cache-dependency-path: pyproject.toml

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pep8-naming wheel coveralls
if [ -f requirements.txt ]; then pip install --prefer-binary -r requirements.txt; fi
# See https://docs.github.com/en/enterprise-cloud@latest/actions/using-github-hosted-runners/customizing-github-hosted-runners
- name: Install libgraphviz-dev
run: |
sudo apt-get update
sudo apt-get -y install libgraphviz-dev
- name: Run some basic checks with flake8
run: |
# Stop the build if there are Python syntax errors or undefined names.
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
- name: Check against PEP8 naming conventions
- name: Install dependencies
run: |
# This needs pep8-naming, installed above
flake8 . --count --select=N8 --show-source --statistics
python -m pip install --upgrade pip
pip install .[test,pygraphviz,lint]
- name: Run complexity checks with flake8
run: |
# Note that `--exit-zero` treats all errors as warnings.
# Code that is too complex is not considered an error, for
# now.
flake8 . --count --exit-zero --max-complexity=10
- name: Lint with ruff
run: ruff check $(git ls-files "*.py")

- name: Run tests
run: |
# Install package so that tests can be run.
pip install .[test,pygraphviz]
# Run tests and collect coverage data.
python -m pytest
# Generate LCOV format coverage data for coveralls.
python -m coverage lcov -o coverage.lcov
- name: Send coverage data to coveralls.io
run: |
python -m coveralls --service=github
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_FLAG_NAME: ${{ matrix.python-version }}
COVERALLS_PARALLEL: true
uses: coverallsapp/github-action@v2
with:
flag-name: run-${{ join(matrix.*, '-') }}
file: coverage.lcov
parallel: true

finalize:
name: finalize
needs: test
runs-on: ubuntu-latest
container: python:3-slim
runs-on: ubuntu-latest
if: ${{ always() }}
steps:
- name: Indicate completion to coveralls.io
run: |
pip --no-cache-dir install --upgrade coveralls
python -m coveralls --service=github --finish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: coverallsapp/github-action@v2
with:
parallel-finished: true
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,4 @@ tests/data/topologies/amlight.png
/coverage.xml

# Generated by setuptools_scm
/src/sdx/pce/_version.py
/src/sdx_pce/_version.py
2 changes: 2 additions & 0 deletions .mailmap
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Yifei Wang <yifei666@umd.edu> <43050198+yifei666@users.noreply.github.com>
Sajith Sasidharan <sajith@hcoop.net> <sajith@renci.org>
53 changes: 43 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,21 @@ PCE's API is still evolving. With that caveat, and omitting some
details, the general usage is like this:

```python
from sdx.pce.load_balancing.te_solver import TESolver
from sdx.pce.topology.temanager import TEManager
from sdx_pce.load_balancing.te_solver import TESolver
from sdx_pce.topology.temanager import TEManager

temanager = TEManager(initial_topology, connection_request)
temanager = TEManager(initial_topology)
for topology in topologies:
temanager.add_topology(topology)

graph = temanager.generate_graph_te()
traffic_matrix = temanager.generate_connection_te()
traffic_matrix = temanager.generate_traffic_matrix(connection_request)

solution = TESolver(graph, traffic_matrix).solve()

breakdown = temanager.generate_connection_breakdown(solution)
for domain, link in breakdown.items():
# publish(domain, link)
```

Note that PCE requires two inputs: network topology and connection
Expand Down Expand Up @@ -86,28 +90,52 @@ compiler and development libraries and headers of graphviz installed.

### Running tests

To run tests, using [tox] is recommended:
Use [pytest] to run all tests:

```console
```
$ pip install --editable .[test]
$ pytest
```

If you want to print console and logging messages when running a test,
do:

```
$ pytest --log-cli-level=info [-s|--capture=no] \
tests/test_te_manager.py::TEManagerTests::test_generate_solver_input
```

Use [tox] to run tests using several versions of Python in isolated
virtual environments:

```
$ tox
```

With tox, you can run single tests like so:
With tox, you can run a single test verbosely like so:

```console
$ tox -- [-s] tests/test_te_manager.py::TestTEManager::test_generate_solver_input
```
$ tox -e py311 -- --log-cli-level=info [-s|--capture=no] \
tests/test_te_manager.py::TEManagerTests::test_generate_solver_input
```

The test that depend on pygraphviz are skipped by default. If you are
able to install pygraphviz in your setup, you can run that test too
with:

```console
```
$ tox -e extras
```

Test data is stored in [tests/data](./tests/data) as JSON files.

There are also some code checks (ruff, black, and isort) that you can
run with:

```console
$ tox -e lint
```


<!-- URLs -->

Expand All @@ -124,6 +152,11 @@ Test data is stored in [tests/data](./tests/data) as JSON files.
[NetworkX]: https://networkx.org/
[OR-Tools]: https://developers.google.com/optimization/

[pytest]: https://docs.pytest.org/
[tox]: https://tox.wiki/en/latest/index.html

[test_request.json]: ./src/sdx/pce/data/requests/test_request.json

[ruff]: https://pypi.org/project/ruff/
[black]: https://pypi.org/project/black/
[isort]: https://pypi.org/project/isort/
28 changes: 18 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ authors = [
{ name = "Yifei Wang", email = "ywang13@renci.org" }
]
readme = "README.md"
requires-python = ">=3.6"
requires-python = ">=3.8"
license = {file = "LICENSE"}
classifiers = [
"Programming Language :: Python :: 3",
Expand All @@ -30,8 +30,7 @@ dependencies = [
"prtpy",
"pydot",
"dataclasses-json",
"importlib-resources; python_version < '3.9'",
"sdxdatamodel @ git+https://github.com/atlanticwave-sdx/datamodel@2.0.0"
"sdx-datamodel @ git+https://github.com/atlanticwave-sdx/datamodel@2.0.6.rc4",
]

[project.urls]
Expand All @@ -42,31 +41,34 @@ Issues = "https://github.com/atlanticwave-sdx/pce/issues"
test = [
"pytest >= 7.1.2",
"pytest-cov >= 3.0.0",
"importlib-resources; python_version < '3.9'",
]
pygraphviz = [
"pygraphviz"
]
]
lint = [
"ruff == 0.0.285",
"black == 24.*",
"isort == 5.*",
]

[options.packages.find]
where = "src"

[tool.pytest.ini_options]
addopts = "--cov=sdx.pce --cov-report html --cov-report term-missing"
addopts = "--cov=sdx_pce --cov-report html --cov-report term-missing"
testpaths = [
"tests"
]

[tool.setuptools_scm]
# Write version info collected from git to a file. This happens when
# we run `python -m build`.
write_to = "src/sdx/pce/_version.py"

[tool.black]
src_paths = ["src", "tests", "setup.py"]
write_to = "src/sdx_pce/_version.py"

[tool.isort]
profile = "black"
src_paths = ["src", "tests", "setup.py"]
src_paths = ["src", "tests", "scripts"]

[tool.coverage.run]
branch = true
Expand All @@ -85,3 +87,9 @@ source = [
# In tox environments.
".tox/**/site-packages/",
]

[tool.ruff]
ignore = [
"E501" # Ignore 'line too long' errors since we auto-format
# using black.
]
2 changes: 1 addition & 1 deletion scripts/results_plot_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def plot_heur(title, path):

# Driver Code:
if __name__ == "__main__":
# fname = '/Users/yxin/NSF/aw-sdx/sdx/pce/tests/results/simulation.57036414_10.out'
# fname = '/Users/yxin/NSF/aw-sdx/sdx_pce/tests/results/simulation.57036414_10.out'
# N = 2
# LastNlines(fname, N)
path = "../../tests/results/"
Expand Down
9 changes: 3 additions & 6 deletions scripts/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@

import numpy as np

from sdx.pce.heuristic.heur import TEGroupSolver, matrix_to_connection, random_graph
from sdx.pce.load_balancing.te_solver import TESolver
from sdx.pce.models import ConnectionSolution
from sdx.pce.utils.constants import Constants
from sdx.pce.utils.random_connection_generator import RandomConnectionGenerator
from sdx.pce.utils.random_topology_generator import RandomTopologyGenerator
from sdx_pce.heuristic.heur import TEGroupSolver, matrix_to_connection, random_graph
from sdx_pce.load_balancing.te_solver import TESolver
from sdx_pce.utils.constants import Constants


def dot_file(g_file, tm_file):
Expand Down
22 changes: 0 additions & 22 deletions src/sdx/pce/data/requests/test_request.json

This file was deleted.

Loading

0 comments on commit a7728af

Please sign in to comment.