Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/potassco/viasp
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanzwicknagl committed Nov 16, 2023
2 parents 1674d4b + 5b0cbc4 commit 5ed2534
Show file tree
Hide file tree
Showing 30 changed files with 535 additions and 190 deletions.
5 changes: 3 additions & 2 deletions backend/src/viasp/server/startup.py
Expand Up @@ -24,7 +24,7 @@



def run(host=DEFAULT_BACKEND_HOST, port=DEFAULT_BACKEND_PORT):
def run(host=DEFAULT_BACKEND_HOST, port=DEFAULT_BACKEND_PORT, colors=None):
""" create the dash app, set layout and start the backend on host:port """

# if running in binder, get proxy information
Expand Down Expand Up @@ -59,7 +59,8 @@ def run(host=DEFAULT_BACKEND_HOST, port=DEFAULT_BACKEND_PORT):
app = Dash(__name__)
app.layout = viasp_dash.ViaspDash(
id="myID",
backendURL=backend_url
backendURL=backend_url,
colors=colors
)

# make sure the backend is up, before continuing with other modules
Expand Down
3 changes: 2 additions & 1 deletion backend/src/viasp/shared/io.py
Expand Up @@ -96,7 +96,8 @@ def dataclass_to_dict(o):
if isinstance(o, Node):
sorted_atoms = sorted(o.atoms, key=lambda x: x.symbol)
sorted_diff = sorted(o.diff, key=lambda x: x.symbol)
return {"_type": "Node", "atoms": sorted_atoms, "diff": sorted_diff, "reason": o.reason, "recursive": o.recursive, "uuid": o.uuid,
sorted_reason = {} if len(o.reason) == 0 else o.reason
return {"_type": "Node", "atoms": sorted_atoms, "diff": sorted_diff, "reason": sorted_reason, "recursive": o.recursive, "uuid": o.uuid,
"rule_nr": o.rule_nr}
elif isinstance(o, TransformationError):
return {"_type": "TransformationError", "ast": o.ast, "reason": o.reason}
Expand Down
2 changes: 1 addition & 1 deletion binder/Dockerfile
@@ -1,2 +1,2 @@
### DO NOT EDIT THIS FILE! This Is Automatically Generated And Will Be Overwritten ###
FROM stephanzwicknagl/viasp:ed112b64ae09
FROM stephanzwicknagl/viasp:8914a6a3976e
186 changes: 186 additions & 0 deletions examples/Color Editor.ipynb
@@ -0,0 +1,186 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# <center>Introduction to viASP</center>\n",
"\n",
"\n",
"viASP is a visualization and interactive explanation tool for ASP programs and their stable models.\n",
"\n",
"viASP allows you to explore the visualization in a variety of ways:\n",
"\n",
"* Visualize the derivation of stable models step-by-step in a tree view\n",
"* Inspect iterations of recursive rules individually\n",
"* Show reasons for the derivation of individual symbols with arrows\n",
"* Relax the constraints of unsatisfiable programs\n",
"* Inspect single models\n",
"* Add `#show` statements on the fly\n",
"* Search models, signatures and rules.\n",
"\n",
"![Example visualization](../docs/img/sprinkler.png)\n",
"\n",
"To get started, the startup module starts the viASP server:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"colors = {\n",
" # node border colors\n",
" \"ten\": {\"dark\": \"#3FA7D1\"}, \n",
" # row background (arbitrary number and names)\n",
" \"twenty\": { \"dark\": \"#a9a9a94a\", \"bright\": \"#ffffff\"},\n",
" # text color of node, detail sidebar, row header (dark) and detail sidebar atoms (bright)\n",
" \"thirty\": {\"dark\": \"#444\", \"bright\": \"#F6F4F3\"},\n",
" # recursive node supernode background (dark) and border (bright)\n",
" \"fourty\": { \"0\": \"#3FA7D1\", \"1\": \"#3FA7D1\"},\n",
" # detail sidebar atom background (dark) and border (bright)\n",
" \"fifty\": { \"dark\": \"#3FA7D1\"},\n",
" # background color of node, detail sidebar, row header\n",
" \"sixty\": {\"dark\": \"#F6F4F3\"},\n",
" # edge color (dark) and edge to clingraph color (bright)\n",
" \"seventy\": { \"dark\": \"#000000\", \"bright\": \"#000000\"},\n",
" # arbitrary number of colors to highlight explanations\n",
" \"highlight\": { \"0\": \"#d48521\", \"1\": \"#9a8298\", \"2\": \"#e0e4ac\", \"3\": \"#98f4e2\", \"4\": \"#21d485\"}, \n",
" # currently not used\n",
" \"error\": {\"ten\": \"#EB4A4E\", \"thirty\": \"#4C191A\", \"sixty\": \"#FCE8E8\"},\n",
" \"warn\": {\"ten\": \"#FF9800\", \"thirty\": \"#653300\", \"sixty\": \"#FFF1DF\"}}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from viasp.server import startup\n",
"app = startup.run(colors=colors)\n",
"# if this cell encounters an error in binder, restart the kernel and run it again"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Defining an encoding."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%file sprinkler.lp\n",
"1{rain;sprinkler}1.\n",
"wet :- rain.\n",
"wet :- sprinkler."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%file hamiltonian.lp\n",
"\n",
"node(1..4). start(1).\n",
"edge(1,2). edge(2,3). edge(2,4). edge(3,1).\n",
"edge(3,4). edge(4,1). edge(4,3).\n",
"\n",
"{ hc(V,U) } :- edge(V,U).\n",
"reached(V) :- hc(S,V), start(S).\n",
"reached(V) :- reached(U), hc(U,V).\n",
":- node(V), not reached(V).\n",
":- hc(V,U), hc(V,W), U!=W.\n",
":- hc(U,V), hc(W,V), U!=W.\n",
"% :- hc(V,U), hc(W,V), U!=W. % uncomment to make the program unsatisfiable & comment the line above\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from viasp import Control\n",
"\n",
"options = ['0']\n",
"programs = ['sprinkler.lp']\n",
"ctl = Control(options)\n",
"for path in programs:\n",
" ctl.load(path)\n",
"ctl.ground([(\"base\", [])])\n",
"\n",
"with ctl.solve(yield_=True) as handle:\n",
" for m in handle:\n",
" print(\"Answer:\\n{}\".format(m))\n",
" ctl.viasp.mark(m) # mark the answer set for visualization\n",
" print(handle.get())\n",
"ctl.viasp.show() # start the graph generation\n",
"app.run() # run the Dash app"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.4"
},
"varInspector": {
"cols": {
"lenName": 16,
"lenType": 16,
"lenVar": 40
},
"kernels_config": {
"python": {
"delete_cmd_postfix": "",
"delete_cmd_prefix": "del ",
"library": "var_list.py",
"varRefreshCmd": "print(var_dic_list())"
},
"r": {
"delete_cmd_postfix": ") ",
"delete_cmd_prefix": "rm(",
"library": "var_list.r",
"varRefreshCmd": "cat(var_dic_list()) "
}
},
"types_to_exclude": [
"module",
"function",
"builtin_function_or_method",
"instance",
"_Feature"
],
"window_display": false
},
"vscode": {
"interpreter": {
"hash": "1785f8d9ecd06a5253af1fb2e0a107be454014433d34b629cfe3c91c9b2ab96a"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
2 changes: 1 addition & 1 deletion frontend/index.html
@@ -1,4 +1,4 @@
<!doctype>
<!doctype html>
<html>
<head>
<title>viASP</title>
Expand Down
55 changes: 55 additions & 0 deletions frontend/package-lock.json

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

4 changes: 4 additions & 0 deletions frontend/package.json
Expand Up @@ -31,6 +31,9 @@
"@babel/plugin-transform-object-rest-spread": "^7.22.15",
"@babel/preset-env": "^7.23.2",
"@babel/preset-react": "^7.22.15",
"@iconify/icons-emojione-monotone": "^1.2.4",
"@iconify/icons-ri": "^1.2.10",
"@iconify/react": "^4.1.1",
"@plotly/dash-component-plugins": "^1.2.3",
"@plotly/webpack-dash-dynamic-import": "^1.3.0",
"babel-loader": "^9.1.3",
Expand All @@ -40,6 +43,7 @@
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-react": "^7.33.2",
"polished": "^4.2.2",
"prop-types": "^15.8.1",
"react-docgen": "^5.4.3",
"react-lineto": "^3.3.0",
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/lib/LazyLoader.js
@@ -0,0 +1,3 @@
import React from 'react';
export const IconWrapper = React.lazy(() => import(/* webpackChunkName: "IconWrapper" */ './fragments/IconWrapper.react'));
export const Settings = React.lazy(() => import(/* webpackChunkName: "Settings" */ './fragments/Settings.react'));
19 changes: 5 additions & 14 deletions frontend/src/lib/components/Detail.react.js
Expand Up @@ -92,21 +92,12 @@ export function Detail(props) {
return () => mounted = false;
}, [shows])

if (shows === null) {
return null;
}
if (data === null) {
return <div id="detailSidebar"
style={{backgroundColor: colorPalette.fifty.dark, color: colorPalette.thirty.dark}}
className="detail">
<h3><CloseButton onClick={clearDetail}/>{type}</h3>
Loading..
</div>
}
return <div id="detailSidebar" style={{backgroundColor: colorPalette.sixty.dark, color: colorPalette.thirty.dark}}
className="detail">
return <div id="detailSidebar" style={{ backgroundColor: colorPalette.info, color: colorPalette.dark}}
className={shows === null ? `detail`:`detail detail-open`}>
<h3><CloseButton onClick={clearDetail}/>{type}</h3>
{data.map((resp) =>
{data===null ?
<div>Loading..</div> :
data.map((resp) =>
<DetailForSignature key={`${resp[0].name}/${resp[0].args}`} signature={resp[0]} symbols={resp[1]}
uuid={shows}/>)}
</div>
Expand Down

0 comments on commit 5ed2534

Please sign in to comment.