Apalache Documentation

repository·main·Indexed 20 days ago

https://github.com/apalache-mc/apalache

A tool for TLA+ model checking, featuring a Bounded Model Checker Modulo Theories (BMCMT) that encodes TLA+ operations into SMT formulas. The project includes Shai (Server for Human-Apalache Interaction) for RPC-based interaction via ZIO-gRPC, a custom TLA+ syntax highlighting plugin for highlight.js, and a multi-stage configuration system for validating runtime options.

Tokens
96.3K
Snippets
306
Records
448
Agent score
69%

What's inside Apalache

  1. What is Shai?

    main

    Shai (Server for Human-Apalache Interaction) is a component of Apalache designed to support human interaction with the symbolic model checker. It provides a server-based interface for clients to interact with Apalache's core logic.

    One of its primary services is TransEX, which allows users to interactively drive the Apalache TransitionExecutor via Remote Procedure Calls (RPCs).

  2. Overview of Bounded Model Checker Modulo Theories (BMCMT)

    main
    The Bounded Model Checker Modulo Theories (BMCMT) is a tool designed to check executions of TLA+ specifications up to a predefined execution length. It works by encoding the semantics of TLA+ operations into Satisfiability Modulo Theories (SMT) formulas, allowing for efficient verification of bounded execution paths.
  3. Navigate Apalache documentation

    main

    The Apalache documentation is organized into five distinct sections depending on your needs:

    • Apalache User Manual: Core operational guidance including Installation, Running the Tool, and Fine Tuning.
    • Apalache Tutorials: Step-by-step guides for learning the tool.
    • Apalache HOWTOs: Practical solutions for specific tasks.
    • TLA+ Language Reference Manual: Detailed technical specifications of the TLA+ language.
    • Guidelines for Idiomatic TLA+: Best practices for writing clean and effective TLA+ code.
  4. Principles of Symbolic Model Checking with Apalache

    main

    To effectively use Apalache's symbolic model checking capabilities, TLA+ specifications must be written following specific principles. A critical requirement is the use of type annotations for all variables and constants.

    For guidance on implementing these principles, refer to the following core topics:

    • Assignments and symbolic transitions: How to structure state changes.
    • Folding sets and sequences: Techniques for handling collections.
    • Invariants (State, Action, Trace): Defining properties to check.
    • Enumeration of counterexamples: Understanding how Apalache presents violations.
    • The Apalache Module: Using the specialized Apalache module.
    • Naturals module: Using the specialized Naturals module.
  5. Apalache execution modes

    main

    Apalache supports several modes of execution depending on your goal:

    • parse: Reads a TLA+ specification and flattens it by instantiating all modules. Terminates if there are no parse errors.
    • typecheck: Performs parse and runs the Snowcat type checker to infer types of all expressions.
    • simulate: Performs typecheck and runs the model checker in simulation mode. It randomly picks a sequence of actions and checks invariants for that subset of executions. This is typically much faster than the check command.
    • check: Performs typecheck and runs bounded model checking. It checks invariants for all executions up to the length specified by --length.
    • test: Performs check in a mode designed to test a single action.
    $ apalache-mc --help
  6. What is Relational TLA (reTLA)?

    main

    Relational TLA (reTLA) is a severely restricted fragment of TLA+ supported by Apalache. It covers uninterpreted first-order logic and is designed to allow for a more direct and efficient encoding compared to standard TLA+.

    Key Benefits

    • Simplified Encoding: Avoids the complex SMT encodings required for standard TLA+ data structures (like sets, records, and sequences) and the need for 'arena' bookkeeping.
    • Standalone Constraints: Running Apalache with reTLA encoding skips the model-checking pass and instead produces a standalone file containing all generated constraints. This file can be consumed by other tools or alternative backend solvers (e.g., IVy or VMT).
    • Performance: By rewriting specifications to use predicates (functions) instead of complex data structures, users can achieve more efficient SMT encodings.
  7. What is the Keramelizer and KerA?

    main
    The Keramelizer is a preprocessing component that rewrites TLA+ expressions into KerA, APALACHE's internal kernel language. While most TLA+ expressions have a direct translation to KerA, certain complex expressions require specific translation decisions to ensure they can be processed by the subsequent SMT translation stages.
  8. What is the Informal Trace Format (ITF)?

    main

    The Informal Trace Format (ITF) is a simplified JSON-based format used by Apalache and Quint to represent counterexamples (traces). Unlike the standard TLA+ or Apalache IR serialization, ITF is designed to be easily readable by engineers unfamiliar with TLA+ and simple for external tools to parse.

    Traces in ITF represent executions in two possible shapes:

    1. Finite execution: A simple sequence of states.
    2. Lasso execution: A finite sequence of states (the prefix) followed by an infinitely repeated sequence of states (the loop).

    Each state in a trace is a mapping from variable names to expressions. These expressions use a minimal subset of TLA operators, including integer/string literals, set/sequence/record constructors, and the function operators :> and @@.

  9. Write types using TypeOK syntax in TLA+

    main

    You can express types in TLA+ using native set membership (\in) syntax. This is known as the TypeOK style. Common patterns include:

    • Integers: x \in Int
    • Functions: f \in [Int -> Int]
    • Subsets: f \in [SUBSET Int -> SUBSET Int]
    • Records: r \in [a: Int, b: STRING]
    • Tuples: f \in SUBSET [Int \X Int -> Int]
    • Higher-order operators: Use THEOREM to define the type of an operator.

    Example of a higher-order operator type definition:

    THEOREM BarType ==
      ASSUME NEW G(_,_),
             \A x \in Int, y \in STRING : G(x,y) \in Int
             PROVE  Bar(G) \in BOOLEAN
    THEOREM FooType ==
      \A a \in Int: \A b \in STRING: Foo(a, b) \in Int
  10. Understand Explicit-state Bounded Model Checking

    main

    Explicit-state Bounded Model Checking (BMC) is an adaptation of the explicit-state algorithm that limits the search to traces of a maximum length $k$.

    How it works

    Instead of just tracking states, the algorithm tracks pairs of (state, step_count). It explores states up to a depth of $k$. If the invariant $I$ is violated at any state within $k$ steps, a witness is found.

    Key Characteristics

    • Termination: Unlike general explicit-state checking, BMC is guaranteed to terminate if the initial state set $S_0$ is finite and each state has finitely many successors, even if the total state space is infinite.
    • Completeness: BMC is incomplete. It will find an invariant violation if it occurs within $k$ steps, but it will fail to find violations that require a trace longer than $k$.
    • Relationship to Diameter: If a system has a finite diameter, BMC is equivalent to full model checking, provided the bound $k$ is greater than or equal to that diameter.
  11. Understanding Record and Variant patterns in TLA+

    main

    When writing TLA+ specifications for use with Apalache, you will typically encounter two patterns for using records:

    1. Plain Records: Records with a fixed, consistent set of fields that are passed around. The type checker expects these to have the same shape.
    2. Variants (Discriminated Unions): Records of different shapes collected in a single set. These are distinguished by a special field called a discriminator (commonly named type). This pattern is frequently used in protocols like Paxos or Raft to represent different types of messages (e.g., Prepare, Promise, Accept) within a single set of messages.

    Precise type inference for these patterns helps prevent spurious counterexamples caused by accessing fields that do not exist in certain variants of a record.

  12. Understand Apalache configuration and command options

    main

    Apalache uses a unified configuration framework where settings can be provided through multiple sources. These sources are treated as producers that are eventually merged and validated to create the final configuration used by Apalache passes.

    Configuration Producers

    • CLI commands: Command-line options specified by the user.
    • JSON config: Configuration files (explicit, local, or global) written by users or tools. Apalache exclusively accepts JSON format for configuration files.
    • Built-in defaults: Standard settings applied when options are not specified.

    Configuration Flow and Precedence

    Configuration is managed by the ApalacheConfigLoader, which handles discovery and precedence. When multiple configuration sources are provided, they are merged using the following precedence (highest to lowest):

    1. Primary (e.g., CLI commands)
    2. Explicit/Local (e.g., local JSON files)
    3. Global (e.g., global JSON files)

    Internal Components

    • ApalacheConfig: The core model capturing the merged configuration. It uses ConfigPatch implementations to represent partial configurations for specific command sections.
    • ApalacheConfigJsonParser: A strict JSON decoder that rejects unknown fields.
    • ApalacheConfigResolver: Performs command-specific validation and produces ValidatedOptions (such as TypecheckerOptions or CheckerOptions) for specific consumers.
    • ApalacheConfigLoader: The main entry point used by CLI tooling and RPC services.

    For the authoritative user-facing schema and discovery rules, refer to the configuration manual.