Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write tests for core functions #35

Merged
merged 88 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
1ab999f
adding code coverage
j-i-l Aug 19, 2024
084b13e
Merge branch 'main' into 12-test-suite-covering-core-functionality
j-i-l Aug 20, 2024
4d219dd
started SSM init tests
j-i-l Aug 20, 2024
b092cd0
silence linter
j-i-l Aug 20, 2024
f9d0f18
fixing wrong testing command
j-i-l Aug 20, 2024
97eadb2
auto-convert to float if needed
j-i-l Aug 20, 2024
9340d05
corrected filename
j-i-l Aug 20, 2024
08e8e8e
show memory usage and timeing
j-i-l Aug 20, 2024
4cad73a
typing
j-i-l Aug 20, 2024
a350bfd
speed and memory checks
j-i-l Aug 20, 2024
bc378a7
adding details about the ssm
j-i-l Aug 21, 2024
cb95710
using also __init__ docstring
j-i-l Aug 21, 2024
9bdfb3e
minor formating corection
j-i-l Aug 21, 2024
a44f86c
added autodoc ext to sphinx
j-i-l Aug 21, 2024
82e7c78
fixing python version also for rtd
j-i-l Aug 21, 2024
e4fc254
configure autoapi instead of autodoc
j-i-l Aug 21, 2024
55a12fb
separate memory tracking tests with _memory in name
j-i-l Aug 22, 2024
570ed07
better typing
j-i-l Aug 22, 2024
2f8d232
make cython and non-cython implementatios testable
j-i-l Aug 22, 2024
e4f5db5
separating inplace row norm
j-i-l Aug 22, 2024
ce843af
try to satisfy long long vs int
j-i-l Aug 22, 2024
bb750ec
minor - avoid declaring unused params
j-i-l Sep 2, 2024
eb27b74
target src for coverage
j-i-l Sep 2, 2024
005cf7c
config for test coverage
j-i-l Sep 2, 2024
49bf505
cleaning up
j-i-l Sep 2, 2024
75021ed
allow coverage to trace lines
j-i-l Sep 2, 2024
03b1c5a
reporting code coverage
j-i-l Sep 2, 2024
46b986f
establish jobs order
j-i-l Sep 2, 2024
60b1e2c
using correct secret
j-i-l Sep 2, 2024
c785c4a
always run coverage
j-i-l Sep 2, 2024
2877484
run coverage report
j-i-l Sep 2, 2024
2e6b87c
remove plugin for codecov reports
j-i-l Sep 2, 2024
7390979
single folder several files
j-i-l Sep 2, 2024
a376ede
specify package location
j-i-l Sep 2, 2024
9dabe70
using local install
j-i-l Sep 2, 2024
bd1cd7c
workaround for hidden files
j-i-l Sep 2, 2024
525d809
site-package install but discover package name
j-i-l Sep 2, 2024
71f0174
fixign artifact option
j-i-l Sep 2, 2024
bf651f1
sepcify source in config to use relative files
j-i-l Sep 2, 2024
27960be
fixing coverage options
j-i-l Sep 2, 2024
19a62d4
minor edits
j-i-l Sep 2, 2024
72d63ea
micro
j-i-l Sep 2, 2024
989a693
started with more tests
j-i-l Sep 2, 2024
d81018d
testing mkl
j-i-l Sep 2, 2024
162b757
float matrices
j-i-l Sep 2, 2024
6100fe7
matmul testing
j-i-l Sep 2, 2024
44c7551
testing with larger matrices
j-i-l Sep 2, 2024
d3b90d2
testing mkl and blas/lapak
j-i-l Sep 3, 2024
117faf3
wip on profiling and testing csr ops
j-i-l Sep 14, 2024
ee5e48f
completing tests for csr methods
j-i-l Sep 14, 2024
bef73be
testing with comparison crs_ operations
j-i-l Sep 15, 2024
50fb6a7
show all memory reports
j-i-l Sep 15, 2024
62fe6be
covering conversion from/to ssm
j-i-l Sep 15, 2024
a27f9f4
formatting docstring - correcting description
j-i-l Sep 16, 2024
28b4051
temp. fix for type inconsistency - see #43
j-i-l Sep 16, 2024
e0b2726
minor formatting
j-i-l Sep 16, 2024
b658f27
tests for inplace ops with diag matrix
j-i-l Sep 16, 2024
02a2e87
minor correction
j-i-l Sep 16, 2024
db16b60
bettery typeing
j-i-l Sep 16, 2024
55385fb
adding tests for sparse_autocov_mat inits
j-i-l Sep 16, 2024
a2d986d
adding tests for SAM creation (also from T)
j-i-l Sep 17, 2024
f2c7cd6
better docstring formatting
j-i-l Sep 17, 2024
41adc53
drop the math mode
j-i-l Sep 17, 2024
1f14078
ditch passing by possition
j-i-l Sep 23, 2024
efbfacb
including more methods for SAM
j-i-l Sep 23, 2024
bce7c39
started with synthtempnetwork
j-i-l Sep 25, 2024
fd98370
adding minimal tests for synth_temp_network subm
j-i-l Sep 27, 2024
2aedd35
started with flow_stability sub-m
j-i-l Sep 27, 2024
3af2c87
initiating FlowStability tests
j-i-l Sep 29, 2024
043c898
init tests for parallel_expm
j-i-l Sep 29, 2024
db1fecc
init tests for temporal_network
j-i-l Sep 29, 2024
decc937
init tests for parallel_clustering
j-i-l Sep 29, 2024
6076d98
minor formatting
j-i-l Sep 29, 2024
aa071ce
minor notes/info
j-i-l Sep 29, 2024
762faf9
minor edits; init cython testing
j-i-l Sep 29, 2024
0f9be60
simple test cases
j-i-l Sep 30, 2024
1c3f36b
better bassis for test data generation
j-i-l Sep 30, 2024
f64641c
tests for temp networks
j-i-l Sep 30, 2024
f08d01f
minor fixes
j-i-l Sep 30, 2024
392432c
scipy upgrade - use sparse_dot_mk for mkl support
j-i-l Sep 30, 2024
2a8f201
minor formatting
j-i-l Sep 30, 2024
98d8fd8
minor fix in assertion
j-i-l Sep 30, 2024
67cafa9
Merge branch 'main' into 12-test-suite-covering-core-functionality
j-i-l Dec 16, 2024
57ca6c8
cleaning up old tests
j-i-l Dec 16, 2024
835700f
cleaning up all tests for discarded implementations
j-i-l Dec 16, 2024
b10ed5c
fixing the data type for now to double
j-i-l Dec 16, 2024
56521ad
adapting lifetime of modified objects
j-i-l Dec 16, 2024
f67781a
adapting to new definitions
j-i-l Dec 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 90 additions & 5 deletions .github/workflows/development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ jobs:
build-venv:
runs-on: ubuntu-22.04
steps:
- run: |
sudo apt-get upgrade
sudo apt-get -y install intel-mkl
- uses: actions/checkout@v4
- name: Set up Python 3.9
uses: actions/setup-python@v5
Expand All @@ -20,11 +23,13 @@ jobs:
uses: actions/cache/restore@v4
with:
path: ./venv
key: venv-${{ runner.os }}-${{ hashFiles('**/requirements.txt') }}-${{ hashFiles('**/**.toml') }}
key: venv-${{ runner.os }}-${{ hashFiles('**/requirements/base.txt') }}-${{ hashFiles('**/**.toml') }}
- name: Build venv
run: |
python -m pip install --upgrade pip
python -m venv ./venv
# with mkl support
./venv/bin/python -m pip install -r requirements/mkl.txt
./venv/bin/python -m pip install .[testing]
if: steps.cached-venv.outputs.cache-hit != 'true'
- name: Cache venv
Expand All @@ -44,7 +49,7 @@ jobs:
uses: actions/cache/restore@v4
with:
path: ./venv
key: venv-${{ runner.os }}-${{ hashFiles('**/requirements.txt') }}-${{ hashFiles('**/**.toml') }}
key: venv-${{ runner.os }}-${{ hashFiles('**/requirements/base.txt') }}-${{ hashFiles('**/**.toml') }}
- name: Build wheel
run: |
venv/bin/python -m pip install build
Expand All @@ -64,7 +69,7 @@ jobs:
- uses: actions/cache/restore@v4
with:
path: ./venv
key: venv-${{ runner.os }}-${{ hashFiles('**/requirements.txt') }}-${{ hashFiles('**/**.toml') }}
key: venv-${{ runner.os }}-${{ hashFiles('**/requirements/base.txt') }}-${{ hashFiles('**/**.toml') }}
- name: Getting build wheel
uses: actions/download-artifact@v4
with:
Expand All @@ -84,6 +89,9 @@ jobs:
runs-on: ubuntu-latest
needs: install
steps:
- run: |
sudo apt-get upgrade
sudo apt-get -y install intel-mkl
- uses: actions/checkout@v4
- name: Set up Python 3.9
uses: actions/setup-python@v5
Expand All @@ -95,9 +103,85 @@ jobs:
with:
path: ./venv
key: venv-${{ runner.os }}-${{ hashFiles('venv/**') }}
- name: Test with pytest
- name: Tests without memory tracking
run: |
venv/bin/python -m pytest
venv/bin/python -m pytest --junitxml=junit/test-results.xml --cov=flowstab --durations=0 -k 'not _memory'
env:
COVERAGE_FILE: ".coverage.no_memory"
- name: Store coverage file
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage-no_memory
path: .coverage.no_memory
include-hidden-files: true

test-memory:
runs-on: ubuntu-latest
needs: install
steps:
- run: |
sudo apt-get upgrade
sudo apt-get -y install intel-mkl
- uses: actions/checkout@v4
- name: Set up Python 3.9
uses: actions/setup-python@v5
with:
python-version: 3.9
- name: Build venv
run: |
python -m pip install --upgrade pip
python -m venv ./venv
# with mkl support
./venv/bin/python -m pip install .[testing,mkl]
# # Note: we use cache here since artifacts do not keep permissions
# - name: Getting the venv
# uses: actions/cache/restore@v4
# with:
# path: ./venv
# key: venv-${{ runner.os }}-${{ hashFiles('venv/**') }}
- name: Tests with memory tracking
run: |
venv/bin/python -m pytest --junitxml=junit/test-results.xml --cov=flowstab --durations=0 --memray --most-allocations=0 -k '_memory'
env:
COVERAGE_FILE: ".coverage.memory"
- name: Store coverage file
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage-memory
path: .coverage.memory
include-hidden-files: true

coverage:
name: combine-coverage
runs-on: ubuntu-22.04
needs: [test, test-memory]
if: |
always()
permissions:
pull-requests: write
contents: write
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
id: download
with:
pattern: coverage-*
merge-multiple: true
- name: Coverage comment
id: coverage_comment
uses: py-cov-action/python-coverage-comment-action@v3
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MERGE_COVERAGE_FILES: true

- name: Store Pull Request comment to be posted
uses: actions/upload-artifact@v4
if: steps.coverage_comment.outputs.COMMENT_FILE_WRITTEN == 'true'
with:
name: python-coverage-comment-action
path: python-coverage-comment-action.txt

lint:
runs-on: ubuntu-latest
Expand All @@ -117,3 +201,4 @@ jobs:
- name: Lint with ruff
run: |
venv/bin/python -m ruff check --select=ALL --output-format=github src/
continue-on-error: true
29 changes: 29 additions & 0 deletions .github/workflows/report_coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Post coverage comment

on:
workflow_run:
workflows: ["Development Workflow"]
types:
- completed

jobs:
test:
name: Run tests & display coverage
runs-on: ubuntu-22.04
# if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'
if: github.event.workflow_run.event == 'pull_request'
permissions:
pull-requests: write
contents: write
actions: read
steps:
# DO NOT run actions/checkout here, for security reasons
# For details, refer to https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
- name: Post comment
uses: py-cov-action/python-coverage-comment-action@v3
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_PR_RUN_ID: ${{ github.event.workflow_run.id }}
# Update those if you changed the default values:
# COMMENT_ARTIFACT_NAME: python-coverage-comment-action
# COMMENT_FILENAME: python-coverage-comment-action.txt
2 changes: 1 addition & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ version: 2
build:
os: ubuntu-22.04
tools:
python: "3.12"
python: "3.9"

# Build documentation in the "docs/" directory with Sphinx
sphinx:
Expand Down
5 changes: 2 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
import pathlib
import sys

# -- Add the project root for autodiscovery with sphinx.ext.autodoc ----------
# -- Add the project root for autodiscovery ----------
sys.path.insert(0, pathlib.Path(__file__).parents[1].resolve().as_posix())
autodoc_typehints = 'description'
autodoc_class_signature = 'separated'

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
Expand Down Expand Up @@ -44,4 +42,5 @@
autoapi_dirs = ["../src/", ]
autoapi_file_patterns = ['*.py', ]
autoapi_member_order = "groupwise"
autoapi_python_class_content = "both"
# autoapi_ignore = ["*conf.py", "*setup.py" , "*_cython*.pyx", ]
26 changes: 23 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ Repository = "https://github.com/alexbovet/flow_stability.git"
Documentation = "https://flow-stability.readthedocs.io/"
Issues = "https://github.com/alexbovet/flow_stability/issues"

[tool.setuptools.dynamic]
dependencies = {file = ["requirements.txt"]}
readme = {file = ["README.md"]}
[tool.setuptools.dynamic.readme]
file = ["README.md"]

[tool.setuptools.dynamic.dependencies]
file = ["requirements/base.txt"]

[tool.setuptools.dynamic.optional-dependencies.mkl]
file = ["requirements/mkl.txt"]

[tool.setuptools.dynamic.optional-dependencies.testing]
file = ["tests/requirements.txt"]
Expand All @@ -47,6 +52,21 @@ requires = [
]
build-backend = "setuptools.build_meta"

# config for the test coverage
[tool.coverage.run]
relative_files = true
# plugins = ["Cython.Coverage", ]
source = ["src/flowstab", ]
omit = [
"tests",
"*__init__.py",
]
[tool.coverage.paths]
source = [
"src/flowstab/",
"venv/lib/python*/site-packages/flowstab/"
]

# This is for the linting with ruff
[tool.ruff]
target-version = "py39"
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt → requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Cython>=3.0.11
pandas>=2.2.2
scipy>=1.13.1
hickle>=5.0.3
psutil>=6.0.0
scipy>=1.13
1 change: 1 addition & 0 deletions requirements/mkl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sparse_dot_mkl>=0.9.4
38 changes: 32 additions & 6 deletions src/flowstab/FlowStability.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
"""#

Check failure on line 1 in src/flowstab/FlowStability.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (N999)

src/flowstab/FlowStability.py:1:1: N999 Invalid module name: 'FlowStability'
# flow stability
#
# Copyright (C) 2021 Alexandre Bovet <[email protected]>
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 3 of the License, or (at your option) any
# later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.


"""

Check failure on line 20 in src/flowstab/FlowStability.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (D205)

src/flowstab/FlowStability.py:1:1: D205 1 blank line required between summary line and description

Check failure on line 20 in src/flowstab/FlowStability.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (D400)

src/flowstab/FlowStability.py:1:1: D400 First line should end with a period

Check failure on line 20 in src/flowstab/FlowStability.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (D415)

src/flowstab/FlowStability.py:1:1: D415 First line should end with a period, question mark, or exclamation point
from __future__ import annotations
from typing import Collection

Check failure on line 22 in src/flowstab/FlowStability.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (UP035)

src/flowstab/FlowStability.py:22:1: UP035 Import from `collections.abc` instead: `Collection`

import importlib.util
import os
import time
Expand All @@ -39,13 +42,23 @@
sparse_matmul,
sparse_stoch_mat,
)
from .TemporalNetwork import inplace_csr_row_normalize, set_to_zeroes, sparse_lapl_expm
from .TemporalNetwork import (
inplace_csr_row_normalize,
set_to_zeroes,
sparse_lapl_expm

Check failure on line 48 in src/flowstab/FlowStability.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (COM812)

src/flowstab/FlowStability.py:48:21: COM812 Trailing comma missing
)

USE_CYTHON = True

Check failure on line 51 in src/flowstab/FlowStability.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (I001)

src/flowstab/FlowStability.py:21:1: I001 Import block is un-sorted or un-formatted
if importlib.util.find_spec("cython") is not None:
from _cython_fast_funcs import compute_S, cython_nmi, cython_nvi, sum_Sout, sum_Sto
from _cython_fast_funcs import (
compute_S,
cython_nmi,
cython_nvi,
sum_Sout,
sum_Sto

Check failure on line 58 in src/flowstab/FlowStability.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (COM812)

src/flowstab/FlowStability.py:58:16: COM812 Trailing comma missing
)
else:

Check failure on line 60 in src/flowstab/FlowStability.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (I001)

src/flowstab/FlowStability.py:53:1: I001 Import block is un-sorted or un-formatted
print("Could not load cython functions")

Check failure on line 61 in src/flowstab/FlowStability.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (T201)

src/flowstab/FlowStability.py:61:5: T201 `print` found
USE_CYTHON = False


Expand All @@ -55,10 +68,22 @@
and a node to cluster dict.
"""

def __init__(self, num_nodes,
cluster_list=None,
node_to_cluster_dict=None,
check_integrity=False):
def __init__(self,
num_nodes:int,
cluster_list:Collection|None=None,
node_to_cluster_dict:dict|None=None,
check_integrity:bool=False):
"""
Parameters
----------
num_nodes:
The number of nodes in the partition
cluster_list:
A list of clusters with each cluster being a set of nodes
node_to_custer_dict:
A mapping that maps each node to the index of the corresponding
cluster in `cluster_list`
"""

self.num_nodes = num_nodes

Expand Down Expand Up @@ -2360,6 +2385,7 @@
return Clustering(p1=pi,p2=pi,T=T, rnd_seed=rnd_seed)


# TODO: move to helper scripts
def n_random_seeds(n):
# generate n random seeds

Expand Down
Loading
Loading