Giter VIP home page Giter VIP logo

z3guide's Introduction

Z3Guide Documentation

This repository contains sources of Z3Guide, an online tutorial for Z3 powered by RiSE at Microsoft Research.

The rest of this page is for developers contributing to the tutorial docs of Z3.

Table of Content

  1. Developer Setup
    1. Local Setup
    2. Codespaces
  2. Development
    1. Contributing to Existing Materials
    2. Creating New Tutorial Materials
    3. Testing the Website
  3. Manually Updating z3-solver
  4. Code of Conduct
  5. Trademarks

Developer Setup

Local Setup (not using Codespaces)

  • install node.js >= 16.15.1
  • install yarn globally if needed
npm install -g yarn
  • Set up repo and start development following the steps in Development.

Codespaces

These instruction use GitHub Codespaces, a convienient way to get a perfect cloud development environment. Your organization may or may not support Codespaces.

  • From this repository, click on the green <> Code button, select the Codespaces tab and then Create codespaces on main. The setup might take a couple of minutes.

  • From there, a VSCode tab will open in your browser. You may now edit, test and commit to the repository just like on your local machine.

    • All command line instructions assume a bash-like terminal.
  • Set up repo and start development following the steps in Development.

Microsoft Employees ONLY

  • Join the Microsoft github organization from Microsoft Open Source via the Employee sign-in at the bottom.

    • From there, go to the GitHub for Open Source at Microsoft tab and follow the instructions to join the organization via the management portal.

Development

  • Change the working directory to website:
cd website
  • From website, run the script to install dependencies
yarn
  • Launch the docs server (which does client-side rendering and allows for hot reloading, so that you see your changes immediately reflected to the locally running page)
yarn clear; # for clearing cache
yarn start; 
  • Click on the generated URL in the terminal output to see the website now running locally.

Inspecting the Output from the Build

  • In case you want to inspect the output (.html files etc. from server-side rendering) from the build, you can run
yarn clear; # clearing your cache first is always recommended
yarn build;

and if successful, you should see a build directory under website.

  • If you want to see how these output files are rendered in the browser, you may run
yarn serve

Note that this is different from yarn start, as yarn serve does not do hot-reloading because it is simply serving the files under build rather than rebuilding everything from scratch for every change you make, like what yarn start does.

Contributing to Existing Tutorial Materials

The online Z3 Guide serves multiple instances of tutorial materials: currently it has a Z3 tutorial in SMTLIB format, and Programming Z3 in different language bindings.

The instances are hosted under website/docs-smtlib and website/docs-programming, respectively. To contribute to existing tutorial materials, you may add/edit materials in either directory.

  • You may find the Docusaurus documentation on Docs useful, especially for configuring the sidebar.

  • Note that Docusaurus does live reload, so that every change you make to website/docs will be immediately reflected in the locally running tab.

  • For all Z3-SMTLIB code snippets, please use the following Markdown code blocks format:

    ```z3
    (exec-this-command arg)
    ```
    
  • Any Z3 runtime error with the code specified in the code block above would fail the build. However, you may intentionally bypass the errors by using flags of no-build or ignore-errors:

    ```z3 no-build
    give me the error on the webpage I know it is invalid
    ```
    

    or

    ```z3 ignore-errors
    I know this snippet is problematic but I want to teach about error messages so show them
    ```
    
  • You may also add Z3-JavaScript or Z3-Python code snippets using Markdown code blocks, e.g.,:

    ```z3-js
    // some z3-js code
    ```
    

    and

    ```z3-python
    # some z3-python code
    ```
    

    and the flags of no-build and ignore-errors remain applicable to these code blocks.

    Note that we currently support output rendering and code editing for Z3-SMTLIB and Z3-JavaScript code snippets, with similar support for Z3-Python coming soon.

  • Programming Z3 in other language bindings is not supported at the moment.

  • Sidebar content is maintained in files under website/sidebars. The Z3-SMTLIB guide uses website/sidebars/smtlibSidebars.js, while the Programming Z3 (with other language bindings) guide uses website/sidebars/programmingSidebars.js. If you find your new content missing from either sidebar, please modify the respective sidebar file accordingly.

Creating New Tutorial Materials

The process of creating new tutorial materials is similar to the above, except for the following additional steps:

  1. You will need to create a new docs-* directory under website. E.g., website/docs-api.
  2. You will need a JavaScript file for configuring the sidebar for your docs under website/sidebars. The sidebar can be generated automatically. You may simply make a renamed copy of programmingSidebars.js for such automation.
  3. You will need to go to docusaurus.config.js to add additional configurations so that the build process can pick up the new directories. Search for comments beginning with [NEW DOCS] within the file for more instructions.

Testing the Website

We provided a test file that contains all kinds of Z3 (SMTLIB and JavaScript) code snippets, docs-playground/_03.test.md. To test if the interactivity with Z3 snippets works as expected, you may remove the underscord at the beginning of the file name, and run

yarn start

to access the file at https://localhost:[PORT]/z3guide/playground/test, where [PORT] is 3000 by default or the port number you specified in docusaurus.config.js.

You may add more code snippets to this test file, or create your own test file under any docs-* directory your prefer. We recommend putting the test files under docs-playground.

When you are done testing, make sure to add the underscore back to the test file name, so that the content will not be included in rendering the website.

Manually Updating z3-solver

Upgrades of z3-solver should be done ONLY you are certain that the latest version of z3-solver works well with the existing examples and website infrastructure. We provide a script to automate the manual upgrade process:

# remember to switch into the `website` directory first
yarn upgrade-z3

The script will update z3-solver to the latest and then try to build the website. If the build fails, then it will downgrade z3-solver to the version before your upgrade. It is unlikely that the update itself fails.

After done, make sure the field dependencies.z3-solver in website/package.json is exactly the version that you just upgraded to. For example, if you just upgraded to version 4.10.1, it should look like

{
  //...
  "dependencies": {
    //...
    "z3-solver": "4.10.1" // it should not be "^4.10.1" or "~4.10.1" or any other values that contain other symbols
  }
}

So that we make sure that yarn install always picks up the exact version of z3-solver that you mean for the website to run on.

Microsoft Open Source Code of Conduct

This project is hosted at https://github.com/microsoft/z3guide/. This project has adopted the Microsoft Open Source Code of Conduct.

Resources:

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.

z3guide's People

Contributors

alwilson avatar ayanamonr avatar dependabot[bot] avatar krooken avatar microsoftopensource avatar moemode avatar muchang avatar nikolajbjorner avatar pelikhan avatar phultquist avatar rlisahuang avatar rmehri01 avatar smoy avatar turibe avatar tzach avatar walnutwaldo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

z3guide's Issues

z3 fail -> build fail

  • Ensure that if a snippet cannot be processed during build, the entire github action fails as well (and no deployment is generated).
  • Ensure that logging is good enough to trace which snippet needs to be investigated. Try to generate an formatted error message in the output so that the github action automatically highlights where the problem is

remark action configuration

Move all remark plugin settings to configuration

  • timeout duration
  • executable name and argument format
  • tool name (eg. z3)
  • custom version number to force hash recomputation

The settings should allow to run the remark tool against another command line tool --> support an array of tool descriptions.

top level organization issues

image

There are several issues with the top-level organization.

  • The top-level organization shows z3 topics on the main landing page. The z3 topics should (eventually?) only show up when selecting the z3 tutorial (reflecting that rise4fun is more than z3 even though current activities are z3 centric).
  • When selecting the z3 tutorial the page is undefined. What is the right link? Where should it be added?
  • The side bar shows z3 sections in an indeterminate order. The order in the upper task bar is according to a json file, but the order in the left side bar is neither logical, nor alphabetical.

Configure Codespace + Onboarding

  • make sure instructions for this step is clear for a user (subject b)
  • note: content in a subfolder
  • make sure everything in codespace is installed on launch
  • instruction on dev server launch should be clear
  • !!! as we hear about what professors need edit

keyboard navigation

Ensure that the page can be navigated with a keyboard, specifically that the interactive snippet editor can be keyboard operated (add short cuts for run, make sure one can escape from the snippet)

Use z3 version 4.9.1

There is a new release of z3 out today.
It doesn't seem to get picked up by the build.
It has some npm version dependencies as well that have changed.
With this release we should be able to remove some of the no-build tags.

Automating Reference Documentation publication

Currently the reference documentation is built on releases and available as a zip file from the release hive.

https://github.com/Z3Prover/z3/releases/download/z3-4.9.1/z3doc.zip

Then I manually download this and unzip the contents into z3prover.github.io/api/html
It is a repository under https://github.com/z3prover
Commit and push

The process for uploading artifacts should be reasonably similar for releases.
Even a self-contained GitHub action that builds documentation by itself and pushes to the right place (could be microsoft.github.io/z3guide if this is better) would be great and perhaps easier to maintain than complicating the release.yml Azure pipeline.

z3 native computing

  • take z3 snippets from the native cli -> into remark tree
    • z3 cli in codespace -> talk to nbjorner ( about the npm stuff )
    • create a remark package that grabs z3 snippets runs and injects output
    • caching mechanism locally
    • ? what happens when z3 fails ?
    • ? how many clis at once ? -> to start one, think about how to do more
    • configure ghactions to leverage the cache mechanism across builds

Phase 1

  • static website > docusaurus < @rlisahuang
  • migrate content to markdown @ayanamonr
  • katex enabled for the math stuff @rlisahuang
  • native computing every snippet at runtime @rlisahuang
  • github publish action
    • make sure the typescript stuff is correctly
  • codespace configured
  • bjorner onboarding documentation @ayanamonr << last step! Subject B :)
  • react component to render output

use remark pluging logger

The second argumen of visit should be a logger; we should use that in order to get proper logging in the builds

landing page inconsistent

image

  • big title at start should probably have some other content
  • learn z3 at bottom section is somewhat misleading as it takes the user to another web site. suggestion: remove

Top-level Organization

Once the SMTLIB tutorial is interactive, the format of the site may very well transition to a wider scope.
The indexing used here
https://github.com/facebook/docusaurus/blob/main/website/docusaurus.config.js
allows for multiple sections.

For z3 the main sections are:

  • Z3 Tutorial (SMTLIB):
    • Logic
    • Theories
    • Strategies
    • Fixedpoints
    • Optimization
    • Playground
  • Programming Z3 Tutorial:
    • Interface concepts (a section that explains main interface concepts and their behavior. Examples in Python?)
      • Context
      • Expressions, Sorts, Functions
      • Model
      • Solver
      • Optimize
      • Fixedpoints
      • Tactic
    • Guides
      • Python tutorial
      • programmingz3 document
    • Examples/Case studies
      • point to examples from GitHub
      • interactive examples (in Python)
      • external links
      • Bazar
  • Language Binding reference (currently at https://z3prover.github.io/api/html)
    • C
    • C++
    • Python
    • Dotnet
    • Java
    • OCaml
    • JS

Other notes:

  • Java Script Tutorial (maybe, or mesh with SMTLIB Tutorial).
  • Python Tutorial (import Jupyter notebooks and programmingz3.mdk)
  • API (link to z3prover.github.io/api/html, or automatically pull material from doc.zip on release)
  • Examples/Case Studies/Home work - some format for sharing information and adding content.
  • External resources:
    • There are external resources (generally, I have little idea and they just appear out of nowhere, but they seem to be known to students): Rust API, Haskell API, PySMT, ...
  • Reference material:
    • programming z3 - that is, using z3 to program constraint solving services.
    • z3 internals - planned for January tutorial, a tutorial introduction on algorithms and implementation for SMT

Resources, such as Slides are linked at bottom of page.

Landing Page Polishing

Currently thinking about the design from https://infinum.github.io/eightshift-docs/, minus the sections below intro. So just one big background, a big title, some text description, and two buttons that get you to Tutorial and Playground, respectively.

It should be able to be done through pure CSS.

TODOs:

  • background pic?
  • landing page redesign
  • theme color? thinking about blu-ish due to the current Z3 logo
  • @NikolajBjorner Z3 logo in SVG/PNG?

Cross references

Develop schema for cross referencing material from the tutorial.
So far there is a way to cross reference SMTLIB in some format. For example.

SMTLIB2 standard Integers

Other categories of cross references are:

  • Reference manual
  • Lectures
  • Papers
  • Case Studies
  • Stackoverflow questions / github discussions - in a nutshell user interaction.

What is a good schema for the static content and way to integrate dynamic content?
Preliminary way:

Note

Information the user should notice even if skimming.

[!TIP]
Optional information to help a user be more successful.

[!IMPORTANT]
Essential information required for user success.

[!CAUTION]
Negative potential consequences of an action.

[!WARNING]
Dangerous certain consequences of an action.

The last point about cross-referencing user interaction is more ambitious and should be aligned with developing methods to integrate learning feedback. Given the state of z3guide, what is the long- and short-term plan for integrating such signals?
What are the technical enablers? (let me zoogl3 this, or link to github discussions, create discussions, cross-link discussions?)

Reset sample

Once a snippet is edited, add button to reset to original code

Things to ask users about

  • github button linking to a main github discussion thread for the online guide?
  • same thing for stackoverflow? (some work that Denae Ford has worked on?)
  • emailing the professor?
  • line numbers?
  • copy button?
  • reset button?
  • keyboard navigation?

Security concerns with z3-js boxes

Now that we eval every z3-js snippet, the door to potential security attacks is opened.

A possible scenario I could think of is that someone forks this repo, changes some z3-js content to be malicious, and hosts it on a public github page. Visitors of that page could have their information stolen through such malicious content.

Pretty sure the official docusaurus website has some mechanism against it as there are executable and editable JS blocks too.

TODO:

  • look into sandboxing / sanity checks that the built-in editor might provide.

Content Migration

  • convert html content to markdown
  • split content into different files

Phase 2

  • Add interactivity with Z3 (SMT-LIB)
  • Migrate content from the Python tutorial and have the Z3 Python bindings run in the browser (maybe through Pyodide?)
  • Z3 JS content
  • Improve content through interviews

z3-wasm support

Context

I encountered some issues with getting the TypeScript bindings to work in Node.js. The idea is to break down a given code snippet (in the smt2 format) by line and obtain the output through Z3.eval_smtlib2_string. My main reference is this z3-wasm webpage, which uses our official WASM build. The way inputs are processed is detailed in their main.js file.

Problem with Node.js

Note that this website runs z3-wasm in the browser from the client side, while we want to run z3-wasm with Node.js from the server side. Therefore, their logic for running Z3 does not work in our scenario -- I had RuntimeErrors complaining about the inability to find z3-built.wasm. My implementation for running Z3 (currently commented out) can be found in website/src/remark/render-code-blocks.mjs in PR #18 .

Additional issue(s) with z3-wasm

I also noticed that several code snippets from our tutorial would not work in the web interface cited above. I wonder if this is a bug with the WASM build, or if there are additional API calls we should use instead for such code snippets. An example of snippet that does not work in the web interface:

(set-option print-success true) 
(set-option produce-unsat-cores true) ; enable generation of unsat cores
(set-option produce-models true) ; enable model generation
(set-option produce-proofs true) ; enable proof generation
(declare-const x Int)
(set-option produce-proofs false) ; error, cannot change this option after a declaration or assertion
(echo before reset)
(reset)
(set-option produce-proofs false) ; ok

I got a bunch of syntax errors when I ran it in that web interface.

@NikolajBjorner We would like some help from Kevin on the following issues:

  1. A simple example of running z3-wasm in Node.js with smt2-formatted inputs;
  2. The syntax errors I got from running code snippets from our tutorial in the existing web interface -- is it a bug, or are there ways around it?

Run Z3 in the browser

Attempting to run Z3 in the browser (currently without webworkers). Code in #42 .

According to @NikolajBjorner it seems that there have been major changes to the JS API since June 14, which involves the names of several files (e.g. wrapper.js was gone) and the signature of init (it used to accept one argument, which is the result of initZ3, now none).

@bakkot It would be super helpful if you could provide us with some examples of:

  • Running Z3 in the browser without webworkers, and
  • ... using webworkers

with the current (4.9.1) npm release.

Mismatched output from z3-wasm vs. z3 executable

Several code snippets from our tutorial would not work in the web interface cited above. According to @NikolajBjorner z3-wasm does produce different outputs than the z3 executables.

Code snippet example:

(set-option :print-success true) 
(set-option :produce-unsat-cores true) ; enable generation of unsat cores
(set-option :produce-models true) ; enable model generation
(set-option :produce-proofs true) ; enable proof generation
(declare-const x Int)
(set-option :produce-proofs false) ; error, cannot change this option after a declaration or assertion
(echo "before reset")
(reset)
(set-option :produce-proofs false) ; ok

Moving the conversation from #19 .

The possible solutions we face:

  1. Remove tutorial materials that contain such problems;
  2. Coordinate with @NikolajBjorner and @bakkot on a wasm build that produces consistent outputs.

screen reader support

ensure that the content is properly handled by a screen reader, in particular that changes to the output div are properly announced (use something like aria-live)

extra material

  • integrate also other tutotiral material

  • integrate tutorial material based on case studies, such as:

  • have a way to assemble pointers to other self-contained examples. A static set of links could bit-rot. Is there a good dynamic approach (let me zoggl3 that for you?)

  • assemble and allow for adding links to youtube material.

    • Nadia has a 30 minute tutorial where she uses the python API. The python code is stored in a Git repository. Can we link to such videos and make the reproducibility of such tutorial easier than just dumping files in a Git?
  • add a mode for running Java script examples

    • add tag z3js similar to z3 tag for environments.
    • it runs the java script in the enclosure together with suitable imports.
    • then one can mix java script examples with the smtlib2 examples
  • run python code samples

  • integration with documentation generation.

Overall:

  • how do we best integrate cross referencing?
    • Started to add cross reference to SMTLIB2 documentation. ad hoc
    • Cross reference to examples
    • Cross reference to reference documentation
    • Cross reference to github discussions and stackoverflow discussions or other discussions
  • how can the tutorial and learning material be made palatable for contributors?
    • Some users could be tempted to add example material (puzzle solving) and making it easier to add such helps everybody.

Onboarding documentation

  • a. Forking this website to extend / customize the existing z3 guide and host on the user's own github pages;
  • b. Forking the tutorial template to customize an online tutorial for a custom language

Record update

describe record update construct for algebraic datatypes

Fix all tutorial code blocks

  • In all website/docs/*.md files, change all instances of
```
<some code>
```

to

```z3
<some code>
```
  • There are some missing quotation marks for strings and angle brackets for int comparisons in the material currently in docs/intro.md. Please fix those manually. For example:
(echo starting Z3...) ;; missing quotations around "starting Z3..."

and

(assert ( a 10)) ;; should have been `(assert (> a 10))`

always show precomputed output

It would be more efficient to immediately show the pre-computed output (that's one less button and it's useful information). We have it let's show it.

I recommend doing this in remark at rendering time by generating a new code node; that later gets rendered by docusaurus. As a bonus, it should be the copy/wrap icons.

Also, drop "Output:", it feels more like noise at this point.

Docusaurus Build

  • set up docusaurus
  • build in github action
    • check that the typescript stuff works
  • deploy to ghpages

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.