Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 19 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,27 @@ jobs:
fail-fast: false
matrix:
os: ['ubuntu-latest']
python-version: ['3.9', '3.11', '3.12']
clingo-version: ['>=5.5.0,<5.6.0','>=5.6.0,<5.7.0','>=5.7.0,<5.8.0']
python-version: ['3.9', '3.11', '3.12','3.14']
clingo-version: ['>=5.5.0,<5.6.0','>=5.6.0,<5.7.0','>=5.7.0,<5.8.0', '>=5.8.0,<5.9.0']
exclude:
- python-version: '3.11'
clingo-version: '>=5.5.0,<5.6.0'
- python-version: '3.12'
clingo-version: '>=5.5.0,<5.6.0'
- python-version: '3.12'
clingo-version: '>=5.6.0,<5.7.0'
- python-version: '3.14'
clingo-version: '>=5.5.0,<5.6.0'
- python-version: '3.14'
clingo-version: '>=5.6.0,<5.7.0'
- python-version: '3.14'
clingo-version: '>=5.7.0,<5.8.0'

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v6

- name: Set up Python
uses: actions/setup-python@v3
uses: actions/setup-python@v6
Comment on lines 31 to +35
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
Expand All @@ -30,15 +43,15 @@ jobs:
python -m pip install clingox==1.2.1.post2 --extra-index-url https://test.pypi.org/simple/
python -m pip install nox
python -m pip install isort

- name: Clingo version
id: clingo-version
run: |
echo "CLINGO_VERSION=$(python -c 'import clingo; print(clingo.__version__)')" >> $GITHUB_ENV

Comment on lines 47 to 51
- name: Cache nox
id: cache-nox
uses: actions/cache@v3
uses: actions/cache@v5
with:
path: .nox
key: ${{ runner.os }}-python-${{ matrix.python-version }}-clingo-${{ env.CLINGO_VERSION }}-nox
Expand Down
14 changes: 5 additions & 9 deletions tests/build_programs.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def _format(self, object, stream, indent, allowance, context, level):


def build_preprocessor_result(
value: Union[str, tuple[str, str]]
value: Union[str, tuple[str, str]],
) -> Tuple[List[Symbol], List[Symbol]]:
if isinstance(value, str):
lower = upper = value
Expand Down Expand Up @@ -161,8 +161,7 @@ def complete_program(program: programs.Program) -> programs_helper.Program:
path = os.path.dirname(os.path.abspath(__file__))
path = os.path.join(path, "generated_programs.py")
with open(path, "w") as f:
f.write(
f'''\
f.write(f'''\
"""
DO NO MODIFY THIS FILE MANUALLY!

Expand All @@ -171,18 +170,15 @@ def complete_program(program: programs.Program) -> programs_helper.Program:
"""


'''
)
f.write(
f"""\
''')
f.write(f"""\
from clingo import Function, Number
from eclingo.solver.candidate import Candidate, Assumptions
from tests.programs_helper import Program

programs = [
{textwrap.indent(str_programs, 4*" ")}
]"""
)
]""")

# for program in programs:
# program = complete_program(program)
Expand Down
2 changes: 1 addition & 1 deletion tests/helper_build_programs.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def build_assumptions(assumptions: str) -> Assumptions:


def build_candidate(
candidate: Union[str, Tuple[str, str]]
candidate: Union[str, Tuple[str, str]],
) -> Optional[List[Candidate]]:
Comment on lines 110 to 112
if isinstance(candidate, str):
return build_candidate_without_assumptions(candidate)
Expand Down
90 changes: 30 additions & 60 deletions tests/test_eclingo.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,57 +66,47 @@ def test_programs_with_default_negation(self):
) # this failed in eclingo
self.assert_models(solve("b :- &k{ not not a }. c :- &k{ b }."), [[]])
self.assert_models(
solve(
"""
solve("""
a :- not c.
c :- not a.
b :- &k{ a }.
:- b.
"""
),
"""),
[[]],
)
self.assert_models(
solve(
"""
solve("""
a :- not c.
c :- not a.
b :- &k{ not a }.
:- b.
"""
),
"""),
[["&m{a}"]],
)
self.assert_models(
solve(
"""
solve("""
a :- not c.
c :- not a.
b :- not &k{ not a }.
d :- &k{ b }.
"""
),
"""),
[["&k{b}", "&m{a}"]],
)
self.assert_models(
solve(
"""
solve("""
a, c.
b :- not &k{ not a }.
d :- &k{ b }.
"""
),
"""),
[["&k{b}", "&m{a}"]],
)
self.assert_models(
solve(
"""
solve("""
p, q.
r :- p.
r :- q.
s :- &k{ r }.
"""
),
"""),
[["&k{r}"]],
)

Expand Down Expand Up @@ -164,104 +154,88 @@ def test_programs_with_default_negation(self):
solve("b :- &k{ not not a(X) }, dom(X). dom(1..2). c :- &k{ b }."), [[]]
)
self.assert_models(
solve(
"""
solve("""
a(1) :- not c(1).
c(1) :- not a(1).
b(X) :- &k{ a(X) }, dom(X).
:- b(X), dom(X).
dom(1..2).
"""
),
"""),
[[]],
)
self.assert_models(
solve(
"""
solve("""
a(1) :- not c(1).
c(1) :- not a(1).
b(X) :- &k{ not a(X) }, dom(X).
dom(1..2).
:- b(1).
:- not b(2).
"""
),
"""),
[["&m{a(1)}"]],
)
self.assert_models(
solve(
"""
solve("""
a(1) :- not c(1).
c(1) :- not a(1).
b(X) :- not &k{ not a(X) }, dom(X).
dom(1..2).
d(X) :- &k{ b(X) }.
"""
),
"""),
[["&m{a(1)}", "&k{b(1)}"]],
)
self.assert_models(
solve(
"""
solve("""
a(1), c(1).
b(X) :- not &k{ not a(X) }, dom(X).
dom(1..2).
d(X) :- &k{ b(X) }.
"""
),
"""),
[["&m{a(1)}", "&k{b(1)}"]],
)

def test_grounding_simplifications(self):
self.assert_models(
solve(
"""
solve("""
dom(1..2).
:- &k{ a(X) }, not a(X), dom(X).
a(1).
{a(2)}.
:- {a(2)} = 0.
"""
),
"""),
[["&k{a(1)}", "&k{a(2)}"]],
)


class TestEclingoAggregates(TestCase):
def test_ground_programs(self):
self.assert_models(
solve(
"""
solve("""
a.
b :- a.
c :- &k{b}.
d :- &k{c}.
"""
),
"""),
[["&k{b}", "&k{c}"]],
)

self.assert_models(
solve(
"""
solve("""
a.
b :- #count{a} >= 1.
c :- &k{b}.
d :- &k{c}.
"""
),
"""),
[["&k{b}", "&k{c}"]],
)

self.assert_models(
solve(
"""
solve("""
a :- not &k{ not a}.
b :- a.
c :- &k{b}.
d :- &k{c}.
"""
),
"""),
[[], ["&m{a}", "&k{b}", "&k{c}"]],
)

Expand Down Expand Up @@ -325,24 +299,20 @@ def test_ground_programs(self):
class TestEclingoUnfounded(TestCase): # pylint: disable=invalid-name
def test_ground_programs(self):
self.assert_models(
solve(
"""
solve("""
a, b.
a :- &k{b}.
b :- &k{a}.
"""
),
"""),
[[], ["&k{a}", "&k{b}"]],
)
self.assert_models(
solve(
"""
solve("""
{a}.
b :- a.
c :- not a.
c :- &k{b}.
b :- &k{c}.
"""
),
"""),
[[], ["&k{b}", "&k{c}"]],
)
6 changes: 2 additions & 4 deletions tests/test_generator_reification.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,7 @@ def test_generator_programs(self):
def test_generator02_reification(self):
# echo "-a. b :- &k{-a}. c :- &k{b}." | eclingo --semantics c19-1 --reification --output=reify
self.assert_models(
generate(
"""tag(incremental).
generate("""tag(incremental).
atom_tuple(0). atom_tuple(0,1). literal_tuple(0). rule(disjunction(0),normal(0)).
atom_tuple(1). atom_tuple(1,2). rule(choice(1),normal(0)).
atom_tuple(2). atom_tuple(2,3). literal_tuple(1).
Expand All @@ -283,8 +282,7 @@ def test_generator02_reification(self):
rule(disjunction(4),normal(3)). output(k(u(-a)),1). output(k(u(b)),3). output(u(-a),0).
output(u(b),2). literal_tuple(4). literal_tuple(4,5). output(u(c),4).
rule(choice(1),normal(0)). rule(disjunction(2),normal(1)). rule(choice(3),normal(2)).
rule(disjunction(4),normal(3))."""
),
rule(disjunction(4),normal(3))."""),
[
# Candidate(pos=[], neg=[Function('k', [Function('u', [Function('b', [], True)], True)], True),
# Function('k', [Function('u', [Function('a', [], False)], True)], True)]),
Expand Down
6 changes: 2 additions & 4 deletions tests/test_solver_reification.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ def test_solver_reification01(self):
def test_solver_reification_explicit_negation(self):
# echo "-a. b :- &k{-a}. c :- &k{b}." | eclingo --semantics c19-1 --reification
self.assert_models(
solve(
"""tag(incremental).
solve("""tag(incremental).
atom_tuple(0). atom_tuple(0,1). literal_tuple(0). rule(disjunction(0),normal(0)).
atom_tuple(1). atom_tuple(1,2). rule(choice(1),normal(0)).
atom_tuple(2). atom_tuple(2,3). literal_tuple(1).
Expand All @@ -64,8 +63,7 @@ def test_solver_reification_explicit_negation(self):
rule(disjunction(4),normal(3)). output(k(u(-a)),1). output(k(u(b)),3). output(u(-a),0).
output(u(b),2). literal_tuple(4). literal_tuple(4,5). output(u(c),4).
rule(choice(1),normal(0)). rule(disjunction(2),normal(1)). rule(choice(3),normal(2)).
rule(disjunction(4),normal(3))."""
),
rule(disjunction(4),normal(3))."""),
[
WorldView(
[
Expand Down