8000 GitHub - keoghpe/learnyoutla: Learn TLA+ one challenge at a time, in your terminal. A learnyounode-style workshop graded by the real TLC model checker. · GitHub
[go: up one dir, main page]

Skip to content

About

Learn TLA+ one challenge at a time, in your terminal. A learnyounode-style workshop graded by the real TLC model checker.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

7 Commits

Folders and files

Repository files navigation

learnyoutla

Learn TLA+ one challenge at a time, in your terminal.

learnyoutla is a hands-on workshop for TLA+, the specification language used to find design bugs in distributed and concurrent systems before they're built. It's inspired by learnyounode: you read a short lesson, write a spec in your own editor, and run learnyoutla verify. The real TLC model checker grades your work.

The course starts from zero. It assumes no math background, teaches the sets-and-logic foundation first, then state machines, PlusCal, liveness and fairness. It ends with you modeling a real distributed protocol.

──────────────────────────────────────────────
  L E A R N   Y O U   T L A +
  for much win, one behavior at a time
──────────────────────────────────────────────

  Part 1 · The math
  ✓ 01  Hello, module
  · 02  Sets  ← you are here
  · 03  Logic and quantifiers

Install

You need Java 11+, because TLC is written in Java. Check with java -version. If you don't have it, install Adoptium Temurin or run brew install openjdk.

cargo install --locked learnyoutla

Or the latest from GitHub: cargo install --locked --git https://github.com/keoghpe/learnyoutla, or from a clone: cargo install --locked --path .

Keep --locked. It makes cargo use the dependency versions in Cargo.lock, which build on Rust 1.80+. Without it, cargo picks the newest versions, and some of those need a much newer Rust.

Then:

learnyoutla doctor

doctor checks Java and downloads the pinned TLA+ tools (tla2tools.jar v1.7.4, 2.2 MB, from the official tlaplus releases). It verifies the download's SHA-256 checksum and stores it in ~/.learnyoutla/tools/.

Use

mkdir tla-workshop && cd tla-workshop
learnyoutla           # see the challenges and your progress
learnyoutla print     # read the current challenge; creates ./01-hello-module/Hello.tla
# ...edit the file in your editor...
learnyoutla verify    # grade it
learnyoutla next      # move on
Command What it does
learnyoutla List challenges and progress
print Show the current challenge and create its starter files
verify [dir] Grade your solution
run [dir|file.tla] [-- tlc args] Run TLC on your spec yourself, for experimenting
translate [dir|file.tla] Translate the PlusCal algorithm in your spec, so you can read the TLA+
hint Reveal the next of up to three progressively specific hints
solution Show the reference solution (after you pass, or with --force)
next / select <n> Move to the next challenge, or jump to one
reset Forget progress (your files are untouched)
doctor Check your setup

Editor: any editor works. The TLA+ extension for VS Code adds syntax highlighting and inline parse errors.

The course

Part Challenges
1 · The math Modules and operators · Sets · Logic and quantifiers · Functions, records and tuples · LET, CHOOSE and recursion
2 · State machines Variables, Init and Next · Invariants and TypeOK · Nondeterminism (TLC solves a puzzle) · Reading counterexamples · Interleaving and race conditions · Break the spec: mutual exclusion
3 · PlusCal Translating PlusCal · Processes, labels and atomicity · await, either, with: concurrent bank transfers
4 · Liveness Temporal operators · Fairness · Break the spec: deadlock, livelock, starvation
5 · Capstone Modeling an unreliable network · Two-phase commit with crashes · Simplified Raft log replication

All 20 challenges are available. See CURRICULUM.md for what each one covers.

How grading works

learnyoutla doesn't parse TLA+ itself. It wraps your module in generated test modules, runs the real TLC model checker on them, and reads TLC's machine-readable (-tool) output. There are three kinds of check:

  • Expression checks evaluate definitions such as Double(21) = 42 against your module and report what you got versus what was expected.
  • Model checks run TLC on a spec and expect a particular outcome: no errors (optionally with an exact state count), a specific invariant violation, a deadlock, or a temporal property violation.
  • Break-the-spec checks run your invariants and temporal properties against hidden buggy specs. They must catch every bug and still pass on the correct spec.
  • Refinement checks compare your spec with a hidden reference, in both directions, so every step you allow is legal and every legal step is allowed.

PlusCal algorithms are translated automatically before grading.

Credits

The format is borrowed from learnyounode and the NodeSchool workshoppers.

Many of the exercises are adapted from classic problems and from existing TLA+ teaching material. The specs and lessons here are written from scratch, but the ideas come from these sources:

10, 13 · Interleaving, processes and labels
Challenge Based on
06 · Your first behavior The HourClock spec in Leslie Lamport's book Specifying Systems
08 · Nondeterminism The water-jug puzzle from Die Hard with a Vengeance (1995), as a TLA+ exercise in Lamport's TLA+ Video Course, including the trick of breaking an invariant to find the solution. Jug-measuring puzzles themselves are centuries old.
The classic lost-update race on a shared counter
11, 17 · Mutual exclusion and liveness Peterson's algorithm (G. L. Peterson, Myths About the Mutual Exclusion Problem, 1981)
12 · PlusCal Euclid's algorithm, a standard first example in Lamport's PlusCal material
14 · Bank transfers The bank-transfer examples common in TLA+ teaching, such as Hillel Wayne's Learn TLA+
18 · An unreliable network Stop-and-wait retransmission, a relative of the alternating bit protocol (Bartlett, Scantlebury and Wilkinson, 1969)
19 · Two-phase commit Lamport's TCommit and TwoPhase specs from the TLA+ Video Course, and Consensus on Transaction Commit (Jim Gray and Leslie Lamport, 2006)
20 · Raft The Raft paper, In Search of an Understandable Consensus Algorithm (Diego Ongaro and John Ousterhout, 2014), including its Figure 8 scenario, and the TLA+ spec in Ongaro's PhD thesis

More classic specs, including versions of several of these, are in the official tlaplus/Examples repository.

Contributing

Challenges are plain files: a README, a starter, a reference solution, hints, and a small challenge.toml describing the checks. You can add one without writing any Rust. See CONTRIBUTING.md.

License

MIT. TLA+ and its tools are by Leslie Lamport and the TLA+ community, under their own MIT license. This project downloads them but doesn't redistribute them.

About

Learn TLA+ one challenge at a time, in your terminal. A learnyounode-style workshop graded by the real TLC model checker.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0