Skip to content

Commit 78252b9

Browse files
authored
Merge pull request #138 from lab-v2/main
upd ai docs branch
2 parents f39a39f + cecfd97 commit 78252b9

49 files changed

Lines changed: 5886 additions & 591 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.pre-commit-config.yaml

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,51 @@
1-
exclude: 'pyreason/\.cache_status\.yaml'
1+
exclude: 'pyreason/\.cache_status\.yaml|pyreason/scripts/interpretation/interpretation_parallel\.py'
22
repos:
33
- repo: https://github.com/pre-commit/pre-commit-hooks
44
rev: v5.0.0
55
hooks:
66
- id: end-of-file-fixer
77
name: Fix end of files
8+
exclude: 'pyreason/scripts/interpretation/interpretation_parallel\.py'
89
stages: [pre-commit]
910

1011
- repo: local
1112
hooks:
1213
# --- COMMIT STAGE: Fast unit tests only ---
1314
- id: ruff-check
1415
name: Run ruff linter
15-
entry: .venv/bin/python -m ruff check pyreason/scripts
16+
entry: ruff check pyreason/scripts
1617
language: system
1718
types: [python]
1819
pass_filenames: false
1920
stages: [pre-commit]
20-
21-
- id: sync-interpretation-parallel
22-
name: Sync interpretation_parallel.py from interpretation.py
23-
entry: .venv/bin/python sync_interpretation_parallel.py
24-
language: system
25-
pass_filenames: false
26-
files: 'pyreason/scripts/interpretation/interpretation\.py'
27-
stages: [pre-commit]
28-
21+
2922
- id: pytest-unit-no-jit
3023
name: Run JIT-disabled unit tests
31-
entry: .venv/bin/python -m pytest tests/unit/disable_jit -m "not slow" --tb=short -q
24+
entry: pytest tests/unit/disable_jit --tb=short -q
3225
language: system
3326
pass_filenames: false
3427
stages: [pre-commit]
28+
require_serial: true
3529

3630
- id: pytest-unit-jit
3731
name: Run JIT-enabled unit tests
38-
entry: .venv/bin/python -m pytest tests/unit/dont_disable_jit -m "not slow" --tb=short -q
32+
entry: pytest tests/unit/dont_disable_jit --tb=short -q
3933
language: system
4034
pass_filenames: false
4135
stages: [pre-commit]
36+
require_serial: true
4237

4338
# --- PUSH STAGE: Complete test suite ---
4439
- id: pytest-unit-api
4540
name: Run pyreason api tests
46-
entry: .venv/bin/python -m pytest tests/api_tests --tb=short -q
41+
entry: pytest tests/api_tests --tb=short -q
4742
language: system
4843
pass_filenames: false
4944
stages: [pre-push]
5045

5146
- id: pytest-functional-complete
5247
name: Run functional test suite
53-
entry: .venv/bin/python -m pytest tests/functional/ --tb=short -q
48+
entry: pytest tests/functional/ --tb=short -q
5449
language: system
5550
pass_filenames: false
56-
stages: [pre-push]
51+
stages: [pre-push]

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ test-api: ## Run only API tests (tests/api_tests)
8585

8686
test-jit: ## Run only JIT-disabled tests (tests/unit/disable_jit)
8787
@echo "$(BOLD)$(BLUE)Running JIT-disabled tests...$(RESET)"
88-
$(RUN_TESTS) --suite don_disable_jit
88+
$(RUN_TESTS) --suite dont_disable_jit
8989

9090
test-no-jit: ## Run only JIT-enabled tests (tests/unit/dont_disable_jit)
9191
@echo "$(BOLD)$(BLUE)Running JIT-enabled tests...$(RESET)"

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ An explainable inference software supporting annotated, real valued, graph based
1414

1515
[📽️ Video](https://www.youtube.com/watch?v=E1PSl3KQCmo)
1616

17-
[🌐 Website](https://pyreason-staging.sites.syr.edu)
17+
[🌐 Website](https://pyreason.syracuse.edu/)
1818

1919
[🏋️‍♂️ PyReason Gym](https://github.com/lab-v2/pyreason-gym)
2020

@@ -64,7 +64,7 @@ Trademark Permission PyReason™ and PyReason Design Logo <img src="https://raw.
6464

6565

6666
## 6. Contact
67-
Dyuman Aditya - daditya@syr.edu
67+
Colton Payne - crpayne@syr.edu
6868

6969
Kaustuv Mukherji - kmukherj@syr.edu
7070

examples/closed_world_pred_ex.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import pyreason as pr
2+
import networkx as nx
3+
from pprint import pprint
4+
5+
pr.reset()
6+
pr.reset_rules()
7+
8+
g = nx.DiGraph()
9+
10+
g.add_nodes_from(['cb_1', 'cb_2', 'l1', 'l2'])
11+
g.add_edge('cb_1', 'cb_2', stepFrom =1)
12+
g.add_edge('cb_1', 'l1', hasLabel = 1)
13+
g.add_edge('cb_2', 'l2', hasLabel = 1)
14+
#g.add_edge('l1','l2', cond=1) # Adding this edge will satisfy hackerControl(cb)
15+
16+
pr.settings.verbose = True
17+
pr.settings.atom_trace = True
18+
pr.settings.inconsistency_check = True
19+
20+
pr.load_graph(g)
21+
22+
# hackerControl is a closed-world pred, meaning that it will be grounded as [0,0] if its bounds are [0,1] (or if it is not in the interpretation dict)
23+
pr.add_closed_world_predicate('hackerControl')
24+
25+
# Initial fact instantiation
26+
pr.add_fact(pr.Fact('stepFrom(cb_1, cb_2)', 'step_from_fact', 0, 1))
27+
pr.add_fact(pr.Fact('hackerControl(cb_1)', 'hacker_control_initial_fact', 0, 0))
28+
29+
# Future(Y) will fire for cb_2
30+
pr.add_rule(pr.Rule('future(Y) <-1 stepFrom(X,Y), hackerControl(X)'))
31+
32+
#This rule will not fire for cb_2, as cond(cb_1, cb_2) is not grounded
33+
pr.add_rule(pr.Rule('hackerControl(Y) <-1 hackerControl(X), hasLabel(X,L1), hasLabel(Y,L2), cond(L1, L2), stepFrom(X,Y)', 'hacker-control-rule'))
34+
35+
# At timestep 1, hackerControl(cb_1) and hackerControl(cb_2) have no associated bounds, so they are treated as [0,1].
36+
# Because hackerControl is minimized, its bounds are gounded as [0,0]. Future(cb_2) has bounds [1,1], so inconsistent(cb_2) fires.
37+
pr.add_rule(pr.Rule('inconsistent(Y) <- future(Y), ~hackerControl(Y), ~hackerControl(X)', 'inconsistent_rule'))
38+
39+
40+
interpretation = pr.reason(timesteps=2)
41+
interp_dict = interpretation.get_dict()
42+
43+
pprint(interp_dict)
44+
45+
# Filter and sort nodes based on hackerControl
46+
dataframes = pr.filter_and_sort_nodes(interpretation, ['hackerControl'])
47+
for t, df in enumerate(dataframes):
48+
print(f'TIMESTEP - {t}')
49+
print(df)
50+
print()
51+
52+
# Filter and sort edges based on inconsistent
53+
edge_dataframes = pr.filter_and_sort_nodes(interpretation, ['inconsistent'])
54+
for t, df in enumerate(edge_dataframes):
55+
print(f'TIMESTEP - {t} (inconsistent nodes)')
56+
print(df)
57+
print()

examples/csv outputs/advanced_rule_trace_edges_20241119-012153.csv renamed to examples/csv_outputs/advanced_rule_trace_edges_20241119-012153.csv

File renamed without changes.

examples/csv outputs/advanced_rule_trace_nodes_20241119-012153.csv renamed to examples/csv_outputs/advanced_rule_trace_nodes_20241119-012153.csv

File renamed without changes.

examples/csv outputs/basic_rule_trace_nodes_20241119-012005.csv renamed to examples/csv_outputs/basic_rule_trace_nodes_20241119-012005.csv

File renamed without changes.

examples/csv outputs/basic_rule_trace_nodes_20241125-114246.csv renamed to examples/csv_outputs/basic_rule_trace_nodes_20241125-114246.csv

File renamed without changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Time,Fixed-Point-Operation,Edge,Label,Old Bound,New Bound,Occurred Due To,Consistent,Triggered By,Inconsistency Message,Clause-1,Clause-2,Clause-3
2+
0,0,"('Alice', 'Bob')",close_contact,"[0.0,1.0]","[0.8,1.0]",alice_bob_close_fact,True,Fact,,,,
3+
0,0,"('Alice', 'Bob')",no_contact,"[0.0,1.0]","[0.0,0.19999999999999996]",IPL: close_contact,True,IPL,,,,
4+
0,0,"('Bob', 'Carol')",trust,"[0.0,1.0]","[0.9,1.0]",bob_carol_trust_high,True,Fact,,,,
5+
0,1,"('Bob', 'Carol')",trust,"[0.9,1.0]","[0.0,1.0]",distrust_rule,False,Rule,"Inconsistency occurred. Conflicting bounds for trust(Bob,Carol). Update from [0.900, 1.000] to [0.000, 0.200] is not allowed. Setting bounds to [0,1] and static=True for this timestep.",['Bob'],"[('Bob', 'Carol')]",
6+
0,1,"('Bob', 'Dave')",trust,"[0.0,1.0]","[0.0,0.2]",distrust_rule,True,Rule,,['Bob'],"[('Bob', 'Dave')]",
7+
0,1,"('Bob', 'Carol')",risk,"[0.0,1.0]","[0.6,0.8]",risk_rule,True,Rule,,['Bob'],"[('Bob', 'Carol')]",
8+
0,1,"('Bob', 'Dave')",risk,"[0.0,1.0]","[0.6,0.8]",risk_rule,True,Rule,,['Bob'],"[('Bob', 'Dave')]",
9+
0,2,"('Bob', 'Dave')",no_contact,"[0.0,1.0]","[0.8,1.0]",quarantine_rule,True,Rule,,['Bob'],['Dave'],"[('Bob', 'Dave')]"
10+
0,2,"('Bob', 'Dave')",close_contact,"[0.0,1.0]","[0.0,0.19999999999999996]",IPL: no_contact,True,IPL,,,,
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Time,Fixed-Point-Operation,Node,Label,Old Bound,New Bound,Occurred Due To,Consistent,Triggered By,Inconsistency Message,Clause-1,Clause-2
2+
0,0,Alice,sick,"[0.0,1.0]","[0.8,1.0]",alice_sick_fact,True,Fact,,,
3+
0,0,Alice,healthy,"[0.0,1.0]","[0.0,0.19999999999999996]",IPL: sick,True,IPL,,,
4+
0,0,Alice,healthy,"[0.0,0.19999999999999996]","[0.0,1.0]",alice_healthy_fact,False,Fact,"Inconsistency occurred. Grounding healthy(Alice) conflicts with grounding sick(Alice). Setting bounds to [0,1] and static=True for this timestep.",,
5+
0,0,Alice,sick,"[0.8,1.0]","[0.0,1.0]",alice_healthy_fact,False,IPL,"Inconsistency occurred. Grounding healthy(Alice) conflicts with grounding sick(Alice). Setting bounds to [0,1] and static=True for this timestep.",,
6+
0,0,Bob,sick,"[0.0,1.0]","[0.6,0.8]",bob_sick_fact,True,Fact,,,
7+
0,0,Bob,healthy,"[0.0,1.0]","[0.19999999999999996,0.4]",IPL: sick,True,IPL,,,
8+
0,0,Carol,healthy,"[0.0,1.0]","[0.9,1.0]",carol_healthy_fact,True,Fact,,,
9+
0,0,Carol,sick,"[0.0,1.0]","[0.0,0.09999999999999998]",IPL: healthy,True,IPL,,,
10+
0,0,Bob,tired,"[0.0,1.0]","[0.8,1.0]",bob_tired_fact_1,True,Fact,,,
11+
0,0,Bob,tired,"[0.8,1.0]","[0.0,1.0]",bob_tired_fact_2,False,Fact,"Inconsistency occurred. Conflicting bounds for tired(Bob). Update from [0.800, 1.000] to [0.000, 0.100] is not allowed. Setting bounds to [0,1] and static=True for this timestep.",,
12+
0,1,Carol,sick,"[0.0,0.09999999999999998]","[0.0,1.0]",spread_rule,False,Rule,"Inconsistency occurred. Grounding sick(Carol) conflicts with grounding healthy(Carol). Setting bounds to [0,1] and static=True for this timestep.",['Bob'],"[('Bob', 'Carol')]"
13+
0,1,Carol,healthy,"[0.9,1.0]","[0.0,1.0]",spread_rule,False,IPL,"Inconsistency occurred. Grounding sick(Carol) conflicts with grounding healthy(Carol). Setting bounds to [0,1] and static=True for this timestep.",,
14+
0,1,Dave,sick,"[0.0,1.0]","[0.5,0.7]",spread_rule,True,Rule,,['Bob'],"[('Bob', 'Dave')]"
15+
0,1,Dave,healthy,"[0.0,1.0]","[0.30000000000000004,0.5]",IPL: sick,True,IPL,,,

0 commit comments

Comments
 (0)