Skip to content

Commit

Permalink
Various maintenance tasks (#88)
Browse files Browse the repository at this point in the history
* update docs, dependencies, tests; add util and result class
* update actions setup
* separate test/doc deps
* add tests for uncovered behaviors
* ^ py version to 3.11
* edit readme
  • Loading branch information
nkrusch authored Apr 8, 2023
1 parent a8e187d commit 887853a
Show file tree
Hide file tree
Showing 49 changed files with 474 additions and 626 deletions.
25 changes: 13 additions & 12 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
### Checking code changes

Any changes to source code must pass lint + unit tests and these are
checked automatically. Here are some helpful commands for checking your changes:
checked automatically.

In the project root, run:
Run this commands locally, to check your changes.

```text
make pre-commit # check everything
```

```text
make test # check unit tests only (1
```
#### Details

```text
make lint # check code style only (2
```
Pre-commit check runs unit tests and lints the source code.
To debug, you can run these steps individually.

```text
make clean # clean generated files
make test # check unit tests only
```


1) Unit tests are in `tests` directory. You can run unit tests on specific files or the entire source.
Unit tests are in `tests` directory. You can run unit tests on specific files or the entire source.
See [pytest documentation](https://docs.pytest.org/en/stable/contents.html) for more details.

2) This project uses [flake8](https://flake8.pycqa.org/en/latest/index.html) for linting.

```text
make lint # check code style only
```

This project uses [flake8](https://flake8.pycqa.org/en/latest/index.html) for linting.
You can use it to check specific files or run it against all Python source files by specifying a path.
6 changes: 3 additions & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.10"
python-version: "3.11"

- name: Install dependencies
run: python -m pip install -r requirements-dev.txt
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.10"
python-version: "3.11"

- name: Install dependencies
run: python -m pip install -r requirements-dev.txt
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/profile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
profile-examples:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.10"
python-version: "3.11"

- uses: kenchan0130/actions-system-info@master
id: system-info
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/pypi-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2
- uses: actions/setup-python@v2
uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.10"
python-version: "3.11"

- name: Install dependencies
run: pip install build setuptools wheel twine
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/pyversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ jobs:
strategy:
matrix:
# test legacy runtimes only; build workflow is set to latest
python: [ 3.7, 3.8, 3.9 ]
python: [ 3.7, 3.8, 3.9, "3.10" ]

steps:
- name: Checkout repo
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}

Expand Down
18 changes: 13 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ SHELL := /bin/bash

help:
@echo "clean - remove all build, test, coverage and Python artifacts"
@echo "clean-build - remove build artifacts"
@echo "clean-pyc - remove Python file artifacts"
@echo "pre-commit - run unit tests and linter"
@echo "profile - run cProfile on all examples"
@echo "test - run unit tests only"
Expand All @@ -17,9 +15,9 @@ clean:
@rm -fr profile/
@rm -fr .pytest_cache/
@rm -fr .eggs/
@rm -fr .coverage
@find . -name '*.egg-info' -exec rm -fr {} +
@find . -name '*.egg' -exec rm -f {} +
@rm -fr .coverage
@find . -name '*.pyc' -exec rm -f {} +
@find . -name '*.pyo' -exec rm -f {} +
@find . -name '*~' -exec rm -f {} +
Expand All @@ -36,7 +34,7 @@ profile: dev-env cprofile
dev-env:
@test -d venv || python3 -m venv venv;
@source venv/bin/activate;
@pip3 install -q -r requirements-dev.txt
@pip3 install -q -r requirements-test.txt

test-only:
pytest --cov=./pymwp tests
Expand All @@ -48,4 +46,14 @@ lint-only:
flake8 ./pymwp --count --show-source --statistics

cprofile:
python3 utilities/profiler.py --lines=100 --no-external
python3 utilities/profiler.py --lines=100 --no-external

compute-ast:
@cd utilities \
&& python3 ast.py ../tests/test_examples ../tests/mocks \
&& python3 ast.py ../c_files/infinite/infinite_2.c ../tests/mocks \
&& python3 ast.py ../c_files/infinite/infinite_8.c ../tests/mocks \
&& python3 ast.py ../c_files/implementation_paper/example14.c ../tests/mocks \
&& python3 ast.py ../c_files/not_infinite/notinfinite_2.c ../tests/mocks \
&& python3 ast.py ../c_files/not_infinite/notinfinite_3.c ../tests/mocks \
&& cd ..
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@

<!--desc-start-->

pymwp is a tool for automatically performing static analysis on programs written in C, inspired by [_"A Flow Calculus of mwp-Bounds for Complexity Analysis"_](https://doi.org/10.1145/1555746.1555752).
pymwp is a tool for automatically performing static analysis on programs written in C.
It is inspired by [_"A Flow Calculus of mwp-Bounds for Complexity Analysis"_](https://doi.org/10.1145/1555746.1555752).
It analyzes resource usage and determines if a program's variables growth rates are no more than polynomially related to their inputs sizes.
You can run our [many examples](https://statycc.github.io/pymwp/examples/) on-line [in our demo](https://statycc.github.io/pymwp/demo/) before [installing it](https://statycc.github.io/pymwp/), consult our list of [supported C language features](https://statycc.github.io/pymwp/features/),
or review latest [profiling results](https://github.com/statycc/pymwp/releases/tag/profile-latest) for interesting metrics.
Try our online [demo](https://statycc.github.io/pymwp/demo/) to see it action.
For more details on usage and behavior, see pymwp [documentation](https://statycc.github.io/pymwp/), particularly [supported C language features](https://statycc.github.io/pymwp/features/).
See latest [profiling results](https://github.com/statycc/pymwp/releases/tag/profile-latest) for interesting performance metrics.

<!--desc-end-->

## Documentation and Demo

Refer to **[statycc.github.io/pymwp](https://statycc.github.io/pymwp/)** for a documentation of our modules, an [on-line demo](https://statycc.github.io/pymwp/demo/) as well as a presentation of [our examples](https://statycc.github.io/pymwp/examples/).
Refer to **[statycc.github.io/pymwp](https://statycc.github.io/pymwp/)** for a documentation, an [online demo](https://statycc.github.io/pymwp/demo/), and a presentation of [examples](https://statycc.github.io/pymwp/examples/).

<!--include-start-->

Expand All @@ -49,7 +51,7 @@ pymwp --help
```


You can also use pymwp in a Python script:
You can also use pymwp by importing it in a Python script:

```python
from pymwp import Polynomial
Expand Down
113 changes: 47 additions & 66 deletions c_files/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,52 @@

<!--start-->

|||
| --- | --- |
| **Basics** | Simple C programs performing operations that corresponds to simple derivation trees. |
| `assign_expression.c` | assign result of binary operation to variable |
| `assign_variable.c` | assign using variable |
| `if.c` | assignment within conditional statement |
| `if_else.c` | conditional statement with `if` and `else` |
| `inline_variable.c` | local variable declaration |
| `while_1.c` | while loop with assignment |
| `while_2.c` | while loop with binary operation |
| `while_if.c` | while loop followed by `if...else` |

|||
| --- | --- |
| **Implementation Paper** | Examples from ["mwp-Analysis Improvement and Implementation: Realizing Implicit Computational Complexity"](https://drops.dagstuhl.de/opus/volltexte/2022/16307/pdf/LIPIcs-FSCD-2022-26.pdf) paper. |
| `example8.c` | An illustration of the sum of two choices. |
| `example14.c` | Examples with function call |
| `example16.c` | Example of an inlined function call |

|||
| --- | --- |
| **Infinite** | Programs that are assigned matrices that always contain infinite coefficients, no matter the choices. |
| `exponent_1.c` | exponential computation |
| `exponent_2.c` | alternative exponential computation |
| `infinite_2.c` | `while` loop with binary operations |
| `infinite_3.c` | `while` loop and `if` statement |
| `infinite_4.c` | `while` loop |
| `infinite_5.c` | `while` loop and `if` statement |
| `infinite_6.c` | `if...else` and `while` loop |
| `infinite_7.c` | 2 `while` loops and `if` |
| `infinite_8.c` | `while` with nested `if...else` and other conditionals |

|||
| --- | --- |
| **Not Infinite** | Programs that are assigned matrices that do not always contain infinite coefficients. |
| `notinfinite_2.c` | binary operations |
| `notinfinite_3.c` | `if` and `while` loop |
| `notinfinite_4.c` | `if` and `while` loop |
| `notinfinite_5.c` | `if` and `while` loop |
| `notinfinite_6.c` | `if...else` and `while` loop |
| `notinfinite_7.c` | 2 `while` loops and `if` |
| `notinfinite_8.c` | `while` with nested `if...else` and other conditionals |

|||
| --- | --- |
| **Original Paper** | Examples taken from or inspired from the ["A Flow Calculus of mwp-Bounds for Complexity Analysis"](https://doi.org/10.1145/1555746.1555752) paper. |
| `example3_1_a.c` | Analysis of two commands |
| `example3_1_b.c` | Analysis of two commands |
| `example3_1_c.c` | Binary operation inside `while` loop |
| `example3_1_d.c` | Two variables and a `while` loop |
| `example3_2.c` | Three variables and `while` loop |
| `example3_4.c` | Iteration with 5 variables |
| `example5_1.c` | Adding two variables |
| `example7_10.c` | program with `if...else` and 3 variables |
| `example7_11.c` | Binary operations with 4 variables |

|||
| --- | --- |
| **Other** | Other programs of interest. |
| `dense.c` | Produces a 3 x 3 dense matrix. |
| `dense_loop.c` | Produces a dense matrix with infinite coefficients in it. |
| `explosion.c` | Explosion of the number of cases |
| `for_loop.c` | Loop example using `for` |
| `gcd.c` | Greatest common divisor by subtraction |
| `long.c` | Longer program with multiple loops and nested statements |
| `simplified_dense.c` | Simplified dense matrix |
## List of Examples

| Category | Program | Description |
|----------------------|-----------------------|-----------------------------------------------------------|
| Basics | `assign_expression.c` | assign result of binary operation to variable |
| | `assign_variable.c` | assign using variable |
| | `if.c` | assignment within conditional statement |
| | `if_else.c` | conditional statement with `if` and `else` |
| | `inline_variable.c` | local variable declaration |
| | `while_1.c` | while loop with assignment |
| | `while_2.c` | while loop with binary operation |
| | `while_if.c` | while loop followed by `if...else` |
| Implementation Paper | `example8.c` | An illustration of the sum of two choices. |
| | `example14.c` | Examples with function call |
| | `example16.c` | Example of an inlined function call |
| Infinite | `exponent_1.c` | exponential computation |
| | `exponent_2.c` | alternative exponential computation |
| | `infinite_2.c` | `while` loop with binary operations |
| | `infinite_3.c` | `while` loop and `if` statement |
| | `infinite_4.c` | `while` loop |
| | `infinite_5.c` | `while` loop and `if` statement |
| | `infinite_6.c` | `if...else` and `while` loop |
| | `infinite_7.c` | 2 `while` loops and `if` |
| | `infinite_8.c` | `while` with nested `if...else` and other conditionals |
| Not Infinite | `notinfinite_2.c` | binary operations |
| | `notinfinite_3.c` | `if` and `while` loop |
| | `notinfinite_4.c` | `if` and `while` loop |
| | `notinfinite_5.c` | `if` and `while` loop |
| | `notinfinite_6.c` | `if...else` and `while` loop |
| | `notinfinite_7.c` | 2 `while` loops and `if` |
| | `notinfinite_8.c` | `while` with nested `if...else` and other conditionals |
| Original Paper | `example3_1_a.c` | Analysis of two commands |
| | `example3_1_b.c` | Analysis of two commands |
| | `example3_1_c.c` | Binary operation inside `while` loop |
| | `example3_1_d.c` | Two variables and a `while` loop |
| | `example3_2.c` | Three variables and `while` loop |
| | `example3_4.c` | Iteration with 5 variables |
| | `example5_1.c` | Adding two variables |
| | `example7_10.c` | program with `if...else` and 3 variables |
| | `example7_11.c` | Binary operations with 4 variables |
| Other | `dense.c` | Produces a 3 x 3 dense matrix. |
| | `dense_loop.c` | Produces a dense matrix with infinite coefficients in it. |
| | `explosion.c` | Explosion of the number of cases |
| | `for_loop.c` | Loop example using `for` |
| | `gcd.c` | Greatest common divisor by subtraction |
| | `long.c` | Longer program with multiple loops and nested statements |
| | `simplified_dense.c` | Simplified dense matrix |

<!--end-->
17 changes: 7 additions & 10 deletions docs/assets/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,13 @@
max-width: 100%;
overflow: auto;
position: relative;
border: 1px solid #ddd;
border: 1px solid #dddb;
border-top: none;
box-sizing: border-box;
}

#demo-output .table-wrapper table, #demo-output .table-wrapper table tr > td {
border-color: #ddd;
border-color: #dddb;
}

#demo-output .table-wrapper table {
Expand All @@ -302,7 +302,7 @@
text-align: left;
vertical-align: top;
min-width: 100px;
background: #fff;
background: transparent;
max-width: 300px;
}

Expand All @@ -322,24 +322,22 @@
}

#demo-output .table-wrapper table tr:first-child td,

#demo-output .table-wrapper table tr > td:first-child {
background: #f5f5f5;
background: var(--md-code-bg-color);
}

#demo-output .table-wrapper table tr td:first-child::after {
content: "";
position: absolute;
width: 2px;
background: #ddd;
width: 1px;
background: #dddb;
height: 100%;
right: -1px;
top: 0;
bottom: 0;
}

#demo-output .table-wrapper table tr:first-child code,

#demo-output .table-wrapper table tr > td:first-child code {
font-weight: bold;
box-sizing: border-box;
Expand Down Expand Up @@ -395,8 +393,7 @@
.progress {
-webkit-animation: loader 8s ease infinite;
animation: loader 6s ease infinite;
background: #FF8F00;
color: #fff;
background: var(--md-accent-fg-color);
padding: 5px;
width: 0;
}
Expand Down
Loading

0 comments on commit 887853a

Please sign in to comment.