예제 #1
0
 def test_symmetries(self):
     dft = stormpy.dft.load_dft_galileo_file(
         get_example_path("dft", "rc.dft"))
     symmetries = dft.symmetries()
     assert len(symmetries.groups) == 1
     for index, group in symmetries.groups.items():
         assert len(group) == 3
         i = 4
         for syms in group:
             assert len(syms) == 2
             for elem in syms:
                 assert elem == i or elem == i + 3
             i += 1
예제 #2
0
 def test_parametric_model_checking_dd(self):
     program = stormpy.parse_prism_program(
         get_example_path("pdtmc", "parametric_die.pm"))
     prop = "P=? [F s=5]"
     formulas = stormpy.parse_properties_for_prism_program(prop, program)
     model = stormpy.build_symbolic_parametric_model(program, formulas)
     assert model.nr_states == 11
     assert model.nr_transitions == 17
     assert model.model_type == stormpy.ModelType.DTMC
     assert model.has_parameters
     result = stormpy.check_model_dd(model, formulas[0])
     assert type(
         result) is stormpy.SymbolicParametricQuantitativeCheckResult
예제 #3
0
 def test_build_instantiated_dtmc(self):
     jani_model, properties = stormpy.parse_jani_model(get_example_path("dtmc", "brp.jani"))
     assert jani_model.has_undefined_constants
     assert not jani_model.undefined_constants_are_graph_preserving
     description = stormpy.SymbolicModelDescription(jani_model)
     constant_definitions = description.parse_constant_definitions("N=16, MAX=2")
     instantiated_jani_model = description.instantiate_constants(constant_definitions).as_jani_model()
     model = stormpy.build_model(instantiated_jani_model)
     assert model.nr_states == 677
     assert model.nr_transitions == 867
     assert model.model_type == stormpy.ModelType.DTMC
     assert not model.supports_parameters
     assert type(model) is stormpy.SparseDtmc
예제 #4
0
 def test_derivatives(self):
     program = stormpy.parse_prism_program(get_example_path("pdtmc", "brp16_2.pm"))
     prop = "P<=0.84 [F s=5 ]"
     formulas = stormpy.parse_properties_for_prism_program(prop, program)
     model = stormpy.build_parametric_model(program, formulas)
     assert model.nr_states == 613
     assert model.nr_transitions == 803
     assert model.model_type == stormpy.ModelType.DTMC
     assert model.has_parameters
     parameters = model.collect_probability_parameters()
     assert len(parameters) == 2
     derivatives = stormpy.pars.gather_derivatives(model, list(parameters)[0])
     assert len(derivatives) == 0
예제 #5
0
 def test_parametric_dft(self):
     import pycarl
     pycarl.clear_pools()
     dft = stormpy.dft.load_parametric_dft_galileo_file(
         get_example_path("dft", "symmetry_param.dft"))
     assert dft.nr_elements() == 7
     assert dft.nr_be() == 4
     assert dft.nr_dynamic() == 0
     assert type(dft) is stormpy.dft.DFT_ratfunc
     parameters = stormpy.dft.get_parameters(dft)
     param_names = [x.name for x in parameters]
     assert "x" in param_names
     assert "y" in param_names
예제 #6
0
 def test_upload_files(self):
     print("Check if uploading files to the server works correctly...",
           flush=True)
     with open(get_example_path("brp", "brp_16-2.pm"), 'r') as pfile:
         prismdata = pfile.read()
     with open(get_example_path("brp", "property1.pctl"), 'r') as pfile:
         pctldata = pfile.read()
     with open(get_example_path("brp", "brp_16-2.rat"), 'r') as pfile:
         result_data = pfile.read()
     prismfile = ('prism-file', 'brp_16-2.pm', prismdata)
     pctlfile = ('pctl-file', 'property1.pctl', pctldata)
     result_file = ('result-file', 'brp_16-2.rat', result_data)
     ct, data = self.encode_multipart_formdata([], [prismfile])
     response = self._sendData('/uploadPrism', data=data, ct=ct)
     assert response.code == 200
     ct, data = self.encode_multipart_formdata([], [pctlfile])
     response = self._sendData('/uploadPctl', data=data, ct=ct)
     assert response.code == 200
     ct, data = self.encode_multipart_formdata([("result-type", "storm")],
                                               [result_file])
     response = self._sendData('/uploadResult', data=data, ct=ct)
     assert response.code == 200
     print("DONE")
예제 #7
0
 def test_model_checking_dtmc_all_labels(self):
     program = stormpy.parse_prism_program(get_example_path("dtmc", "die.pm"))
     formulas = stormpy.parse_properties_for_prism_program("P=? [ F \"one\" ]", program)
     model = stormpy.build_model(program)
     assert model.nr_states == 13
     assert model.nr_transitions == 20
     assert len(model.initial_states) == 1
     initial_state = model.initial_states[0]
     assert initial_state == 0
     result = stormpy.model_checking(model, formulas[0])
     assert math.isclose(result.at(initial_state), 1 / 6)
     formulas = stormpy.parse_properties_for_prism_program("P=? [ F \"two\" ]", program)
     result = stormpy.model_checking(model, formulas[0])
     assert math.isclose(result.at(initial_state), 1 / 6)
예제 #8
0
 def test_model_checking_prism_dd_dtmc(self):
     program = stormpy.parse_prism_program(
         get_example_path("dtmc", "die.pm"))
     formulas = stormpy.parse_properties_for_prism_program(
         "P=? [ F \"one\" ]", program)
     model = stormpy.build_symbolic_model(program, formulas)
     assert model.nr_states == 13
     assert model.nr_transitions == 20
     result = stormpy.check_model_dd(model, formulas[0])
     assert type(result) is stormpy.SymbolicQuantitativeCheckResult
     filter = stormpy.create_filter_initial_states_symbolic(model)
     result.filter(filter)
     assert result.min == result.max
     assert math.isclose(result.min, 1 / 6, rel_tol=1e-6)
예제 #9
0
 def test_model_checking_only_initial(self):
     program = stormpy.parse_prism_program(
         get_example_path("dtmc", "die.pm"))
     formulas = stormpy.parse_properties_for_prism_program(
         "Pmax=? [F{\"coin_flips\"}<=3 \"one\"]", program)
     model = stormpy.build_model(program, formulas)
     assert len(model.initial_states) == 1
     initial_state = model.initial_states[0]
     assert initial_state == 0
     result = stormpy.model_checking(model,
                                     formulas[0],
                                     only_initial_states=True)
     assert not result.result_for_all_states
     assert math.isclose(result.at(initial_state), 1 / 8)
예제 #10
0
 def test_build_dtmc_from_prism_program_reward_formulas(self):
     program = stormpy.parse_prism_program(get_example_path("dtmc", "die.pm"))
     prop = "R=? [F \"done\"]"
     properties = stormpy.parse_properties_for_prism_program(prop, program, None)
     model = stormpy.build_symbolic_model(program, properties)
     assert model.nr_states == 13
     assert model.nr_transitions == 20
     assert model.model_type == stormpy.ModelType.DTMC
     assert len(model.reward_models) == 1
     assert not model.reward_models["coin_flips"].has_state_rewards
     assert model.reward_models["coin_flips"].has_state_action_rewards
     assert not model.reward_models["coin_flips"].has_transition_rewards
     assert not model.supports_parameters
     assert type(model) is stormpy.SymbolicSylvanDtmc
예제 #11
0
 def test_relevant_events_additional(self):
     dft = stormpy.dft.load_dft_json_file(
         get_example_path("dft", "and.json"))
     properties = stormpy.parse_properties("P=? [ F<=1 \"failed\" ]")
     formulas = [p.raw_formula for p in properties]
     relevant_events = stormpy.dft.compute_relevant_events(
         dft, formulas, ["B", "C"])
     assert relevant_events.is_relevant("B")
     assert relevant_events.is_relevant("C")
     assert not relevant_events.is_relevant("A")
     results = stormpy.dft.analyze_dft(dft,
                                       formulas,
                                       relevant_events=relevant_events)
     assert math.isclose(results[0], 0.1548181217)
예제 #12
0
 def test_transformation(self):
     dft = stormpy.dft.load_dft_galileo_file(
         get_example_path("dft", "rc2.dft"))
     valid, output = stormpy.dft.is_well_formed(dft)
     assert not valid
     assert "not binary" in output
     dft = stormpy.dft.transform_dft(dft,
                                     unique_constant_be=True,
                                     binary_fdeps=True)
     valid, output = stormpy.dft.is_well_formed(dft)
     assert valid
     formulas = stormpy.parse_properties("Tmin=? [ F \"failed\" ]")
     results = stormpy.dft.analyze_dft(dft, [formulas[0].raw_formula])
     assert math.isclose(results[0], 6.380930905)
예제 #13
0
 def test_transform_symbolic_parametric_dtmc_to_sparse(self):
     program = stormpy.parse_prism_program(
         get_example_path("pdtmc", "parametric_die.pm"))
     model = stormpy.build_symbolic_parametric_model(program)
     assert model.nr_states == 13
     assert model.nr_transitions == 20
     assert model.model_type == stormpy.ModelType.DTMC
     assert model.supports_parameters
     assert type(model) is stormpy.SymbolicSylvanParametricDtmc
     symbolic_model = stormpy.transform_to_sparse_model(model)
     assert symbolic_model.nr_states == 13
     assert symbolic_model.nr_transitions == 20
     assert symbolic_model.model_type == stormpy.ModelType.DTMC
     assert symbolic_model.supports_parameters
     assert type(symbolic_model) is stormpy.SparseParametricDtmc
예제 #14
0
 def test_label(self):
     program = stormpy.parse_prism_program(
         get_example_path("dtmc", "die.pm"))
     formulas = stormpy.parse_properties_for_prism_program(
         "P=? [ F \"one\" ]", program)
     model = stormpy.build_model(program, formulas)
     labeling = model.labeling
     labels = labeling.get_labels()
     assert len(labels) == 3
     assert "init" in labels
     assert "one" in labels
     assert "init" in model.labels_state(0)
     assert "init" in labeling.get_labels_of_state(0)
     assert "one" in model.labels_state(7)
     assert "one" in labeling.get_labels_of_state(7)
예제 #15
0
 def test_build_ctmc(self):
     program = stormpy.parse_prism_program(get_example_path("ctmc", "polling2.sm"), True)
     formulas = stormpy.parse_properties_for_prism_program("P=? [ F<=3 \"target\" ]", program)
     model = stormpy.build_model(program)
     assert model.nr_states == 12
     assert model.nr_transitions == 22
     assert model.model_type == stormpy.ModelType.CTMC
     assert not model.supports_parameters
     assert type(model) is stormpy.SparseCtmc
     model_for_formula = stormpy.build_model(program, formulas)
     assert model_for_formula.nr_states == 12
     assert model_for_formula.nr_transitions == 21
     assert model_for_formula.model_type == stormpy.ModelType.CTMC
     assert not model_for_formula.supports_parameters
     assert type(model_for_formula) is stormpy.SparseCtmc
예제 #16
0
 def test_model_checking_jani_dtmc(self):
     jani_model, properties = stormpy.parse_jani_model(get_example_path("dtmc", "die.jani"))
     formulas = [properties["Probability to throw a six"], properties["Expected number of coin flips"]]
     formulas = stormpy.eliminate_reward_accumulations(jani_model, formulas)
     assert len(formulas) == 2
     model = stormpy.build_model(jani_model, formulas)
     assert model.nr_states == 13
     assert model.nr_transitions == 20
     assert len(model.initial_states) == 1
     initial_state = model.initial_states[0]
     assert initial_state == 0
     result = stormpy.model_checking(model, formulas[0])
     assert math.isclose(result.at(initial_state), 1 / 6)
     result = stormpy.model_checking(model, formulas[1])
     assert math.isclose(result.at(initial_state), 11 / 3)
예제 #17
0
 def test_parametric_model_checking_sparse(self):
     program = stormpy.parse_prism_program(get_example_path("pdtmc", "brp16_2.pm"))
     prop = "P=? [F s=5]"
     formulas = stormpy.parse_properties_for_prism_program(prop, program)
     model = stormpy.build_parametric_model(program, formulas)
     assert model.nr_states == 613
     assert model.nr_transitions == 803
     assert model.model_type == stormpy.ModelType.DTMC
     assert model.has_parameters
     initial_state = model.initial_states[0]
     assert initial_state == 0
     result = stormpy.model_checking(model, formulas[0])
     func = result.at(initial_state)
     one = stormpy.FactorizedPolynomial(stormpy.RationalRF(1))
     assert func.denominator == one
예제 #18
0
    def test_convert_ma_to_ctmc(self):
        program = stormpy.parse_prism_program(get_example_path("ma", "ctmc.ma"), True)
        formulas = stormpy.parse_properties_for_prism_program("P=? [ F<=3 s=2 ]", program)
        model = stormpy.build_model(program, formulas)
        assert model.nr_states == 4
        assert model.nr_transitions == 6
        assert model.model_type == stormpy.ModelType.MA
        assert type(model) is stormpy.SparseMA

        assert model.convertible_to_ctmc
        ctmc = model.convert_to_ctmc()
        assert ctmc.nr_states == 4
        assert ctmc.nr_transitions == 6
        assert ctmc.model_type == stormpy.ModelType.CTMC
        assert type(ctmc) is stormpy.SparseCtmc
예제 #19
0
 def test_filter(self):
     program = stormpy.parse_prism_program(get_example_path("dtmc", "die.pm"))
     formulas = stormpy.parse_properties_for_prism_program("P=? [ F \"one\" ]", program)
     model = stormpy.build_model(program, formulas)
     assert model.nr_states == 13
     assert model.nr_transitions == 20
     assert len(model.initial_states) == 1
     initial_state = model.initial_states[0]
     assert initial_state == 0
     result = stormpy.model_checking(model, formulas[0])
     assert math.isclose(result.at(initial_state), 1 / 6)
     filter = stormpy.create_filter_initial_states_sparse(model)
     result.filter(filter)
     assert result.min == result.max
     assert math.isclose(result.min, 1 / 6)
예제 #20
0
 def test_model_checking_jani_dtmc(self):
     jani_model, formulas = stormpy.parse_jani_model(
         get_example_path("dtmc", "die.jani"))
     formulas = stormpy.eliminate_reward_accumulations(jani_model, formulas)
     assert len(formulas) == 2
     model = stormpy.build_model(jani_model, formulas)
     assert model.nr_states == 13
     assert model.nr_transitions == 20
     assert len(model.initial_states) == 1
     initial_state = model.initial_states[0]
     assert initial_state == 0
     result = stormpy.model_checking(model, formulas[0])
     assert math.isclose(result.at(initial_state), 1 / 6)
     result = stormpy.model_checking(model, formulas[1])
     assert math.isclose(result.at(initial_state), 11 / 3)
예제 #21
0
 def test_symbolic_bisimulation(self):
     program = stormpy.parse_prism_program(
         get_example_path("dtmc", "crowds5_5.pm"))
     prop = "P=? [F \"observe0Greater1\"]"
     properties = stormpy.parse_properties_for_prism_program(prop, program)
     model = stormpy.build_symbolic_model(program, properties)
     assert model.nr_states == 7403
     assert model.nr_transitions == 13041
     assert model.model_type == stormpy.ModelType.DTMC
     assert not model.supports_parameters
     model_bisim = stormpy.perform_symbolic_bisimulation(model, properties)
     assert model_bisim.nr_states == 65
     assert model_bisim.nr_transitions == 105
     assert model_bisim.model_type == stormpy.ModelType.DTMC
     assert not model_bisim.supports_parameters
예제 #22
0
 def test_build_parametric_dtmc_preprocess(self):
     program = stormpy.parse_prism_program(
         get_example_path("pdtmc", "herman5.pm"))
     formulas = stormpy.parse_properties_for_prism_program(
         "R=? [ F \"stable\" ]", program)
     trans_program, trans_formulas = stormpy.preprocess_symbolic_input(
         program, formulas, "")
     trans_prism = trans_program.as_prism_program()
     model = stormpy.build_parametric_model(trans_prism, trans_formulas)
     assert model.nr_states == 33
     assert model.nr_transitions == 266
     assert model.model_type == stormpy.ModelType.DTMC
     assert model.supports_parameters
     assert model.has_parameters
     assert type(model) is stormpy.SparseParametricDtmc
예제 #23
0
 def test_transform_symbolic_dtmc_to_sparse(self):
     program = stormpy.parse_prism_program(
         get_example_path("dtmc", "crowds5_5.pm"))
     symbolic_model = stormpy.build_symbolic_model(program)
     assert symbolic_model.nr_states == 8607
     assert symbolic_model.nr_transitions == 15113
     assert symbolic_model.model_type == stormpy.ModelType.DTMC
     assert not symbolic_model.supports_parameters
     assert type(symbolic_model) is stormpy.SymbolicSylvanDtmc
     sparse_model = stormpy.transform_to_sparse_model(symbolic_model)
     assert sparse_model.nr_states == 8607
     assert sparse_model.nr_transitions == 15113
     assert sparse_model.model_type == stormpy.ModelType.DTMC
     assert not sparse_model.supports_parameters
     assert type(sparse_model) is stormpy.SparseDtmc
예제 #24
0
 def test_label(self):
     program = stormpy.parse_prism_program(
         get_example_path("dtmc", "brp-16-2.pm"))
     properties = stormpy.parse_properties_for_prism_program(
         "P=? [ F s=5 ]", program)
     options = stormpy.BuilderOptions([p.raw_formula for p in properties])
     options.set_build_choice_labels(True)
     model = stormpy.build_sparse_model_with_options(program, options)
     clabeling = model.choice_labeling
     clabels = clabeling.get_labels()
     assert len(clabels) == 7
     assert "aB" in clabels
     assert "aA" in clabels
     assert "NewFile" in clabeling.get_labels_of_choice(0)
     assert "aG" in clabeling.get_labels_of_choice(7)
예제 #25
0
 def test_symbolic_parametric_bisimulation(self):
     program = stormpy.parse_prism_program(
         get_example_path("pdtmc", "brp16_2.pm"))
     prop = "P=? [F \"error\"]"
     properties = stormpy.parse_properties_for_prism_program(prop, program)
     model = stormpy.build_symbolic_parametric_model(program, properties)
     assert model.nr_states == 613
     assert model.nr_transitions == 803
     assert model.model_type == stormpy.ModelType.DTMC
     assert model.has_parameters
     model_bisim = stormpy.perform_symbolic_bisimulation(model, properties)
     assert model_bisim.nr_states == 326
     assert model_bisim.nr_transitions == 454
     assert model_bisim.model_type == stormpy.ModelType.DTMC
     assert model_bisim.has_parameters
예제 #26
0
 def test_simulate_trace(self):
     dft = stormpy.dft.load_dft_json_file(
         get_example_path("dft", "and.json"))
     symmetries = dft.symmetries()
     relevant_events = stormpy.dft.compute_relevant_events(dft, [])
     dft.set_relevant_events(relevant_events, False)
     info = dft.state_generation_info(symmetries)
     generator = stormpy.dft.RandomGenerator.create(5)
     simulator = stormpy.dft.DFTSimulator_double(dft, info, generator)
     res = simulator.simulate_trace(2)
     assert res == stormpy.dft.SimulationResult.SUCCESSFUL
     res = simulator.simulate_trace(2)
     assert res == stormpy.dft.SimulationResult.UNSUCCESSFUL
     res = simulator.simulate_trace(2)
     assert res == stormpy.dft.SimulationResult.UNSUCCESSFUL
예제 #27
0
 def test_label_parametric(self):
     program = stormpy.parse_prism_program(
         get_example_path("pdtmc", "brp16_2.pm"))
     formulas = stormpy.parse_properties_for_prism_program(
         "P=? [ F s=5 ]", program)
     model = stormpy.build_parametric_model(program, formulas)
     labels = model.labeling.get_labels()
     assert len(labels) == 3
     assert "init" in labels
     assert "(s = 5)" in labels
     assert "init" in model.labels_state(0)
     assert "(s = 5)" in model.labels_state(28)
     assert "(s = 5)" in model.labels_state(611)
     initial_states = model.initial_states
     assert len(initial_states) == 1
     assert 0 in initial_states
예제 #28
0
 def test_parametric_transitions(self):
     program = stormpy.parse_prism_program(
         get_example_path("pmdp", "two_dice.nm"))
     model = stormpy.build_parametric_model(program)
     assert model.states[1].id == 1
     one = stormpy.FactorizedPolynomial(stormpy.RationalRF(1))
     i = 0
     for state in model.states:
         assert state.id == i
         i += 1
         j = 0
         for action in state.actions:
             assert j == 0 or j == 1
             j += 1
             for transition in action.transitions:
                 assert transition.value().denominator == one
예제 #29
0
 def test_set_labeling(self):
     program = stormpy.parse_prism_program(
         get_example_path("dtmc", "die.pm"))
     model = stormpy.build_model(program)
     labeling = model.labeling
     assert "tmp" not in labeling.get_labels()
     assert not labeling.contains_label("tmp")
     labeling.add_label("tmp")
     assert labeling.contains_label("tmp")
     labeling.add_label_to_state("tmp", 0)
     assert labeling.has_state_label("tmp", 0)
     states = labeling.get_states("tmp")
     assert states.get(0)
     states.set(3)
     labeling.set_states("tmp", states)
     assert labeling.has_state_label("tmp", 3)
예제 #30
0
 def test_pla_manual(self):
     program = stormpy.parse_prism_program(
         get_example_path("pdtmc", "brp16_2.pm"))
     prop = "P=? [F s=5 ]"
     formulas = stormpy.parse_properties_for_prism_program(prop, program)
     model = stormpy.build_parametric_model(program, formulas)
     assert model.has_parameters
     env = stormpy.Environment()
     checker = stormpy.pars.DtmcParameterLiftingModelChecker()
     checker.specify(env, model, formulas[0].raw_formula)
     parameters = model.collect_probability_parameters()
     assert len(parameters) == 2
     region = stormpy.pars.ParameterRegion.create_from_string(
         "0.7<=pL<=0.9,0.75<=pK<=0.95", parameters)
     result = checker.get_bound(env, region, True)
     assert math.isclose(float(result.constant_part()),
                         0.8369631383670559,
                         rel_tol=1e-6)