Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Visualization Constraints and Weight Learning

License

NotificationsYou must be signed in to change notification settings

uwdata/draco

Repository files navigation

Formalizing Visualization Design Knowledge as Constraints

This reporsitory contains the source for the original Draco project. We develop a much improved Draco 2 athttps://github.com/cmudig/draco2.

TestCoverage StatusCode style: blackcode style: prettier

Draco is a formal framework for representing design knowledge about effective visualization design as a collection of constraints. You can use Draco to find effective visualization visual designs in Vega-Lite. Draco's constraints are implemented in based on Answer Set Programming (ASP) and solved with the Clingo constraint solver. We also implemented a way to learn weights for the recommendation system directly from the results of graphical perception experiment.

Read our introductoryblog post about Draco and ourresearch paper for more details. Try Draco in the browser athttps://uwdata.github.io/draco-editor.

Status

There Be Dragons! This project is in active development and we are working hard on cleaning up the repository and making it easier to use the recommendation model in Draco. If you want to use this right now, please talk to us. More documentation is forthcoming.

Overview

This repository currently contains:

  • draco (pypi) The ASP programs with soft and hard constraints, a python API forrunning Draco, theCLI, and thepython wrapper for thedraco-core API. Additionally includes somehelper functions that may prove useful.
  • draco-core (npm) Holds a Typescript / Javascript friendly copy of the ASP programs, and additionally, a Typescript /Javascript API for all the translation logic of Draco, as described below.

Sibling Repositories

Various functionality and extensions are in the following repositories

  • draco-vis

    • A web-friendly Draco! Including a bundled Webassembly module of Draco's solver, Clingo.
  • draco-learn

    • Runs a learning-to-rank method on results of perception experiments.
  • draco-tools

    • UI tools to create annotated datasets of pairs of visualizations, look at the recommendations, and to explore large datasets of example visualizations.
  • draco-analysis

    • Notebooks to analyze the results.

Draco API (Python)

In addition to a wrapper of the Draco-Core API describe below, the python API contains the following functions.

objectResult<>

The result of a Draco run, a solution to a draco_query. Userresult.as_vl() to convert this solution into a Vega-Lite specification.

run(draco_query: List[str] [,constants, files, relax_hard, silence_warnings, debug, clear_cache]) -> Result:<>

Runs adraco_query, defined as a list of Draco ASP facts (strings), against givenfile asp programs (defaults to base Draco set). Returns aResult if the query is satisfiable. Ifrelax_hard is set toTrue, hard constraints (hard.lp) will not be strictly enforced, and instead will incur an infinite cost when violated.

is_valid(draco_query: List[str] [,debug]) -> bool:<>

Runs adraco_query, defined as a list of Draco ASP facts (strings), against Draco's hard constraints. Returns true if the visualization defined by the query is a valid one (does not violate hard constraints), and false otherwise. Hard constraints can be found inhard.lp.

data_to_asp(data: List) -> List[str]:<>

Reads an array ofdata and returns the ASP declaration of it (a list of facts).

read_data_to_asp(file: str) -> List[str]:<>

Reads afile of data (either.json or.csv) and returns the ASP declaration of it (a list of facts).

Draco-Core API (Typescript / Javascript)

vl2asp(spec: TopLevelUnitSpec): string[]<>

Translates a Vega-Lite specification into a list of ASP Draco facts.

cql2asp(spec: any): string[]<>

Translates a CompassQL specification into a list of ASP Draco constraints.

asp2vl(facts: string[]): TopLevelUnitSpec<>

Interprets a list of ASP Draco facts as a Vega-Lite specification.

data2schema(data: any[]): Schema<>

Reads a list of rows and generates a data schema for the dataset.data should be given as a list of dictionaries.

schema2asp(schema: Schema): string[]<>

Translates a data schema into an ASP declaration of the data it describes.

constraints2json(constraintsAsp: string, weightsAsp?: string): Constraint[]<>

Translates the given ASP constraints and matching weights (i.e. for soft constraints) into JSON format.

json2constraints(constraints: Constraint[]): ConstraintAsp<>

Translates the given JSON format ASP constraints into ASP strings for definitions and weights (if applicable, i.e. for soft constraints).

User Info

Installation

Python (Draco API)

Install Clingo

You can install Clingo with conda:conda install -c potassco clingo. On MacOS, you can alternatively runbrew install clingo.

Install Draco (Python)

pip install draco

Typescript / Javascript (Draco-Core API)

STOP! If you wish torun Draco in aweb browser, consider usingdraco-vis, which bundles the Clingo solver as a WebAssembly module. The Draco-Core API does not include this functionality by itself. It merely handles the logic of translating between the various interface languages.

yarn add draco-core ornpm install draco-core

Developer Info

Installation

Install Clingo.

You can install Clingo with conda:conda install -c potassco clingo. On MacOS, you can alternatively runbrew install clingo.

Install node dependencies

yarn ornpm install

You might need to activate a Python 2.7 environment to compile the canvas module.

Build JS module

yarn build. We are currently using typescript version 3.2.1 and greater.

Python setup

pip install -r requirements.txt orconda install --file requirements.txt

Install Draco in editable mode. We expect Python 3.

pip install -e .

Now you can call the command line tooldraco. For exampledraco --version ordraco --help.

Tests

You should also be able to run the tests (and coverage report)

python setup.py test

Run only ansunit tests

ansunit asp/tests.yaml

Run only python tests

pytest -v

Test types

mypy draco tests --ignore-missing-imports

Running Draco

End to end example

To run Draco on a partial spec.

sh run_pipeline.sh spec

The output would be a .vl.json file (for Vega-Lite spec) and a .png file to preview the visualization (by default, outputs would be in folder__tmp__).

Use CompassQL to generate examples

Runyarn build_cql_examples.

Run Draco directly on a set of ASP constraints

You can use the helper fileasp/_all.lp.

clingo asp/_all.lp test.lp

Alternatively, you can invoke Draco withdraco -m asp test.lp.

Run APT example

clingo asp/_apt.lp examples/example_apt.lp --opt-mode=optN --quiet=1 --project -c max_extra_encs=0

This only prints the relevant data and restricts the extra encodings that are being generated.

Releases

  • Make sure everything works!
  • Update__version__ indraco/__init__.py and use the right version below.
  • git commit -m "bump version to 0.0.1"
  • Tag the last commitgit tag -a v0.0.1.
  • git push andgit push --tags
  • Runpython setup.py sdist upload.

Resources

Related Repositories

Previous prototypes

For a bit of historical perspective, after buildingCompass andCompassQL with @kanitw, @domoritz worked with colleagues at UW on a first constraint-based prototypevis-csp in ASP, then tried Z3 invis-constraints before going back to ASP for Draco.

Related software

Guides


[8]ページ先頭

©2009-2025 Movatter.jp