Interactive version:

# Parametric Models¶

## Instantiating parametric models¶

01-parametric-models.py

Input formats such as prism allow to specify programs with open constants. We refer to these open constants as parameters. If the constants only influence the probabilities or rates, but not the topology of the underlying model, we can build these models as parametric models:

:

>>> import stormpy
>>> import stormpy.examples
>>> import stormpy.examples.files
>>> path = stormpy.examples.files.prism_pdtmc_die
>>> prism_program = stormpy.parse_prism_program(path)
>>> formula_str = "P=? [F s=7 & d=2]"
>>> properties = stormpy.parse_properties(formula_str, prism_program)
>>> model = stormpy.build_parametric_model(prism_program, properties)
>>> parameters = model.collect_probability_parameters()
>>> for x in parameters:
...     print(x)

p
q


In order to obtain a standard DTMC, MDP or other Markov model, we need to instantiate these models by means of a model instantiator:

:

>>> import stormpy.pars
>>> instantiator = stormpy.pars.PDtmcInstantiator(model)


Before we obtain an instantiated model, we need to map parameters to values: We build such a dictionary as follows:

:

>>> point = dict()
>>> for x in parameters:
...    print(x.name)
...    point[x] = stormpy.RationalRF(0.4)
>>> instantiated_model = instantiator.instantiate(point)
>>> result = stormpy.model_checking(instantiated_model, properties)

p
q


Initial states and labels are set as for the parameter-free case.

## Checking parametric models¶

02-parametric-models.py

It is also possible to check the parametric model directly, similar as before in Checking properties:

:

>>> result = stormpy.model_checking(model, properties)
>>> initial_state = model.initial_states
>>> func = result.at(initial_state)


We collect the constraints ensuring that underlying model is well-formed and the graph structure does not change:

:

>>> import stormpy.info
>>> if stormpy.info.storm_ratfunc_use_cln():
...     import pycarl.cln.formula
>>> else:
...     import pycarl.gmp.formula
>>> collector = stormpy.ConstraintCollector(model)
>>> for formula in collector.wellformed_constraints:
...     print(formula)
>>> for formula in collector.graph_preserving_constraints:
...     print(formula)

(<= (+ p (- 1)) 0)
(<= (+ q (- 1)) 0)
(<= (* (- 1) p) 0)
(<= (* (- 1) q) 0)
(!= (+ q (- 1)) 0)
(!= q 0)
(!= (+ p (- 1)) 0)
(!= p 0)


## Collecting information about the parametric models¶

03-parametric-models.py

This example shows three implementations to obtain the number of transitions with probability one in a parametric model.
{"ft_lang_label":"__label__en","ft_lang_prob":0.6407906,"math_prob":0.9882073,"size":2470,"snap":"2023-14-2023-23","text_gpt3_token_len":608,"char_repetition_ratio":0.16666667,"word_repetition_ratio":0.029940119,"special_character_ratio":0.28097165,"punctuation_ratio":0.21411192,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9938227,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-06-07T18:34:12Z\",\"WARC-Record-ID\":\"<urn:uuid:42745753-5c7a-47be-8071-6a5ea4d49e96>\",\"Content-Length\":\"134688\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:602e12bc-0fe9-4056-947d-9a4483cc03fd>\",\"WARC-Concurrent-To\":\"<urn:uuid:1f456011-323f-4cd0-9442-02fe292fabe4>\",\"WARC-IP-Address\":\"185.199.111.153\",\"WARC-Target-URI\":\"https://moves-rwth.github.io/stormpy/doc/parametric_models.html\",\"WARC-Payload-Digest\":\"sha1:TNX2HSCYINY2LA2Q7NLV7RQDJUSIGJGH\",\"WARC-Block-Digest\":\"sha1:EUMBNTDY5RRG4EQKDNJDOXWELFDFRZ3R\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-23/CC-MAIN-2023-23_segments_1685224654012.67_warc_CC-MAIN-20230607175304-20230607205304-00076.warc.gz\"}"}