Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
6facc2c
Add unit tests and update api reference
ColtonPayne Aug 8, 2025
6990e03
Demo floating point wierdness
ColtonPayne Aug 8, 2025
307004e
Add pre-commit hook for pytest
ColtonPayne Aug 8, 2025
5522d33
Upd pre-commit
ColtonPayne Aug 8, 2025
6cfc330
Upd
ColtonPayne Aug 8, 2025
87bb9c7
Add pre-push hook for functional tests
ColtonPayne Aug 8, 2025
53d3bc5
Add contributing.md
ColtonPayne Aug 8, 2025
84c89c8
Add ruff linter
ColtonPayne Aug 8, 2025
ce96151
Revert "Add ruff linter"
ColtonPayne Aug 8, 2025
a4f136f
Add support for ruff linter
ColtonPayne Aug 8, 2025
5af8466
Add a comment
ColtonPayne Aug 11, 2025
e618cdd
add initial classifier tests
ColtonPayne Aug 18, 2025
198d20e
Merge pull request #1 from ColtonPayne/add-pytest
ColtonPayne Aug 24, 2025
da0621b
test: add JIT consistency check for hello world
ColtonPayne Aug 24, 2025
ff247ab
Merge pull request #2 from ColtonPayne/codex/add-tests-for-jit-and-pu…
ColtonPayne Aug 24, 2025
d88f451
test: revise hello world consistency
ColtonPayne Aug 24, 2025
9b63e31
Merge branch 'main' into codex/add-tests-for-jit-and-pure-python-cons…
ColtonPayne Aug 24, 2025
d5f1296
Merge pull request #3 from ColtonPayne/codex/add-tests-for-jit-and-pu…
ColtonPayne Aug 24, 2025
609a3bf
test: expand _ground_rule coverage
ColtonPayne Aug 24, 2025
2c4dd66
test: fix interval constructor for hello world consistency
ColtonPayne Aug 24, 2025
a947acb
Merge branch 'main' into codex/add-tests-for-jit-and-pure-python-cons…
ColtonPayne Aug 24, 2025
e7cfe09
test: filter edge groundings when node clause narrows
ColtonPayne Aug 24, 2025
a382cf9
Merge pull request #5 from ColtonPayne/codex/add-tests-for-jit-and-pu…
ColtonPayne Aug 24, 2025
7d54a2c
test: cover node recheck failure branch
ColtonPayne Aug 24, 2025
8c15823
test: cover edge head node reuse
ColtonPayne Aug 24, 2025
44b25de
test: cover edge recheck in _ground_rule
ColtonPayne Aug 24, 2025
c8ef7a8
Merge pull request #4 from ColtonPayne/codex/add-tests-for-full-branc…
ColtonPayne Aug 24, 2025
bfca28a
Pull in new changesz
ColtonPayne Aug 31, 2025
132f5ee
Merge pull request #8 from ColtonPayne/lab-v2-main
ColtonPayne Aug 31, 2025
63d2feb
Merge pull request #9 from ColtonPayne/add-pytest
ColtonPayne Aug 31, 2025
fbe3836
Update interpretation tests to use new fixed point module
ColtonPayne Aug 31, 2025
627361e
Merge pull request #10 from ColtonPayne/codex/explain-interpretation_…
ColtonPayne Aug 31, 2025
3a36b7d
Add tests for interpretation helpers
ColtonPayne Aug 31, 2025
de32278
test: expand reason coverage
ColtonPayne Aug 31, 2025
4efc5a6
test: cover reason persistence branches
ColtonPayne Aug 31, 2025
3a1ec05
test: extend reason branch coverage
ColtonPayne Aug 31, 2025
84f8320
test: cover additional reason branches
ColtonPayne Aug 31, 2025
e2293e6
test: cover edge additions and static traces
ColtonPayne Aug 31, 2025
d25c009
test: cover edge atom and inconsistency branches
ColtonPayne Aug 31, 2025
3806dbf
test: cover additional reason branches
ColtonPayne Aug 31, 2025
a41099e
Split interpretation tests into modules
ColtonPayne Aug 31, 2025
63028a3
test: expand node rule coverage
ColtonPayne Sep 1, 2025
4cc4555
test: cover edge rule branches in reason
ColtonPayne Sep 7, 2025
ce21a8f
test: cover delta-bound rule branches
ColtonPayne Sep 7, 2025
8824a5e
test: cover edge rule static and inconsistency branches
ColtonPayne Sep 7, 2025
bdfffb1
test: cover remaining edge convergence branches
ColtonPayne Sep 7, 2025
c99493b
test: cover convergence break conditions
ColtonPayne Sep 7, 2025
9314a24
test: assert convergence break outputs
ColtonPayne Sep 7, 2025
ea5783b
Merge pull request #11 from ColtonPayne/codex/add-unit-tests-for-help…
ColtonPayne Sep 7, 2025
1a0deb8
test: exercise _start_fp via real Interpretation
ColtonPayne Sep 7, 2025
aeb144b
Merge pull request #16 from ColtonPayne/codex/review-test-setup-for-i…
ColtonPayne Sep 7, 2025
4c6046b
Move get_dict tests into existing suite
ColtonPayne Sep 7, 2025
8db807e
Add tests for get_final_num_ground_atoms and query
ColtonPayne Sep 7, 2025
185a370
Add tests for update helpers
ColtonPayne Sep 7, 2025
cc4fb0d
Cover override and tracing branches in update_node
ColtonPayne Sep 7, 2025
9049106
test: cover complement branches in _update_node
ColtonPayne Sep 7, 2025
93c359d
test: cover _update_edge complement bookkeeping
ColtonPayne Sep 7, 2025
1b2a752
test: cover _update_edge for both interpretations
ColtonPayne Sep 7, 2025
206129c
Cover _update_edge complement delta branches
ColtonPayne Sep 7, 2025
783519b
Cover complement predicate edge branches
ColtonPayne Sep 7, 2025
c651ecb
Merge pull request #17 from ColtonPayne/codex/add-full-branch-coverag…
ColtonPayne Sep 7, 2025
aee6fea
Revert "Add branch coverage tests for get_dict"
ColtonPayne Sep 7, 2025
5d8dc6e
Merge pull request #18 from ColtonPayne/revert-17-codex/add-full-bran…
ColtonPayne Sep 7, 2025
f67bb48
Revert "Revert "Add branch coverage tests for get_dict""
ColtonPayne Sep 7, 2025
3b8587b
Merge pull request #19 from ColtonPayne/revert-18-revert-17-codex/add…
ColtonPayne Sep 7, 2025
b207301
test: cover node complement branches
ColtonPayne Sep 7, 2025
5d5bb00
test: cover predicate map append
ColtonPayne Sep 7, 2025
d54e47f
test: exercise node and edge branches
ColtonPayne Sep 7, 2025
68a6f1c
test: cover update_edge complement branches
ColtonPayne Sep 7, 2025
861071a
test: cover comparison and inconsistency branches
ColtonPayne Sep 7, 2025
f731e89
test: cover edge comparison and add-edge branches
ColtonPayne Sep 7, 2025
932644e
Merge pull request #20 from ColtonPayne/codex/add-test-coverage-for-_…
ColtonPayne Sep 7, 2025
caa721f
consolidate interpretation tests
ColtonPayne Sep 7, 2025
7e30a41
Extract reason tests into dedicated modules
ColtonPayne Sep 7, 2025
1c63733
Merge pull request #22 from ColtonPayne/codex/move-tests-to-test_inte…
ColtonPayne Sep 7, 2025
5c6d341
Merge pull request #23 from ColtonPayne/codex/consolidate-test_reason…
ColtonPayne Sep 7, 2025
7f6b63e
Document testing hooks and add jit unit hook
ColtonPayne Sep 7, 2025
a8f2eb4
Merge pull request #24 from ColtonPayne/codex/update-contributing.md-…
ColtonPayne Sep 7, 2025
b345f28
refactor: consolidate interpretation tests
ColtonPayne Sep 7, 2025
53e85a9
Merge pull request #27 from ColtonPayne/codex/consolidate-test_interp…
ColtonPayne Sep 7, 2025
289e892
Add tests for interpretation branch coverage
ColtonPayne Sep 9, 2025
c8908e6
Expand interpretation.reason branch tests
ColtonPayne Sep 9, 2025
44d56ca
test: cover atom trace and static node rule branches
ColtonPayne Sep 9, 2025
62c90a2
test: cover edge rule zero-delta trace
ColtonPayne Sep 9, 2025
a17dfa3
Add tests for verbose convergence, ground atom count, and edge threshold
ColtonPayne Sep 9, 2025
7867b47
Merge pull request #29 from ColtonPayne/codex/add-unit-tests-for-inte…
ColtonPayne Sep 9, 2025
943282b
Upd naming of old interp tests
ColtonPayne Sep 9, 2025
b53ad97
Merge pull request #30 from ColtonPayne/upd-interp-tests
ColtonPayne Sep 9, 2025
e10e68e
Rm old classifier tests
ColtonPayne Sep 9, 2025
834b6ba
Merge pull request #31 from ColtonPayne/prep-for-pr
ColtonPayne Sep 9, 2025
5a6110f
test: cover interpretation init and start_fp
ColtonPayne Sep 9, 2025
815dd2a
Merge pull request #32 from ColtonPayne/codex/add-tests-for-interpret…
ColtonPayne Sep 9, 2025
97b6162
Remove unrelated changes
ColtonPayne Sep 9, 2025
d27c265
Merge pull request #33 from ColtonPayne/more-pr-prep
ColtonPayne Sep 9, 2025
7414c44
Add cache status back
ColtonPayne Sep 9, 2025
a22736f
Merge pull request #34 from ColtonPayne/more-pr-prep
ColtonPayne Sep 9, 2025
b1832a6
Newline
ColtonPayne Sep 9, 2025
202b08f
Merge pull request #35 from ColtonPayne/more-pr-prep
ColtonPayne Sep 9, 2025
ec95577
Add tests for annotation functions
ColtonPayne Sep 13, 2025
4c6d3e7
Merge pull request #36 from ColtonPayne/codex/add-unit-tests-for-anno…
ColtonPayne Sep 13, 2025
1b04907
Upd
ColtonPayne Sep 15, 2025
fdd1e87
Upd
ColtonPayne Sep 15, 2025
50a8524
Merge pull request #38 from ColtonPayne/fix-flake8-linting
ColtonPayne Sep 15, 2025
dfcbc62
Upd pytest unit tests
ColtonPayne Sep 15, 2025
01eb5ef
Merge pull request #39 from ColtonPayne/fix-flake8-linting
ColtonPayne Sep 15, 2025
2e40431
Add other test suites
ColtonPayne Sep 15, 2025
c5e5008
Merge pull request #40 from ColtonPayne/fix-flake8-linting
ColtonPayne Sep 15, 2025
780d37f
Add copilot fix
ColtonPayne Sep 15, 2025
14b0d89
Merge pull request #41 from ColtonPayne/fix-flake8-linting
ColtonPayne Sep 15, 2025
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
15 changes: 8 additions & 7 deletions .github/workflows/python-package-version-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ jobs:
python -m pip install flake8 pytest
pip install torch==2.6.0
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
- name: Pytest Unit Tests with JIT Disabled
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
pytest tests/unit/disable_jit
- name: Pytest Unit Tests with JIT Enabled
run: |
pytest
pytest tests/unit/dont_disable_jit
- name: Pytest Functional Tests
run: |
pytest tests/functional

8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
__pycache__/
*.py[cod]
*$py.class
.cache_status.yaml
.DS_STORE

# C extensions
*.so
Expand Down Expand Up @@ -84,6 +86,12 @@ target/
profile_default/
ipython_config.py

#VS Code configs
.vscode/settings.json
.vscode/tasks.json
.vscode/launch.json
.vscode/extensions.json

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
Expand Down
24 changes: 24 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
repos:
- repo: local
hooks:
# --- Unit tests ---
- id: pytest-unit-with-coverage
name: Run unit tests with coverage and open report
entry: bash -c 'pytest tests/unit/disable_jit --cov pyreason --cov-report=html && ( (command -v xdg-open >/dev/null && xdg-open htmlcov/index.html) || (command -v open >/dev/null && open htmlcov/index.html) || (command -v start >/dev/null && start htmlcov/index.html) )'
language: system
pass_filenames: false

- id: pytest-unit-jit
name: Run JIT-enabled unit tests
entry: bash -c 'pytest tests/unit/dont_disable_jit'
language: system
pass_filenames: false

# --- Functional tests ---
- id: pytest-functional
name: Run functional tests
entry: bash -c 'pytest tests/functional'
language: system
pass_filenames: false
# Only run manually, not on every commit
stages: [pre-push]
47 changes: 47 additions & 0 deletions contributing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

## Getting Started

Install the project requirements and the pre-commit framework:

```bash
pip install -r requirements.txt
pip install pre-commit
```

## Setting up Pre-Commit Hooks

To ensure code quality and consistency, enable the pre-commit hooks:

```bash
pre-commit install --hook-type pre-commit --hook-type pre-push
```

On every commit, the hooks will run the unit tests located in
`tests/unit/disable_jit` and `tests/unit/dont_disable_jit`. Functional tests in
`tests/functional` execute on every push. You can trigger all checks manually
with `pre-commit run --all-files`.

## Linting

We are working to update the codebase to comply with `ruff` linting rules. Run
this command to view linting results:

```bash
ruff check .
```

## Running Tests Manually

The automated hooks cover most scenarios, but you can invoke the test suites
directly:

```bash
pytest tests/unit
```

```bash
pytest tests/functional
```

Running tests locally before committing or pushing helps catch issues early and
speeds up code review.
1 change: 0 additions & 1 deletion pyreason/scripts/learning/classification/classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,3 @@ def forward(self, x, t1: int = 0, t2: int = 0) -> Tuple[torch.Tensor, torch.Tens
fact = Fact(fact_str, name=f'{self.identifier}-{class_name}-fact', start_time=t1, end_time=t2)
facts.append(fact)
return output, probabilities, facts

3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ numba==0.59.1
numpy==1.26.4
memory_profiler
pytest
torch
setuptools_scm
pytest-cov
pre-commit

sphinx_rtd_theme
sphinx
Expand Down
Empty file.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pyreason as pr
import numba
import numpy as np
from pyreason.scripts.numba_wrapper.numba_types.interval_type import closed


@numba.njit
Expand All @@ -13,6 +14,17 @@ def probability_func(annotations, weights):
return union_prob, 1


def test_probability_func_consistency():
"""Ensure annotation function behaves the same with and without JIT."""
annotations = numba.typed.List()
annotations.append(numba.typed.List([closed(0.01, 1.0)]))
annotations.append(numba.typed.List([closed(0.2, 1.0)]))
weights = numba.typed.List([1.0, 1.0])
jit_res = probability_func(annotations, weights)
py_res = probability_func.py_func(annotations, weights)
assert jit_res == py_res


def test_annotation_function():
# Reset PyReason
pr.reset()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


def test_anyBurl_rule_1():
graph_path = './tests/knowledge_graph_test_subset.graphml'
graph_path = './tests/functional/knowledge_graph_test_subset.graphml'
pr.reset()
pr.reset_rules()
pr.reset_settings()
Expand Down Expand Up @@ -36,7 +36,7 @@ def test_anyBurl_rule_1():


def test_anyBurl_rule_2():
graph_path = './tests/knowledge_graph_test_subset.graphml'
graph_path = './tests/functional/knowledge_graph_test_subset.graphml'
pr.reset()
pr.reset_rules()
pr.reset_settings()
Expand Down Expand Up @@ -72,7 +72,7 @@ def test_anyBurl_rule_2():


def test_anyBurl_rule_3():
graph_path = './tests/knowledge_graph_test_subset.graphml'
graph_path = './tests/functional/knowledge_graph_test_subset.graphml'
pr.reset()
pr.reset_rules()
pr.reset_settings()
Expand Down Expand Up @@ -108,7 +108,7 @@ def test_anyBurl_rule_3():


def test_anyBurl_rule_4():
graph_path = './tests/knowledge_graph_test_subset.graphml'
graph_path = './tests/functional/knowledge_graph_test_subset.graphml'
pr.reset()
pr.reset_rules()
pr.reset_settings()
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def test_custom_thresholds():
pr.reset_rules()

# Modify the paths based on where you've stored the files we made above
graph_path = "./tests/group_chat_graph.graphml"
graph_path = "./tests/functional/group_chat_graph.graphml"

# Modify pyreason settings to make verbose
pr.reset_settings()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Test if the simple hello world program works
import pyreason as pr
import faulthandler
import json
import os
import subprocess
import sys
import textwrap

# import pyreason.pyreason as pr


def test_hello_world():
Expand All @@ -10,7 +17,7 @@ def test_hello_world():
pr.reset_settings()

# Modify the paths based on where you've stored the files we made above
graph_path = './tests/friends_graph.graphml'
graph_path = './tests/functional/friends_graph.graphml'

# Modify pyreason settings to make verbose
pr.settings.verbose = True # Print info to screen
Expand Down Expand Up @@ -47,3 +54,35 @@ def test_hello_world():

# John should be popular in timestep 3
assert 'John' in dataframes[2]['component'].values and dataframes[2].iloc[1].popular == [1, 1], 'John should have popular bounds [1,1] for t=2 timesteps'

def test_hello_world_consistency():
"""Ensure hello world output matches when using JIT vs pure Python interval constructors."""

import pyreason.scripts.numba_wrapper.numba_types.interval_type as interval_type

def run():
pr.reset()
pr.reset_rules()
pr.reset_settings()
pr.settings.verbose = False
pr.load_graphml('./tests/functional/friends_graph.graphml')
pr.add_rule(pr.Rule('popular(x) <-1 popular(y), Friends(x,y), owns(y,z), owns(x,z)', 'popular_rule'))
pr.add_fact(pr.Fact('popular(Mary)', 'popular_fact', 0, 2))
interpretation = pr.reason(timesteps=2)
dataframes = pr.filter_and_sort_nodes(interpretation, ['popular'])
return [df[['component', 'popular']].to_dict('records') for df in dataframes]

original_closed = interval_type.closed
jit_res = run()
try:
from pyreason.scripts.interval.interval import Interval

def py_closed(lower, upper, static=False):
return Interval(float(lower), float(upper), static)

interval_type.closed = py_closed
py_res = run()
finally:
interval_type.closed = original_closed

assert jit_res == py_res
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def test_hello_world_parallel():
pr.reset_rules()

# Modify the paths based on where you've stored the files we made above
graph_path = './tests/friends_graph.graphml'
graph_path = './tests/functional/friends_graph.graphml'

# Modify pyreason settings to make verbose
pr.reset_settings()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_num_ga.py → tests/functional/test_num_ga.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


def test_num_ga():
graph_path = './tests/knowledge_graph_test_subset.graphml'
graph_path = './tests/functional/knowledge_graph_test_subset.graphml'
pr.reset()
pr.reset_rules()
pr.reset_settings()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def test_reason_again():
pr.reset_settings()

# Modify the paths based on where you've stored the files we made above
graph_path = './tests/friends_graph.graphml'
graph_path = './tests/functional/friends_graph.graphml'

# Modify pyreason settings to make verbose
pr.settings.verbose = True # Print info to screen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def test_reorder_clauses():
pr.reset_settings()

# Modify the paths based on where you've stored the files we made above
graph_path = './tests/friends_graph.graphml'
graph_path = './tests/functional/friends_graph.graphml'

# Modify pyreason settings to make verbose
pr.settings.verbose = True # Print info to screen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def test_rule_filtering():
pr.reset_settings()

# Modify the paths based on where you've stored the files we made above
graph_path = './tests/friends_graph.graphml'
graph_path = './tests/functional/friends_graph.graphml'

# Modify pyreason settings to make verbose
pr.settings.verbose = True # Print info to screen
Expand Down
Loading