Code evaluation · Research feature

Software Testing Meets Bayesian Workflow: A Literature-Driven Artifact Study of Probabilistic Programs

A study evaluates testable correctness properties for probabilistic models derived from a key Bayesian textbook, assessing their utility in automated testing across 59 real-world models.

Adapted from research by Oleg Jarma, Maja Dall, Raúl Pardo and colleagues.

arXiv preprint revision · 2026-10-12 · Attribution & reuse
In this article
Editorial illustration of linked workflow.

Editor’s introduction

These properties, rooted in established statistical modeling practices, are shown to be relevant and applicable in practice, with most tests proving stable despite theoretical flakiness risks. The research finds that model complexity and sampler configuration significantly influence test flakiness, with some models exhibiting up to 50% flakiness due to insufficient sampling or high tolerance thresholds. This misalignment suggests a gap between general-purpose mutations and the specific nature of probabilistic correctness criteria. The findings indicate that while the properties are usable in real-world testing, their effectiveness in mutation testing is limited, highlighting a need for tailored mutation strategies in probabilistic program verification.

Introduction

A number of papers address bugs in probabilistic programs and probabilistic inference systems, however, to our knowledge, none attacks the oracle problem or, more generally, formalizes properties to automate the testing of probabilistic models. Correctness is hard to specify here. It is difficult to discern whether poor convergence or poor fit arise because the problem is hard, the model is broken, or wrong assumptions were made. It is thus hard to understand if the numbers produced by inference carry ground-breaking discoveries or manifest bugs. This calls for using partial proxy properties as tests. Yet it is unclear which such properties hold for data analysis models in general and which only for specific model classes. Answering this would enable the systematic reuse of tests and prevent checks where they do not apply. Finally, there is a gap between the rich but largely manual and informal practices for checking models used in applied statistics and the automated, systematic testing practices of software engineering.

Overall, we identify 17 specification properties applicable across all main aspects of the probabilistic models (data, prior, likelihood, posterior, parameters, model structure). Most of the properties are broadly applicable to many models or model classes. We show that all properties are relevant and testable on realistic models, using our designed oracles, and that these oracles are robust, in the sense that most of the tests are not flaky. This is despite the inherent non-determinism in both models and tests. We gather evidence that flakiness in this domain depends more on the complexity of the model-under-test than on the tested property. Finally, we discover a significant mismatch between the fault models induced by our probabilistic properties and standard mutation testing, calling for dedicated mutation operators for this domain.

Our method engages deeply with the domain knowledge of Bayesian data analysis and probabilistic programming as practiced in the field, using a textbook synthesis as a proxy. We have two audiences. First, we want to demonstrate to the Bayesian Data Analysis community, that it is possible and beneficial to automate a large part of their procedures. Second, we want to attract the software testing community to the properties and model requirements that data analysts work with, in order to ground the software engineering research for probabilistic programs in statistical modeling practice.

Analysis and Implementation

We follow a two-phase design. In the first phase, we identify correctness properties for model design. In the second phase, we implement oracles to make the properties automatically testable, and to study how they behave as tests.

We begin by identifying procedures that SR recommends to assess whether a model or its inference behave as expected—we call these operations checks. For each check, we record its location in the book, the type of model it is applied to, the quantity computed, the reference value it is compared against, and how the outcome is judged. We exclude checks for which the oracle is unclear, or impossible to implement without performing extensive property-specific research (to the best of our knowledge). Chiefly, the checks that rely on subjective judgment that cannot be turned into an automated decision procedure are excluded.

The process is iterative. We cluster and refine the properties of interest as we proceed, by comparing each identified check with the prior ones and adjusting them (for instance merging). Once the list is stable, we iterate again over the final collection to ensure consistency.

Model Type (Generality)

Our properties include both general checks, applicable to different types of models, and specific checks for select model classes. The generally applicable properties enforce universal statistical concepts that are relevant regardless of the model type (similar to say deadlock-freedom or lack of data races in concurrent programming). Our implementations of derived tests can be reused by data analysts using PyMC regardless of the model they work with. The specific properties enforce requirements regarding a problem or a requirement for a class of models, for instance linear regression models. Six properties in our collection are general and apply to most model types and the rest are model-type-specific, most commonly limited to Count and Categorical models, which themselves are broad classes.

Some of the general properties target classic statistical concepts: Posterior unimodality checks whether the posterior has a single mode, Directional bias of the posterior looks at its symmetry, and Multicollinearity flags strong correlation among the model’s predictors. Others use a test procedure that does not depend on the model type. Information content of the likelihood compares the prior and the posterior through their KL-divergence. Parameter reconstruction verifies if the parameters used to simulate data can be recovered from it. Conditional independence attempts to confirm if the model is consistent with its assumed causal structure. The last two properties rely on external input aside from the model itself: simulated data with known original parameters and previously assumed causal relations respectively.

The specific properties above concern the likelihood, and each model belongs to exactly one of these classes. The remaining specific properties concern the model’s parameter structure instead, and can combine with any likelihood class: a model can be both Linear and Multivariate, or both Count and Hierarchical. Hierarchical models implement hyper-priors to model both populational and group-level variation in the model. Non-centered parameterization validates whether the chosen parameterization (centered or non-centered) suits the data, and Shrinkage level variance checks whether group-level estimates are pooled as expected. Multivariate models treat the outcome as a vector rather than a single value. Correlation matrix values specifically tests whether the Correlation matrix, a prior parameter particular to these models, is correctly defined.

Subject Probabilistic Models

Since models and properties are paired in SR (each property is pedagogically exemplified on a matching model) it is important to find alternative cases to reduce bias. We follow Sect. 7 performing a targeted search for models of the given types in order to identify examples to which the properties pertain. Note that a random sampling would be unlikely to give a lot of interesting property–model matches, given how large the specification and model space is. A random pairing of specifications and systems is unlikely to be successful in any domain.

All models are designed by experts in probabilistic modeling (not ourselves), and are supposed to be correct. However, we do include (if available in a data source) or create (if not available) incorrect versions of some models to make sure that each property has at least one satisfying and at least one falsifying witness. This emulates a regression test scenario, and shows that our oracle implementations are effective. The negative examples represent common errors in model design, the positive examples represent the error resolutions. Overall the models can be used to evaluate whether our properties detect errors in more complex models than those of SR, and even models not originally in the scope of the book.

Results

In our experiments, the model under test affects flakiness more than the property. For instance, GrsmLatentIgrModel was used for testing two properties and it shows a 50% flakiness, with 100% for theoretically flaky properties (the other property is theoretically not-flaky). This could be explained by the sampler configuration (the number of samples) not being sufficient for this complex model, or by the property tolerance threshold being set too high. Half (50%) of the tests of StateSpaceStochasticLevelStochasticSeasonalModel are also flaky. This model was tested with three theoretically flaky properties and one deterministic test. However, only Posterior unimodality and Directional bias of the posterior show flakiness in practice for this model. The SeedsCenteredModel and NormalMixtureKModel were tested against three theoretically flaky properties and only one (Information content of the likelihood) showed flakiness, i.e., 33% flakiness rate. EightSchoolCentredModel was tested in four theoretically flaky properties, but only shown flaky for one (Posterior unimodality). The other three properties, Information content of the likelihood, Shrinkage level variance and Directional bias of the posterior, did not yield flaky tests. All in all, there are strong indications that the model affects flakiness more than a property, with complex models being more prone to flakiness.

Only 6 out of 123 tests were practically flaky, which indicates that statistical oracles can be robustly implemented, and flakiness associated with probabilistic programming might be possible to overcome in practice. Furthermore, the tested properties seem to have lower effect on the flakiness than the complexity of the models under test.

Results

“Fail” counts tests that run to completion and trigger a violation of a test assertion (the mutant is killed). Killing mutants is a positive verdict in mutation testing. It shows that the test harness works. Most of observed failures are for K-1 model completeness, which tests a vector size. Several operators, such as Number_Replacer, change the integer used to set the size of a vector in the models. More interestingly, most of the remaining properties kill mutants rarely or never. This is another manifestation of a misalignment between the probabilistic specifications and general mutations; this time showing that probabilistic properties are unable to catch most standard programming errors.

Specific operators are more likely to yield “Fail” outcomes (Tbl. 6). They show the closest fault overlap with probabilistic properties. The NumberReplacer operator is by far the most likely to cause an assertion fail, with 133 detected failures. Admittedly though, this is the operator most frequently applied by Cosmic Ray in our experiments (1526 times), and its effectiveness in detecting failures is unsuprising, as many errors in probabilistic models arise from selecting incorrect parameter values (e.g., mean or standard deviation in prior distributions). These hints that mutations that affect parameter values can be useful for mutation testing of probabilistic properties.

Our answer to RQ3 is negative. As most of the 161 mutation operators result in runtime errors, most of the surviving mutants do not affect inferred distributions, and most of the properties never fail a mutant, we conclude that there is a significant misalignment between general programming and probabilistic programming fault models.

External Validity / Transferability

Our property collection comes from a single source, but SR is one of the most widely used comprehensive textbooks on Bayesian data analysis, covering a large variety of probabilistic models and properties. We use 59 models from three sources, a number that is substantial given the manual refactoring and test implementation effort, but cannot represent all models in the ecosystem. Other models and properties could show different challenges in automation, with different flakiness and mutation behavior. More important than completeness in this respect are the research process and the insights obtained: what kinds of properties can be found by studying literature, whether they are testable (RQ1), whether they tend to be flaky (RQ2), whether they track known or new faults (RQ3).

The mutation experiments in Sect. 3.3 rely on a single tool, Cosmic Ray. Its mutation operators are representative of core operator categories used in many tools, but we have not verified whether other tools and languages would give the same results.

We used targeted search (Sect. 3) rather than comprehensive pairing, so the tested property–model pairs reflect our judgment about which properties pertain to which models. The flakiness and mutation rates in RQ2 and RQ3 therefore describe this collection rather than estimating rates over the space of all plausible pairs. We note, though, that pairs were fixed before any tests were run, so the selection could not be influenced by flakiness or mutation outcomes.

Correctness Properties for Probabilistic Programs

Formal methods research provides a host of specification languages, also for probabilistic systems. Specification languages used in statistical model checking, such as probabilistic process algebra and probabilistic temporal logics cannot express the quantitative properties of interest in data analysis, where we handle complex multivariate continuous and discrete distributions with many data observations. They have been designed for specification of probabilistic properties of stateful control systems, not data analytics. In contrast, our properties target data analysis models directly, so models that are multivariate and mix continuous and discrete dimensions following many classes of distributions.

Grunske catalogued probabilistic properties as patterns in the sense of Dwyer et al.. He assembled ProProST, a dataset of temporal properties of stateful probabilistic models (CTMCs, DTMCs) and the corresponding temporal logics (CSL and PCTL) as seen embedded control systems, web applications, and network protocols. In contrast, we collect the requirements from a text (SR) that encodes years of established practice and hundreds of research papers in data modeling and analysis. In particular, our properties cannot be represented using ProProST’s patterns, as the data analysis models and their properties differ wildly from those in probabilistic control.

The PosteriorDB project collects probabilistic data analysis models, which we use extensively in Sect. 3. It was created to support development of quality diagnostics for statistical models, including testing implementations of Bayesian inference algorithms against each other. However, PosteriorDB itself does not contain any correctness properties, tests, or specifications beyond reference posteriors (which are oracles for inference algorithms, not for models). Our collection thus complements theirs by specifying properties that the models themselves should satisfy.

Flakiness

Flakiness often stems from concurrency and inter-test dependencies, but flakiness induced by randomization is increasingly reported. For example, about 60% of flaky tests in inference engines are caused by algorithmic non-determinism. Several tools and studies already consider identifying flakiness in probabilistic programs and reducing it. These works take the departure in a collection of flaky tests, whereas we begin more broadly, with specification properties, and then learn that only few of the specifications are flaky. For example, Dutta and coauthors study flakiness in probabilistic programs, mostly deep-learning-based, using Pyro, PyMC, TensorFlow probability, and PyTorch through the lens of 75 historical (practically) flaky tests. Their conclusions are in agreement with ours: the most common cause for flaky tests is randomness in the considered systems. They present FLASH, a tool for detection of flakiness. Unfortunately, the tool, developed with PyMC3, is not maintained, and it no longer works with PyMC (we use v5), so we could not evaluate whether it is effective against our properties. Our work differs by having different objectives: we are interested in systematizing knowledge about correctness and testing, in order to work around the oracle problem, while we see flakiness as a relevant dimension of interest. Furthermore, our subject systems are primarily analytical scientific models, not deep learning systems.

Conclusion

Our goal was to explore the use of modeling guidelines found in Bayesian data analysis literature for automated model testing. We demonstrate how to effectively elicit and automate correctness properties for probabilistic data analysis models. Our collection contains 17 broadly applicable probabilistic properties, designed and implemented in Python and evaluated on 59 realistic models from three repositories. We show that probabilistic tests, if setup as robust statistical procedures, do not need to be flaky; albeit achieving non-flakiness for more complex posteriors is challenging (four PosteriorDB cases). We believe that we are the first to evaluate the effectiveness of mutation operators designed for regular coding tasks to assess specifications of probabilistic models. We point out deficiencies of standard mutation testing methods when applied in this field. The fault models of standard mutation operators and the identified properties are not compatible. Most mutation operators introduce runtime errors that prevent tests from evaluating the assertions that capture the properties. Moreover, many operators alter the probabilistic model insignificantly, so they do not interact with probabilistic properties. This calls for the definition of new mutation operators for this domain, and a suggestion to consider operators that affect parameter values.

In the future, we intend to exploit the results of this domain analysis to create a property language for a testing tool for probabilistic models. Furthermore, we are working on an adequate mutation testing methodology for probabilistic models.