From 00a9413834b7df20723cc58e070d425d844a8785 Mon Sep 17 00:00:00 2001 From: Stephan Zwicknagl Date: Thu, 24 Oct 2024 15:59:24 -0400 Subject: [PATCH] Add test, prepare release candidate 2.2.0rc0 --- backend/setup.cfg | 3 +- backend/src/viasp/wrapper.py | 2 - backend/test/test_python_api.py | 57 +++++++++++++++++++++++++-- frontend/package-lock.json | 4 +- frontend/package.json | 2 +- frontend/viasp_dash/package-info.json | 2 +- setup.cfg | 6 +-- setup.py | 6 +-- 8 files changed, 66 insertions(+), 16 deletions(-) diff --git a/backend/setup.cfg b/backend/setup.cfg index 383b5a9f..c9de3e0b 100644 --- a/backend/setup.cfg +++ b/backend/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = viasp-backend -version = 2.0.0rc2 +version = 2.2.0rc0 author = Luis Glaser author_email = Luis.Glaser@uni-potsdam.de description = The backend for the viasp package. @@ -27,6 +27,7 @@ install_requires = numpy clingraph waitress + sqlalchemy [options.packages.find] where = src diff --git a/backend/src/viasp/wrapper.py b/backend/src/viasp/wrapper.py index 806b3469..6e74f688 100644 --- a/backend/src/viasp/wrapper.py +++ b/backend/src/viasp/wrapper.py @@ -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) @@ -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) diff --git a/backend/test/test_python_api.py b/backend/test/test_python_api.py index 23b58929..aa493044 100644 --- a/backend/test/test_python_api.py +++ b/backend/test/test_python_api.py @@ -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 @@ -28,12 +27,25 @@ 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 @@ -41,6 +53,7 @@ def __init__(self, internal_client: FlaskClient, *args, **kwargs): "__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") @@ -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( diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 537d69af..455ff4c8 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -1,12 +1,12 @@ { "name": "viasp_dash", - "version": "2.0.0rc2", + "version": "2.2.0rc0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "viasp_dash", - "version": "2.0.0rc2", + "version": "2.2.0rc0", "license": "MIT", "dependencies": { "@react-hook/resize-observer": "^1.2.6", diff --git a/frontend/package.json b/frontend/package.json index bf94156a..778ba0a7 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -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": { diff --git a/frontend/viasp_dash/package-info.json b/frontend/viasp_dash/package-info.json index bf94156a..778ba0a7 100644 --- a/frontend/viasp_dash/package-info.json +++ b/frontend/viasp_dash/package-info.json @@ -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": { diff --git a/setup.cfg b/setup.cfg index 781192af..a508f0d7 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = viasp -version = 2.0.0rc2 +version = 2.2.0rc0 author = Luis Glaser author_email = Luis.Glaser@uni-potsdam.de description = a visualization tool for clingo. @@ -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 = =. diff --git a/setup.py b/setup.py index 48130f93..f35cda63 100644 --- a/setup.py +++ b/setup.py @@ -30,12 +30,12 @@ def run(self): EMAIL = 'Luis.Glaser@uni-potsdam.de' 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',