ASP Studio

Documentation

Everything the extension and the Python package can do. If something here does not match what you see, open an issue.

Quick start

  1. Install the extension from the latest release (see the install steps).
  2. Open a .lp file. Click the graph icon in the editor title bar, or run ASP: Open Visualizer from the Command Palette. The panel opens beside your file.
  3. 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.

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

CommandWhat it doesKey
ASP: Open VisualizerOpens the panel for the active .lp file.editor title icon
ASP: Solve Current FileComputes all answer sets.Cmd Alt Enter or Ctrl Alt Enter
ASP: Animator: Step Forward / BackMoves one round, or one step in the Grounding tab.Ctrl Alt → / ←
ASP: Animator: Play / PausePlays the rounds in sequence.Ctrl Alt Space
ASP: Animator: Reset to Round 0Goes back to the facts.
ASP: Set Up Environment…Installs native clingo, a syntax highlighter and viASP. See below.
ASP: Open viASP for Current FileStarts viASP on the file, installing it first if needed.
ASP: Select clingo Executable…Points the extension at a specific clingo binary.
ASP: Remove Private EnvironmentDeletes the Python environment created by Set Up Environment.
ASP: Open SettingsOpens the ASP Studio settings.
ASP: Show Output LogShows the commands that ran and clingo's messages.

Settings

All settings start with asp. and are in Settings under ASP Studio.

SettingDefaultMeaning
clingoPath""Path to a native clingo. Empty means auto-detect (PATH, the private environment, conda, Homebrew), then fall back to WebAssembly.
preferWasmfalseAlways use the bundled WebAssembly clingo.
models0Maximum number of answer sets. 0 means all.
options[]Extra clingo options, one per entry, for example ["--opt-mode=optN", "-c", "n=6"].
timeoutSeconds10Stops a computation after this many seconds.
scopeactiveFilefolder solves every .lp file in the folder together, for example instance.lp and encoding.lp.
autoRun, autoRunDelaytrue, 500Re-solve while the panel is open, after a pause of this many milliseconds.
autoRunMaxModels50Model limit used by auto-run when models is 0.
runOnSavetrueCheck .lp files on save and report problems.
maxModelsShown100Answer sets drawn in the panel.
animator.speed1400Milliseconds per round while playing.
animator.highlightRulestrueHighlight 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.

ComponentWhat happens
Native clingoThe 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 highlightingInstalls the Marketplace extension abelcour.asp-syntax-highlight.
viASPInstalls 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.

python
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:

OptionMeaning
-n 5At most 5 answer sets. 0 means all.
-o "--opt-mode=optN -c n=6"Extra clingo options.
-t 20Timeout in seconds. Default 10.
--tab answersFirst tab to show: animator, grounding, answers, graph or console.
--theme darkauto, light or dark. In VS Code notebooks the editor theme is used.
--out resKeep the result in a variable called res.

Command line

shell
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.