Skip to content
Merged
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
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changes

## clinguin 2.7.4

* New flags to improve performance
* `--explicit-show` only shows atoms that are part of a show statement in the domain state
* DS state is only return in the response when explicitly requested

## clinguin 2.7.3

* Added a backend for fclingo with example
Expand Down
34 changes: 30 additions & 4 deletions clinguin/server/application/backends/clingo_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,20 @@ def register_options(cls, parser):
help="Optional domain files that can be activated/deactivated",
metavar="",
)
parser.add_argument(
"--explicit-show",
help="""If set, the UI encoding will only consider atoms that are shown in the domain encoding.
Otherwise, all atoms are considered. While this option can improve performance,
the user must make sure any predicate used in the UI is shown in the domain encoding.""",
action="store_true",
)

parser.add_argument(
"--include-ds-in-response",
help="""If set, the response of the server will include the domain state as a dictionary.
Setting it will impact performance.""",
action="store_true",
)

# ---------------------------------------------
# Properties
Expand Down Expand Up @@ -295,6 +309,10 @@ def _init_command_line(self):

self._opt_timeout = self._args.opt_timeout

self._explicit_show = self._args.explicit_show

self._include_ds_in_response = self._args.include_ds_in_response

def _init_interactive(self):
"""
Initializes the attributes that will change during the interaction.
Expand Down Expand Up @@ -662,6 +680,7 @@ def _call_solver_with_cache(
self._ctl,
self._assumption_list,
self._on_model,
include_all_atoms=not self._explicit_show,
)
self._unsat_core = ucore
if symbols is None:
Expand Down Expand Up @@ -790,7 +809,12 @@ def _ds_model(self):
)
)

symbols, ucore = solve(self._ctl, self._assumption_list, self._on_model)
symbols, ucore = solve(
self._ctl,
self._assumption_list,
self._on_model,
include_all_atoms=not self._explicit_show,
)
self._unsat_core = ucore
if symbols is None:
self._logger.warning(
Expand Down Expand Up @@ -1007,9 +1031,11 @@ def get(self):
This method will be automatically called after executing all the operations.
"""
self._update_ui_state()
json_structure = StandardJsonEncoder.encode(
self._ui_state, self._domain_state_dict
)
ds = None
if self._include_ds_in_response:
self._logger.debug("Including domain state in response")
ds = self._domain_state
json_structure = StandardJsonEncoder.encode(self._ui_state, ds)
return json_structure

def restart(self):
Expand Down
3 changes: 2 additions & 1 deletion clinguin/server/application/standard_json_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def encode(cls, ui_state, ds_dict):

root = ElementDto("root", "root", "root")
elements_dict[str(root.id)] = root

if not ds_dict:
ds_dict = {}
cls._generate_hierarchy(ui_state, root, elements_dict)
return {"ui": root, "ds": ds_dict}

Expand Down
4 changes: 2 additions & 2 deletions clinguin/server/data/domain_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def tag(symbols, tag_name):
return tagged


def solve(ctl, assumptions, on_model=lambda m: None):
def solve(ctl, assumptions, on_model=lambda m: None, include_all_atoms=True):
"""
Adds information about the browsing to the domain state.

Expand All @@ -27,7 +27,7 @@ def solve(ctl, assumptions, on_model=lambda m: None):
model_symbols = None
for m in result:
on_model(m)
model_symbols = m.symbols(shown=True, atoms=True, theory=True)
model_symbols = m.symbols(shown=True, atoms=include_all_atoms, theory=True)
if model_symbols is None:
return None, result.core()
return model_symbols, None
14 changes: 14 additions & 0 deletions docs/clinguin/help.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@
If you are unsure how to use a feature, you can check the :ref:`examples` section for inspiration.
You can also use the search bar to see which examples use the feature you are interested in.

.. admonition:: **Loading empty page with error**
:class: tip

If the page is loaded empty with the error icon. It might be the case that the encodings took to long to load. Try reloading the page.


.. admonition:: **Long response time**
:class: tip
Expand All @@ -80,6 +85,15 @@
if the solver is already searching when the timeout is reached. If you pass a timeout of ``0``, the server will only get the first model; you can then keep calling the operation ``next_solution(optN)`` to improve the cost, one at a time.
Check out the `placement example <https://github.com/potassco/clinguin/tree/master/examples/angular/placement>`_.

*Show statements*
Another reason for a long response time is that the problem is very large and there is an overhead of atoms in the domain state that are not needed but slow down creating the UI state.
This is the case because in clinguin, by default, we show all atoms that are part of the answer set so that they can be used in the UI encoding.
This can be done differently by adding ``#show`` statements to your :ref:`domain-files` to only show the atoms that are relevant for your UI and also passing the flag ``--explicit-show`` in the command line.
Notice that any atom that is not shown will not be part of the :ref:`domain-state` and thus cannot be used in the UI encoding.





.. admonition:: **Can't manage to place or style things in my UI**
:class: tip
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
author = "Susana Hahn, Alexander Beiser"

# The full version, including alpha/beta/rc tags
release = "2.7.3"
release = "2.7.4"

# -- General configuration ---------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = clinguin
version = 2.7.3
version = 2.7.4
author = Alexander Beiser, Susana Hahn (Potassco)
author_email = [email protected], [email protected]
description = An interactive visualizer for clingo
Expand Down
2 changes: 1 addition & 1 deletion tests/reference_json_output/health.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Health:
def get_reference_json(cls):
json_dict = {
"name": "clinguin",
"version": "2.7.3",
"version": "2.7.4",
"description": "An interactive visualizer for clingo",
}

Expand Down
1 change: 1 addition & 0 deletions tests/test_basic_00_05.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def teardown_method(self, test_method):
def test_health(self):
uri = f"{self.uvicorn_url}/health"
received_by_postman = json.dumps(Health.get_reference_json())
print(received_by_postman)
UtilsTestUtils.assert_get_request(uri, received_by_postman)

def test_basic_05(self):
Expand Down
1 change: 1 addition & 0 deletions tests/utils_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def assert_get_request(self, uri, should_output, should_status_code=200):
assert False
except Exception as ex:
print(ex)

assert False

@classmethod
Expand Down
Loading