Skip to content

Simulator: fix evaluation of "deadlock"/"init" labels in property formulas#282

Merged
davexparker merged 4 commits into
masterfrom
feat/smc-deadlock-init
May 28, 2026
Merged

Simulator: fix evaluation of "deadlock"/"init" labels in property formulas#282
davexparker merged 4 commits into
masterfrom
feat/smc-deadlock-init

Conversation

@davexparker
Copy link
Copy Markdown
Member

@davexparker davexparker commented May 26, 2026

Summary

The statistical model checking (simulation) engine crashed when properties referenced the built-in "deadlock" or "init" labels (e.g. P=?[F "deadlock"]), because ExpressionLabel.evaluate() always threw "Cannot evaluate labels". Unlike user-defined labels, these two are never expanded to a Boolean state formula by expandPropRefsAndLabels"deadlock" depends on available transitions and "init" on the initial state, neither of which is a function of state variables alone.

  • Add a getLabelValue(String) hook to EvaluateContext (returns null by default = unsupported). ExpressionLabel.evaluate() now calls this hook first and only throws if it returns null.
  • Add Path.evaluateBooleanInCurrentState(Expression, ModelGenerator), which provides a label-aware context: "deadlock" delegates to ModelGenerator.isDeadlock(), "init" to a new ModelGenerator.isInitialState() helper, and other labels to ModelGenerator.isLabelTrue(). Compound expressions like "deadlock" & s=7 work correctly since the context is applied recursively by the expression evaluator.
  • Update all samplers (SamplerUntil, SamplerBoundedUntilDisc, SamplerBoundedUntilCont, SamplerNext) to use this overload.
  • Also fix bounded-until deadlock handling: when a deadlock is found before the lower time bound, the formula's satisfaction can be determined
  • When fixDeadlocks is off, report the deadlock state and throw an error (matching the behaviour of the non-simulation engines).

Test plan

  • ./bin/prism dice-deadlock.prism -pf 'P=?[F "deadlock"]' -sim — previously crashed; now returns 1.0
  • ./bin/prism dice-deadlock.prism -pf 'P=?[F "deadlock"]' -ex — cross-check against explicit engine (also 1.0)
  • New regression tests in prism-tests/bugfixes/sim-deadlock-label.* and prism-tests/functionality/verify/sim/sim-deadlock-*.* pass on both -sim and -ex
  • Existing sim regression tests (chain.prism, samplerboundeduntildisc.pm, sim-ctmc-until-false.prism) unaffected
  • make unittests — all 25 480 tests pass

🤖 Generated with Claude Code

The statistical model checking engine did not support the built-in
"deadlock" label (e.g. P=?[F "deadlock"]), because it cannot be treated
in the same way as user-defined labels, where these are replaced
with their (Expression) definitions before simulation.

The solution is in two parts:
(i) Add getLabelValue(String) to EvaluateContext (returning null by
default, meaning unsupported), used in ExpressionLabel.evaluate().
(ii) Path.evaluateBooleanInCurrentState can now also take a
ModelGenerator allowing it to reason about transitions in the
current state (notably using modelGen.isDeadlock()).
Re-using mechanism just added to support "deadlock", allow
the statistical model checking engine to check "init".

Only supports models with a single initial state for now
(as does the simulator). Not super efficient, but ok for now.
There were some errors in path evaluation for time-bounded properties.
@davexparker davexparker requested a review from Copilot May 26, 2026 10:54
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@davexparker davexparker merged commit 6dc8c08 into master May 28, 2026
1 check failed
@davexparker davexparker deleted the feat/smc-deadlock-init branch May 28, 2026 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants