This repository contains the implementation of TempEST, a tool for probabilistic model checking of Metric Temporal Logic (MTL) formulas using the PRISM model checker.
TempEST provides functionality for:
- Building Discrete-Time Markov Chain (DTMC) models from execution traces
- Parsing and converting Metric Temporal Logic (MTL) formulas to Linear Temporal Logic (LTL) formulas
- Performing L1-distance-based search for counterexamples
- Parallel batch processing of PRISM model checking queries
Install Python dependencies using:
pip install -r requirements.txtTempEST requires PRISM to be installed and accessible. PRISM can be downloaded from:
- Official Website: https://www.prismmodelchecker.org/
- GitHub: https://github.com/prismmodelchecker/prism
-
Download PRISM from the official website or clone from GitHub
-
Extract/compile PRISM according to the official instructions
-
Configure the PRISM path using one of the following methods:
Option A: Environment Variable (Recommended)
export PRISM_PATH="/path/to/prism/bin/prism"
Option B: Modify
tempest.pyUpdate theprism_pathvariable intempest.py:prism_path = os.environ.get("PRISM_PATH", os.path.abspath("path/to/prism/bin/prism"))
Default: If neither is set, TempEST assumes PRISM is in
prism-mac/bin/prismrelative to the script (macOS default).
.
├── tempest.py # Main implementation file
├── mltl2ltlf.py # MTL to LTL formula converter
├── mltl.lark # Lark grammar file for parsing MTL formulas
├── requirements.txt # Python dependencies
└── README.md # This file
Important: The mltl.lark file must be in the same directory as mltl2ltlf.py for the parser to work correctly.
The mltl2ltlf.py module is based on the mltl2ltlf library by lu-w, with adaptations for use in TempEST.
Original Repository: https://github.com/lu-w/mltl2ltlf
License: MIT License
The original library converts Mission-Time Linear Temporal Logic (MLTL) to Linear Temporal Logic on Finite Traces (LTLf). TempEST includes an adapted version of this converter to handle MTL formula parsing and conversion.
-
Install dependencies:
pip install -r requirements.txt
-
Install PRISM (see Requirements section above)
-
Configure PRISM path (choose one):
- Set environment variable:
export PRISM_PATH="/path/to/prism/bin/prism" - Or modify
prism_pathintempest.py(see Requirements section)
- Set environment variable:
-
Run the example:
python tempest.py
import tempest
# Build a DTMC model from a trace
history = {"a": [0, 0, 1, 0, 1], "b": [0, 1, 0, 1, 0]}
model_path = "model.pm"
horizon = 5
tempest.model_builder(history, model_path, horizon)
# Check an MTL formula
formula = "F[1, 2] a"
result = tempest.run_prism(formula, model_path)
print(f"Formula satisfied: {result}")To find the minimum L1 distance to a counterexample:
formula = "F[5, 30] p"
model_path = "model.pm"
horizon = 30
min_distance = tempest.entire_search_l1_batched(
formula,
model_path,
horizon,
max_workers=4, # Number of parallel workers
chunk_size=10 # Formulas per batch
)
print(f"Minimum L1 distance: {min_distance}")Builds a PRISM DTMC model from a trace history.
Parameters:
history: Dictionary mapping atom names to lists of boolean values (trace)model_path: Path where the PRISM model file will be writtenhorizon: Maximum time horizon for the model
Checks if an MTL formula is satisfied by the PRISM model.
Parameters:
input_formula: MTL formula string (e.g.,"F[1, 2] a","G[5, 10] p")model_path: Path to the PRISM model file
Returns:
Trueif the formula is satisfied,Falseotherwise
Performs an L1-distance-based search for counterexamples, processing batches in parallel.
Parameters:
input_formula: MTL formula with parameterized intervals (e.g.,"F[t_1, t_2] p")model_path: Path to the PRISM model filehorizon: Maximum time horizonmax_workers: Number of parallel worker threads (default: 4)chunk_size: Number of formulas per batch (default: 10)
Returns:
- Minimum L1 distance to a counterexample, or
horizonif no counterexample found
TempEST supports the following MTL operators:
- Eventually with interval:
F[a, b] φ- φ holds at some time in [a, b] - Always with interval:
G[a, b] φ- φ holds at all times in [a, b] - Until with interval:
U[a, b]- standard until operator - Eventually with upper bound:
F_<=n φ- equivalent toF[0, n] φ - Eventually with strict upper bound:
F_<n φ- equivalent toF[0, n-1] φ - Always with upper bound:
G_<=n φ- equivalent toG[0, n] φ - Always with strict upper bound:
G_<n φ- equivalent toG[0, n-1] φ
Standard LTL operators (&, |, !, X, U) are also supported.
# Eventually p holds between cycles 5 and 30
formula1 = "F[5, 30] p"
# Always q holds between cycles 1 and 10
formula2 = "G[1, 10] q"
# Eventually p within 20 cycles
formula3 = "F_<=20 p"
# Complex formula with conjunction
formula4 = "(F[1, 5] a) & (G[2, 8] b)"The entire_search_l1_batched function uses parallel processing to speed up model checking:
- Formulas are grouped by L1 distance
- Each distance group is divided into chunks
- Chunks are processed in parallel using
ThreadPoolExecutor - Early termination occurs when a counterexample is found
Adjust max_workers and chunk_size based on your system's capabilities and PRISM's performance.
If you encounter errors about PRISM not being found:
- Verify PRISM is installed correctly
- Update
prism_pathintempest.pyto the correct location - Ensure PRISM executable has execute permissions
If MTL formulas fail to parse:
- Verify the formula syntax matches supported MTL operators
- Check that
mltl.larkis in the same directory asmltl2ltlf.py - Ensure the
larkPython package is installed
If model building fails:
- Verify
historydictionary has consistent list lengths - Ensure
horizonmatches the length of trace lists - Check write permissions for
model_path
If you use TempEST in your research, please cite:
@software{tempest2026,
title={{TempEST: Temporal Exploration for Stress Testing}},
author={Katie Wang and Rory Lipkis and Anastasia Mavridou},
year={2026},
url={https://github.com/kwangel/TempEST}
}Note: TempEST uses an adapted version of the mltl2ltlf library. If you use the MTL parsing functionality, please also consider citing the original work.
This project is licensed under the MIT License.