Tools to aid the development of explanation systems using clingo
Project description
from clingexplaid.transformers.transformer_assumption import FilterSignature
clingexplaid
API to aid the development of explanation systems using clingo
Installation
Clingo-Explaid easily be installed with pip:
pip install clingexplaid
Requirements
python >= 3.9clingo >= 5.7.1
Building from Source
Please refer to DEVELOPEMENT
API
Here are two example for using clingexplaid's API.
Minimal Unsatisfiable Subsets (MUS)
Transforming facts to Assumptions (necessary pre-processing step):
from clingexplaid.preprocessors import AssumptionPreprocessor
from clingexplaid.preprocessors import (
FilterSignature,
FilterPattern,
)
PROGRAM = """
a(book;magazine;video).
b(test).
c(1..10).
d(1..3).
"""
ap = AssumptionPreprocessor(filters=[
FilterSignature("a", 1),
FilterPattern("d(2)")
])
result = ap.process(PROGRAM)
# You can either use the return value of `ap.process`
print(result)
# Or use `ap.control` with your transformed program already added
print(ap.control)
You can also use an existing control and pass it to the
AssumptionPreprocessor as follows:
FILE = "local/encoding.lp"
ctl = clingo.Control("0")
ap = AssumptionPreprocessor(
control=ctl,
filters=[
FilterSignature("a", 1),
FilterPattern("d(2)")
])
ap.process_files([FILE])
# The transformed files are added to ctl so it can be directly used
ctl.ground([("base", [])])
ctl.solve()
Getting a single MUS:
from clingexplaid.preprocessors import AssumptionPreprocessor, FilterSignature
from clingexplaid.mus import CoreComputer
PROGRAM = """
a(1..3).
{b(4..6)}.
a(X) :- b(X).
:- a(X), X>=3.
"""
ap = AssumptionPreprocessor(filters={FilterSignature("a", 1)})
ap.process(PROGRAM)
ap.control.ground([("base", [])])
cc = CoreComputer(ap.control, ap.assumptions)
def shrink_on_core(core) -> None:
mus_literals = cc.shrink(core)
print("MUS:", cc.mus_to_string(mus_literals))
ap.control.solve(
assumptions=list(ap.assumptions),
on_core=shrink_on_core
)
Getting multiple MUS:
import clingo
from clingexplaid.transformers import AssumptionTransformer
from clingexplaid.mus import CoreComputer
PROGRAM = """
a(1..3).
b(1..3).
:- a(X), b(X).
"""
at = AssumptionTransformer()
transformed_program = at.parse_string(PROGRAM)
control = clingo.Control()
control.add("base", [], transformed_program)
control.ground([("base", [])])
assumptions = at.get_assumption_literals(control)
cc = CoreComputer(control, assumptions)
mus_generator = cc.get_multiple_minimal()
for i, mus in enumerate(mus_generator):
print(f"MUS {i}:", cc.mus_to_string(mus))
Unsatisfiable Constraints
from clingexplaid.unsat_constraints import UnsatConstraintComputer
PROGRAM = """
a(1..3).
{b(4..6)}.
a(X) :- b(X).
:- a(X), X>=3.
"""
ucc = UnsatConstraintComputer()
ucc.parse_string(PROGRAM)
unsat_constraints = ucc.get_unsat_constraints()
for uc_id, unsat_constraint in unsat_constraints.items():
print(f"Unsat Constraint {uc_id}:", unsat_constraint)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file clingexplaid-1.3.4.tar.gz.
File metadata
- Download URL: clingexplaid-1.3.4.tar.gz
- Upload date:
- Size: 80.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce34ea88402c362794091f86312b2f467aa7034fa0037d9759345ac37d267bfe
|
|
| MD5 |
a6c1de218510e06d12e6f159ac6f2b4c
|
|
| BLAKE2b-256 |
3cefad2adca8f60ee61eb6fa52eb3620896057d258a8a7d33ba8f6d79443d3d3
|
Provenance
The following attestation bundles were made for clingexplaid-1.3.4.tar.gz:
Publisher:
deploy.yml on potassco/clingo-explaid
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
clingexplaid-1.3.4.tar.gz -
Subject digest:
ce34ea88402c362794091f86312b2f467aa7034fa0037d9759345ac37d267bfe - Sigstore transparency entry: 284570499
- Sigstore integration time:
-
Permalink:
potassco/clingo-explaid@941c884d0d28bc42a5356ebbf237b6eb76bdde68 -
Branch / Tag:
refs/tags/v1.3.4 - Owner: https://github.com/potassco
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
deploy.yml@941c884d0d28bc42a5356ebbf237b6eb76bdde68 -
Trigger Event:
push
-
Statement type:
File details
Details for the file clingexplaid-1.3.4-py3-none-any.whl.
File metadata
- Download URL: clingexplaid-1.3.4-py3-none-any.whl
- Upload date:
- Size: 31.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7af01c8f87c11e301a6fcfed954715334d7185cdbd9b68ec416df5c63eea2e19
|
|
| MD5 |
d8ea1d528d876561c80304af7f0a309c
|
|
| BLAKE2b-256 |
29162a91d62fca9be3b7fdec0607987d04a7a664ec1ca15497196e1ffa566b38
|
Provenance
The following attestation bundles were made for clingexplaid-1.3.4-py3-none-any.whl:
Publisher:
deploy.yml on potassco/clingo-explaid
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
clingexplaid-1.3.4-py3-none-any.whl -
Subject digest:
7af01c8f87c11e301a6fcfed954715334d7185cdbd9b68ec416df5c63eea2e19 - Sigstore transparency entry: 284570586
- Sigstore integration time:
-
Permalink:
potassco/clingo-explaid@941c884d0d28bc42a5356ebbf237b6eb76bdde68 -
Branch / Tag:
refs/tags/v1.3.4 - Owner: https://github.com/potassco
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
deploy.yml@941c884d0d28bc42a5356ebbf237b6eb76bdde68 -
Trigger Event:
push
-
Statement type: