Skip to content

Commit

Permalink
Add test, prepare release candidate 2.2.0rc0
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanzwicknagl committed Oct 24, 2024
1 parent 7a31094 commit 00a9413
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 16 deletions.
3 changes: 2 additions & 1 deletion backend/setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = viasp-backend
version = 2.0.0rc2
version = 2.2.0rc0
author = Luis Glaser
author_email = [email protected]
description = The backend for the viasp package.
Expand All @@ -27,6 +27,7 @@ install_requires =
numpy
clingraph
waitress
sqlalchemy
[options.packages.find]
where = src

Expand Down
2 changes: 0 additions & 2 deletions backend/src/viasp/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ def get_relaxed_program(self, head_name:str = "unsat", collect_variables:bool =
default=True (collect variables from body as a tuple in the head literal)
"""
self._database.set_target_stable_model(self._marked)
self._database._reconstruct()
kwargs = {"head_name": head_name, "collect_variables": collect_variables}
return self._database.relax_constraints(**kwargs)

Expand All @@ -81,7 +80,6 @@ def relax_constraints(self, head_name:str = "unsat", collect_variables:bool = Tr
default=True (collect variables from body as a tuple in the head literal)
"""
self._database.set_target_stable_model(self._marked)
self._database._reconstruct()
kwargs = {"head_name": head_name, "collect_variables": collect_variables}

relaxed_prg = self._database.relax_constraints(**kwargs)
Expand Down
57 changes: 54 additions & 3 deletions backend/test/test_python_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@
from pytest import raises

from viasp import wrapper
from viasp.api import (FactParserError,
add_program_file, add_program_string,
from viasp.api import (FactParserError, add_program_file, add_program_string,
clear, load_program_file, load_program_string,
mark_from_clingo_model, mark_from_file,
mark_from_string, show, unmark_from_clingo_model,
unmark_from_file, unmark_from_string)
unmark_from_file, unmark_from_string, get_relaxed_program, relax_constraints, clingraph, register_transformer)
from viasp.shared.interfaces import ViaspClient
from viasp.shared.model import ClingoMethodCall, StableModel
from viasp.shared.io import clingo_model_to_stable_model
Expand All @@ -28,19 +27,33 @@ def show(self):
def set_target_stable_model(self, stable_models: Collection[StableModel]):
self.client.post("control/models", json=stable_models)

def relax_constraints(self, *args, **kwargs):
serialized = current_app.json.dumps({
"args": args,
"kwargs": kwargs
})
r = self.client.post("/control/relax",
data=serialized,
headers={'Content-Type': 'application/json'})
return ''.join(r.json) # type: ignore

def register_function_call(self, name: str, sig: Signature, args: Sequence[Any], kwargs: Dict[str, Any]):
serializable_call = ClingoMethodCall.merge(name, sig, args, kwargs)
self.client.post("control/add_call", json=serializable_call)

def is_available(self):
return True

def register_warning(self, message: str):
pass

def __init__(self, internal_client: FlaskClient, *args, **kwargs):
self.client = internal_client
self.register_function_call(
"__init__", signature(InnerControl.__init__), args, kwargs)



def test_load_program_file(client, db_session):
sample_encoding = str(pathlib.Path(__file__).parent.resolve() / "resources" / "sample_encoding.lp")

Expand Down Expand Up @@ -290,6 +303,44 @@ def test_unmark_model_from_file(client):
assert res.status_code == 200
assert len(res.json) == 0

def test_get_relaxed_program(client):
debug_client = DebugClient(client)
input_program = r"sample. :- sample.:-a(X)."
relaxed_program = r"#program base.sample.unsat(r1) :- sample.unsat(r2,(X,)) :- a(X).:~ unsat(R,T). [1@0,R,T]"
load_program_string(
input_program, _viasp_client=debug_client)

res = get_relaxed_program(_viasp_client=debug_client)
assert res == relaxed_program

res = get_relaxed_program(_viasp_client=debug_client, head_name="unsat2")
assert res == relaxed_program.replace("unsat", "unsat2")

res = get_relaxed_program(_viasp_client=debug_client, head_name="unsat3", collect_variables=False)
assert res == relaxed_program\
.replace("unsat","unsat3")\
.replace(",(X,)", "")\
.replace(",T", "")

def test_relax_constraints(client):
debug_client = DebugClient(client)

load_program_string(
r"sample.{encoding} :- sample.", _viasp_client=debug_client)

clear()
show()
# Assert the models were cleared
res = client.get("control/models")
assert res.status_code == 200
assert len(res.json) == 0

mark_from_string("sample.encoding.")
mark_from_string("sample.")
show()
res = relax_constraints(_viasp_client=debug_client)
assert isinstance(res, wrapper.Control)

def test_call_in_different_order(client):
debug_client = DebugClient(client)
sample_model = str(pathlib.Path(
Expand Down
4 changes: 2 additions & 2 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "viasp_dash",
"version": "2.0.0rc2",
"version": "2.2.0rc0",
"description": "The dash frontend for the viasp package.",
"main": "build/index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion frontend/viasp_dash/package-info.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "viasp_dash",
"version": "2.0.0rc2",
"version": "2.2.0rc0",
"description": "The dash frontend for the viasp package.",
"main": "build/index.js",
"scripts": {
Expand Down
6 changes: 3 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = viasp
version = 2.0.0rc2
version = 2.2.0rc0
author = Luis Glaser
author_email = [email protected]
description = a visualization tool for clingo.
Expand All @@ -15,8 +15,8 @@ classifiers =
[options]
python_requires = >=3.8
install_requires =
viasp-backend==2.0.0rc2
viasp-dash==2.0.0rc2
viasp-backend
viasp-dash
packages = find:
package_dir =
=.
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ def run(self):
EMAIL = '[email protected]'
AUTHOR = 'Luis Glaser'
REQUIRES_PYTHON = '>=3.8.0'
VERSION = '2.0.0rc2'
VERSION = '2.2.0rc0'

# What packages are required for this module to be executed?
REQUIRED = [
'viasp-backend==2.0.0rc2',
'viasp-dash==2.0.0rc2',
'viasp-backend',
'viasp-dash',
'jupyter-server-proxy',
'clingraph',
'graphviz',
Expand Down

0 comments on commit 00a9413

Please sign in to comment.