Skip to content

Commit

Permalink
cvc5 is now under env variable KNUCKLE_SOLVER
Browse files Browse the repository at this point in the history
  • Loading branch information
philzook58 committed Aug 9, 2024
1 parent c94f6a7 commit 355c19c
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 78 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ jobs:
publish_branch: gh-pages
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: _build/
force_orphan: true
force_orphan: true
40 changes: 20 additions & 20 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,34 @@ name: Python package

on:
push:
branches: [ "main" ]
branches: ["main"]
pull_request:
branches: [ "main" ]
branches: ["main"]

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install ruff pytest
python -m pip install -e .
- name: Lint with Ruff
run: |
ruff check --output-format=github .
continue-on-error: true
- name: Test with pytest
run: |
pytest
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install ruff pytest
python -m pip install -e .
- name: Lint with Ruff
run: |
ruff check --output-format=github .
continue-on-error: true
- name: Test with pytest
run: |
pytest
KNUCKLE_SOLVER=cvc5 pytest
3 changes: 2 additions & 1 deletion knuckledragger/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from . import smt
from . import kernel
from . import notation
from . import tactics
import knuckledragger.smt as smt


lemma = tactics.lemma
axiom = kernel.axiom
Expand Down
10 changes: 0 additions & 10 deletions knuckledragger/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,7 @@ def define(name: str, args: list[smt.ExprRef], body: smt.ExprRef) -> smt.FuncDec
tuple[smt.FuncDeclRef, __Proof]: A tuple of the defined term and the proof of the definition.
"""
sorts = [arg.sort() for arg in args] + [body.sort()]
print(sorts)
f = smt.Function(name, *sorts)
print(f.range())
print(f.arity())
print(f.domain(0))
print(f(*args).sort())
print(body.sort())
f(*args) == body
# import cvc5

# print(cvc5.__version__)
if len(args) > 0:
def_ax = axiom(smt.ForAll(args, f(*args) == body), by="definition")
else:
Expand Down
99 changes: 53 additions & 46 deletions knuckledragger/smt.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,55 @@
# from z3 import *
import cvc5
from cvc5.pythonic import *

Z3PPObject = object
FuncDecl = FuncDeclRef


class Solver(cvc5.pythonic.Solver):
def __init__(self):
super().__init__()
self.set("produce-unsat-cores", "true")

def set(self, option, value):
if option == "timeout":
self.set("tlimit-per", value)
import os

Z3SOLVER = "z3"
CVC5SOLVER = "cvc5"
solver = os.getenv("KNUCKLE_SOLVER")
if solver is None or solver == Z3SOLVER:
solver = "z3"
from z3 import *

Check failure on line 8 in knuckledragger/smt.py

View workflow job for this annotation

GitHub Actions / build (3.9)

Ruff (F403)

knuckledragger/smt.py:8:5: F403 `from z3 import *` used; unable to detect undefined names

Check failure on line 8 in knuckledragger/smt.py

View workflow job for this annotation

GitHub Actions / build (3.10)

Ruff (F403)

knuckledragger/smt.py:8:5: F403 `from z3 import *` used; unable to detect undefined names

Check failure on line 8 in knuckledragger/smt.py

View workflow job for this annotation

GitHub Actions / build (3.11)

Ruff (F403)

knuckledragger/smt.py:8:5: F403 `from z3 import *` used; unable to detect undefined names
elif solver == CVC5SOLVER:
import cvc5
from cvc5.pythonic import *

Check failure on line 11 in knuckledragger/smt.py

View workflow job for this annotation

GitHub Actions / build (3.9)

Ruff (F403)

knuckledragger/smt.py:11:5: F403 `from cvc5.pythonic import *` used; unable to detect undefined names

Check failure on line 11 in knuckledragger/smt.py

View workflow job for this annotation

GitHub Actions / build (3.10)

Ruff (F403)

knuckledragger/smt.py:11:5: F403 `from cvc5.pythonic import *` used; unable to detect undefined names

Check failure on line 11 in knuckledragger/smt.py

View workflow job for this annotation

GitHub Actions / build (3.11)

Ruff (F403)

knuckledragger/smt.py:11:5: F403 `from cvc5.pythonic import *` used; unable to detect undefined names

Z3PPObject = object
FuncDecl = FuncDeclRef

Check failure on line 14 in knuckledragger/smt.py

View workflow job for this annotation

GitHub Actions / build (3.9)

Ruff (F405)

knuckledragger/smt.py:14:16: F405 `FuncDeclRef` may be undefined, or defined from star imports

Check failure on line 14 in knuckledragger/smt.py

View workflow job for this annotation

GitHub Actions / build (3.10)

Ruff (F405)

knuckledragger/smt.py:14:16: F405 `FuncDeclRef` may be undefined, or defined from star imports

Check failure on line 14 in knuckledragger/smt.py

View workflow job for this annotation

GitHub Actions / build (3.11)

Ruff (F405)

knuckledragger/smt.py:14:16: F405 `FuncDeclRef` may be undefined, or defined from star imports

class Solver(cvc5.pythonic.Solver):
def __init__(self):
super().__init__()
self.set("produce-unsat-cores", "true")

def set(self, option, value):
if option == "timeout":
self.set("tlimit-per", value)
else:
super().set(option, value)

def assert_and_track(self, thm, name):
x = Bool(name)

Check failure on line 28 in knuckledragger/smt.py

View workflow job for this annotation

GitHub Actions / build (3.9)

Ruff (F405)

knuckledragger/smt.py:28:17: F405 `Bool` may be undefined, or defined from star imports

Check failure on line 28 in knuckledragger/smt.py

View workflow job for this annotation

GitHub Actions / build (3.10)

Ruff (F405)

knuckledragger/smt.py:28:17: F405 `Bool` may be undefined, or defined from star imports

Check failure on line 28 in knuckledragger/smt.py

View workflow job for this annotation

GitHub Actions / build (3.11)

Ruff (F405)

knuckledragger/smt.py:28:17: F405 `Bool` may be undefined, or defined from star imports
self.add(x)
return self.add(Implies(x, thm))

Check failure on line 30 in knuckledragger/smt.py

View workflow job for this annotation

GitHub Actions / build (3.9)

Ruff (F405)

knuckledragger/smt.py:30:29: F405 `Implies` may be undefined, or defined from star imports

Check failure on line 30 in knuckledragger/smt.py

View workflow job for this annotation

GitHub Actions / build (3.10)

Ruff (F405)

knuckledragger/smt.py:30:29: F405 `Implies` may be undefined, or defined from star imports

Check failure on line 30 in knuckledragger/smt.py

View workflow job for this annotation

GitHub Actions / build (3.11)

Ruff (F405)

knuckledragger/smt.py:30:29: F405 `Implies` may be undefined, or defined from star imports

def unsat_core(self):
return [cvc5.pythonic.BoolRef(x) for x in self.solver.getUnsatCore()]

def Const(name, sort):
# _to_expr doesn't have a DatatypeRef case
x = cvc5.pythonic.Const(name, sort)
if isinstance(sort, DatatypeSortRef):

Check failure on line 38 in knuckledragger/smt.py

View workflow job for this annotation

GitHub Actions / build (3.9)

Ruff (F405)

knuckledragger/smt.py:38:29: F405 `DatatypeSortRef` may be undefined, or defined from star imports

Check failure on line 38 in knuckledragger/smt.py

View workflow job for this annotation

GitHub Actions / build (3.10)

Ruff (F405)

knuckledragger/smt.py:38:29: F405 `DatatypeSortRef` may be undefined, or defined from star imports

Check failure on line 38 in knuckledragger/smt.py

View workflow job for this annotation

GitHub Actions / build (3.11)

Ruff (F405)

knuckledragger/smt.py:38:29: F405 `DatatypeSortRef` may be undefined, or defined from star imports
x = DatatypeRef(x.ast, x.ctx, x.reverse_children)

Check failure on line 39 in knuckledragger/smt.py

View workflow job for this annotation

GitHub Actions / build (3.9)

Ruff (F405)

knuckledragger/smt.py:39:17: F405 `DatatypeRef` may be undefined, or defined from star imports

Check failure on line 39 in knuckledragger/smt.py

View workflow job for this annotation

GitHub Actions / build (3.10)

Ruff (F405)

knuckledragger/smt.py:39:17: F405 `DatatypeRef` may be undefined, or defined from star imports

Check failure on line 39 in knuckledragger/smt.py

View workflow job for this annotation

GitHub Actions / build (3.11)

Ruff (F405)

knuckledragger/smt.py:39:17: F405 `DatatypeRef` may be undefined, or defined from star imports
return x

def Consts(names, sort):
return [Const(name, sort) for name in names.split()]

def _qsort(self):
if self.is_lambda():
return ArraySort(self.var_sort(0), self.body().sort())

Check failure on line 47 in knuckledragger/smt.py

View workflow job for this annotation

GitHub Actions / build (3.9)

Ruff (F405)

knuckledragger/smt.py:47:20: F405 `ArraySort` may be undefined, or defined from star imports

Check failure on line 47 in knuckledragger/smt.py

View workflow job for this annotation

GitHub Actions / build (3.10)

Ruff (F405)

knuckledragger/smt.py:47:20: F405 `ArraySort` may be undefined, or defined from star imports

Check failure on line 47 in knuckledragger/smt.py

View workflow job for this annotation

GitHub Actions / build (3.11)

Ruff (F405)

knuckledragger/smt.py:47:20: F405 `ArraySort` may be undefined, or defined from star imports
else:
super().set(option, value)

def assert_and_track(self, thm, name):
x = Bool(name)
self.add(x)
return self.add(Implies(x, thm))

def unsat_core(self):
return [cvc5.pythonic.BoolRef(x) for x in self.solver.getUnsatCore()]


def Const(name, sort):
# _to_expr doesn't have a DatatypeRef case
x = cvc5.pythonic.Const(name, sort)
if isinstance(sort, DatatypeSortRef):
x = DatatypeRef(x.ast, x.ctx, x.reverse_children)
return x


def Consts(names, sort):
return [Const(name, sort) for name in names.split()]


def _qsort(self):
if self.is_lambda():
return ArraySort(self.var_sort(0), self.body().sort())
else:
return BoolSort(self.ctx)

return BoolSort(self.ctx)

QuantifierRef.sort = _qsort
QuantifierRef.sort = _qsort
else:
raise ValueError(
"Unknown solver in environment variable KNUCKLE_SOLVER: {}".format(solver)
)

0 comments on commit 355c19c

Please sign in to comment.