Documentation
Everything the extension and the Python package can do. If something here does not match what you see, open an issue.
Quick start
- Install the extension from the latest release (see the install steps).
- Open a
.lpfile. Click the graph icon in the editor title bar, or run ASP: Open Visualizer from the Command Palette. The panel opens beside your file. - Edit the program. With auto-run on, the panel updates when you stop typing. Press Solve to compute every answer set instead of the first few.
The status bar shows the model count for the active file, and syntax errors appear in the Problems panel after each run.
Online playground
The playground runs the same visualizer in your browser, with nothing to install. clingo 5.8 runs locally as WebAssembly in a background thread, so your program is never uploaded.
- Type in the editor. With "Run while typing" on, the result updates after a short pause. Ctrl or Cmd with Enter runs it right away.
- Auto-run computes at most 50 answer sets. Press Run for all of them. A run is stopped after 10 seconds.
- The Options field takes clingo options such as
--opt-mode=optNor-c n=6. - While you step through the animator, the rules that fire are highlighted in the editor, and clicking a rule in the panel jumps to its line.
- Copy link puts the whole program into the URL after
#p=, so you can share it. The text stays in the address, never on a server.
The animator
The animator evaluates a positive program the way a naive bottom-up evaluator would. Round 0 contains the facts. In every later round, each rule is applied to all atoms known so far, and the atoms that were not known before form the round. It stops at the fixpoint, when a round adds nothing.
For every new atom the panel shows which rule produced it and the variable bindings. While you step, the rules that fired are highlighted in the editor with a short note. Click a rule in the panel to jump to its line.
The animator rejects rules with not, choice rules, constraints and ranges such as 1..n. The message names the offending line. The Answer Sets, Graph and Console tabs work for every program clingo accepts.
Inside the panel, ← and → step, Space plays or pauses and R resets.
The Grounding tab
The Grounding tab shows how a rule with variables becomes ground rules, one step at a time. Take node(1..2). color(r;g;b). { c(N,C) : color(C) } = 1 :- node(N).
The body literal node(N) is the outer loop: N is 1, then 2. For each N the conditional literal color(C) is an inner loop that adds c(N,C) to a set. When C has run through all colors, the set closes and becomes the ground rule { c(1,r); c(1,g); c(1,b) } = 1.
The panel highlights the part of the rule that is active, lists the loops with their current values, shows the set while it is being built, and keeps the ground rules produced so far. The last step shows how many answer sets clingo finds. The arrow keys, Space and R work as in the animator, and the rule being expanded is highlighted in the editor.
The steps follow the structure of your rules, not clingo's internal grounder, which simplifies a little more and may order rules differently. Facts with ranges and pools, normal rules, constraints, disjunctions, choice rules, comparisons, not, arithmetic and #const are supported. A rule with an aggregate in its body is listed as not shown, and atoms it would derive are then missing. A rule with many instances shows the first 60 and groups the rest into one step. Constants given with -c are not applied.
Commands and keys
| Command | What it does | Key |
|---|---|---|
| ASP: Open Visualizer | Opens the panel for the active .lp file. | editor title icon |
| ASP: Solve Current File | Computes all answer sets. | Cmd Alt Enter or Ctrl Alt Enter |
| ASP: Animator: Step Forward / Back | Moves one round, or one step in the Grounding tab. | Ctrl Alt → / ← |
| ASP: Animator: Play / Pause | Plays the rounds in sequence. | Ctrl Alt Space |
| ASP: Animator: Reset to Round 0 | Goes back to the facts. | |
| ASP: Set Up Environment… | Installs native clingo, a syntax highlighter and viASP. See below. | |
| ASP: Open viASP for Current File | Starts viASP on the file, installing it first if needed. | |
| ASP: Select clingo Executable… | Points the extension at a specific clingo binary. | |
| ASP: Remove Private Environment | Deletes the Python environment created by Set Up Environment. | |
| ASP: Open Settings | Opens the ASP Studio settings. | |
| ASP: Show Output Log | Shows the commands that ran and clingo's messages. |
Settings
All settings start with asp. and are in Settings under ASP Studio.
| Setting | Default | Meaning |
|---|---|---|
clingoPath | "" | Path to a native clingo. Empty means auto-detect (PATH, the private environment, conda, Homebrew), then fall back to WebAssembly. |
preferWasm | false | Always use the bundled WebAssembly clingo. |
models | 0 | Maximum number of answer sets. 0 means all. |
options | [] | Extra clingo options, one per entry, for example ["--opt-mode=optN", "-c", "n=6"]. |
timeoutSeconds | 10 | Stops a computation after this many seconds. |
scope | activeFile | folder solves every .lp file in the folder together, for example instance.lp and encoding.lp. |
autoRun, autoRunDelay | true, 500 | Re-solve while the panel is open, after a pause of this many milliseconds. |
autoRunMaxModels | 50 | Model limit used by auto-run when models is 0. |
runOnSave | true | Check .lp files on save and report problems. |
maxModelsShown | 100 | Answer sets drawn in the panel. |
animator.speed | 1400 | Milliseconds per round while playing. |
animator.highlightRules | true | Highlight firing rules in the editor. |
The highlight colors are theme colors named asp.activeRuleBackground and asp.activeRuleBorder. Override them in workbench.colorCustomizations.
Setting up tools
Run ASP: Set Up Environment… to see what is installed and pick what to add. Nothing downloads until you confirm.
| Component | What happens |
|---|---|
| Native clingo | The PyPI package clingo is installed into a private virtual environment inside the extension's storage folder. It is picked up automatically and runs as python -m clingo. Needs Python 3.8 or newer. |
| Syntax highlighting | Installs the Marketplace extension abelcour.asp-syntax-highlight. |
| viASP | Installs the PyPI package viasp into the same environment. About 60 MB with its dependencies. |
Nothing outside the extension's storage folder is changed. ASP: Remove Private Environment deletes it. If only the WebAssembly clingo is available, the extension offers this setup once and stops asking if you choose "Don't ask again".
Python and notebooks
Install with pip install "asp-studio[notebook]". It needs Python 3.9 or newer and the clingo Python package, which pip installs for you.
import asp_studio as asp
res = asp.solve("a :- not b. b :- not a.", models=0, timeout=10)
res.result # 'SATISFIABLE'
list(res) # [['b'], ['a']]
res.diagnostics # error and warning positions from clingo
res # as the last line of a cell: shows the visualizer
asp.show(res, tab="graph")
solve takes ASP text, a pathlib.Path or a list of those. A broken program does not raise: check res.ok and res.error. With #minimize or #maximize and a finished search, only the optimal models are kept and their costs are in res.costs.
In a notebook, %load_ext asp_studio adds the %%asp cell magic:
| Option | Meaning |
|---|---|
-n 5 | At most 5 answer sets. 0 means all. |
-o "--opt-mode=optN -c n=6" | Extra clingo options. |
-t 20 | Timeout in seconds. Default 10. |
--tab answers | First tab to show: animator, grounding, answers, graph or console. |
--theme dark | auto, light or dark. In VS Code notebooks the editor theme is used. |
--out res | Keep the result in a variable called res. |
Command line
asp-studio program.lp --open # writes program.html and opens it asp-studio instance.lp encoding.lp -n 3 # several files are joined in order cat program.lp | asp-studio - --out out.html # read the program from standard input asp-studio program.lp -o --opt-mode=optN # extra clingo options asp-studio --version python -m asp_studio program.lp # the same, without the script on PATH
The exit code is 0 when the program ran, 1 when it has an error (positions are printed as file:line:col) and 2 for bad arguments or unreadable input.
Troubleshooting
The panel says "WebAssembly" and solving feels slow
No native clingo was found. Run ASP: Set Up Environment… and tick the native solver, or set asp.clingoPath.
The animator says it cannot show my program
It names the first line it does not support. Remove not, choice rules, constraints or ranges from the part you want to animate. A small positive core of a larger program is a good thing to animate on its own.
A notebook cell shows nothing
Jupyter drops iframe output from notebooks it does not trust. Use File, then Trust Notebook, or run the cell again. In VS Code, make sure the kernel's environment has asp-studio installed.
Setup says no Python was found
Install Python 3.8 or newer from python.org and run the setup command again. The WebAssembly clingo keeps working in the meantime.
Nothing happens on save
Check that asp.runOnSave is on and that the file ends in .lp, .asp or .lpx. The Output panel, channel "ASP Studio", shows what ran.