def test_parameters(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) model_parameters = model.collect_probability_parameters() reward_parameters = model.collect_reward_parameters() all_parameters = model.collect_all_parameters() assert len(model_parameters) == 2 assert len(reward_parameters) == 0 assert len(all_parameters) == 2 program_reward = stormpy.parse_prism_program( get_example_path("pdtmc", "brp_rewards16_2.pm")) formulas_reward = stormpy.parse_properties_for_prism_program( "Rmin=? [ F \"target\" ]", program_reward) model = stormpy.build_parametric_model(program_reward, formulas_reward) model_parameters = model.collect_probability_parameters() reward_parameters = model.collect_reward_parameters() all_parameters = model.collect_all_parameters() assert len(model_parameters) == 2 assert len(reward_parameters) == 2 assert len(all_parameters) == 4 model = stormpy.build_symbolic_parametric_model(program, formulas) assert len(model.get_parameters()) == 4 model = stormpy.build_symbolic_parametric_model( program_reward, formulas_reward) assert len(model.get_parameters()) == 4
def example_schedulers_02(): path = stormpy.examples.files.prism_ma_simple formula_str = "Tmin=? [ F s=4 ]" program = stormpy.parse_prism_program(path, False, True) formulas = stormpy.parse_properties_for_prism_program(formula_str, program) ma = stormpy.build_model(program, formulas) assert ma.model_type == stormpy.ModelType.MA # Convert MA to MDP mdp, mdp_formulas = stormpy.transform_to_discrete_time_model(ma, formulas) assert mdp.model_type == stormpy.ModelType.MDP initial_state = mdp.initial_states[0] assert initial_state == 0 result = stormpy.model_checking(mdp, mdp_formulas[0], extract_scheduler=True) assert result.has_scheduler scheduler = result.scheduler print(scheduler) assert scheduler.memoryless assert scheduler.deterministic for state in mdp.states: choice = scheduler.get_choice(state) action = choice.get_deterministic_choice() print("In state {} choose action {}".format(state, action))
def test_initial_states(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) initial_states = model.initial_states assert len(initial_states) == 1 assert 0 in initial_states
def example_parametric_models_02(): # Check support for parameters if not config.storm_with_pars: print("Support parameters is missing. Try building storm-pars.") return import stormpy.pars from pycarl.formula import FormulaType, Relation if stormpy.info.storm_ratfunc_use_cln(): import pycarl.cln.formula else: import pycarl.gmp.formula 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_for_prism_program(formula_str, prism_program) model = stormpy.build_parametric_model(prism_program, properties) initial_state = model.initial_states[0] result = stormpy.model_checking(model, properties[0]) print("Result: {}".format(result.at(initial_state))) collector = stormpy.ConstraintCollector(model) print("Well formed constraints:") for formula in collector.wellformed_constraints: print(formula.get_constraint()) print("Graph preserving constraints:") for formula in collector.graph_preserving_constraints: print(formula.get_constraint())
def test_bisimulation(self): program = stormpy.parse_prism_program( get_example_path("dtmc", "crowds5_5.pm")) assert program.nr_modules == 1 assert program.model_type == stormpy.PrismModelType.DTMC prop = "P=? [F \"observe0Greater1\"]" properties = stormpy.parse_properties_for_prism_program(prop, program) model = stormpy.build_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 initial_state = model.initial_states[0] assert initial_state == 0 result = stormpy.model_checking(model, properties[0]) model_bisim = stormpy.perform_bisimulation( model, properties, stormpy.BisimulationType.STRONG) assert model_bisim.nr_states == 64 assert model_bisim.nr_transitions == 104 assert model_bisim.model_type == stormpy.ModelType.DTMC assert not model_bisim.supports_parameters result_bisim = stormpy.model_checking(model_bisim, properties[0]) initial_state_bisim = model_bisim.initial_states[0] assert initial_state_bisim == 34 assert math.isclose(result.at(initial_state), result_bisim.at(initial_state_bisim), rel_tol=1e-4)
def test_parametric_bisimulation(self): program = stormpy.parse_prism_program( get_example_path("pdtmc", "brp16_2.pm")) assert program.nr_modules == 5 assert program.model_type == stormpy.PrismModelType.DTMC assert program.has_undefined_constants assert program.undefined_constants_are_graph_preserving prop = "P=? [F s=5]" properties = stormpy.parse_properties_for_prism_program(prop, program) model = stormpy.build_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 initial_state = model.initial_states[0] assert initial_state == 0 result = stormpy.model_checking(model, properties[0]) ratFunc = result.at(initial_state) model_bisim = stormpy.perform_bisimulation( model, properties, stormpy.BisimulationType.STRONG) assert model_bisim.nr_states == 324 assert model_bisim.nr_transitions == 452 assert model_bisim.model_type == stormpy.ModelType.DTMC assert model_bisim.has_parameters result_bisim = stormpy.model_checking(model_bisim, properties[0]) initial_state_bisim = model_bisim.initial_states[0] assert initial_state_bisim == 316 ratFunc_bisim = result_bisim.at(initial_state_bisim) assert ratFunc == ratFunc_bisim
def example_getting_started_02(): path = stormpy.examples.files.prism_dtmc_die prism_program = stormpy.parse_prism_program(path) model = stormpy.build_model(prism_program) print("Number of states: {}".format(model.nr_states)) print("Number of transitions: {}".format(model.nr_transitions)) print("Labels in the model: {}".format(model.labeling.get_labels())) formula_str = "P=? [F s=2]" properties = stormpy.parse_properties_for_prism_program( formula_str, prism_program) model_for_formula = stormpy.build_model(prism_program, properties) print("Number of states: {}".format(model_for_formula.nr_states)) print("Number of transitions: {}".format(model_for_formula.nr_transitions)) print("Labels in the model: {}".format( model_for_formula.labeling.get_labels())) formula_str_2 = "P=? [F s=7 & d=2]" properties_2 = stormpy.parse_properties_for_prism_program( formula_str_2, prism_program) model_for_formula_2 = stormpy.build_model(prism_program, properties_2) print("Number of states: {}".format(model_for_formula_2.nr_states)) print("Number of transitions: {}".format( model_for_formula_2.nr_transitions)) print("Labels in the model: {}".format( model_for_formula_2.labeling.get_labels()))
def load_sketch_prism(cls, sketch_path): # read lines with open(sketch_path) as f: sketch_lines = f.readlines() # replace hole definitions with constants hole_re = re.compile(r'^hole\s+(.*?)\s+(.*?)\s+in\s+\{(.*?)\};$') sketch_output = [] hole_definitions = {} for line in sketch_lines: match = hole_re.search(line) if match is not None: hole_type = match.group(1) hole_name = match.group(2) hole_options = match.group(3).replace(" ", "") hole_definitions[hole_name] = hole_options line = f"const {hole_type} {hole_name};" sketch_output.append(line) # store modified sketch to a temporary file tmp_path = sketch_path + str(uuid.uuid4()) with open(tmp_path, 'w') as f: for line in sketch_output: print(line, end="", file=f) # try to parse temporary sketch and then delete it try: prism = stormpy.parse_prism_program(tmp_path, prism_compat=True) os.remove(tmp_path) except: os.remove(tmp_path) exit(1) return prism, hole_definitions
def load_sketch(cls, sketch_path): # read lines with open(sketch_path) as f: sketch_lines = f.readlines() # strip hole definitions hole_re = re.compile(r'^hole\s+(.*?)\s+(.*?)\s+in\s+\{(.*?)\};$') sketch_output = [] hole_definitions = OrderedDict() for line in sketch_lines: match = hole_re.search(line) if match is not None: hole_name = match.group(2) hole_definitions[hole_name] = match.group(3).replace(" ", "") line = f"const {match.group(1)} {hole_name};" sketch_output.append(line) # store stripped sketch to a temporary file tmp_path = sketch_path + str(uuid.uuid4()) with open(tmp_path, 'w') as f: for line in sketch_output: print(line, end="", file=f) # parse temporary sketch program = stormpy.parse_prism_program(tmp_path) # delete temporary sketch os.remove(tmp_path) return program, hole_definitions
def example_building_models_04(): path = stormpy.examples.files.prism_mdp_firewire prism_program = stormpy.parse_prism_program(path) prism_program = stormpy.preprocess_symbolic_input( prism_program, [], "delay=10,fast=0.8")[0].as_prism_program() options = stormpy.BuilderOptions() options.set_build_state_valuations() options.set_build_all_reward_models(True) options.set_build_choice_labels(True) def permissive_policy(state_valuation, action_index): """ Whether for the given state and action, the action should be allowed in the model. :param state_valuation: :param action_index: :return: True or False """ action_name = prism_program.get_action_name(action_index) print(f"{state_valuation.to_json()}, {action_name}") # conditions on the action cond1 = action_name.startswith("snd") # conditions on the state (efficient) cond2 = state_valuation.get_integer_value( prism_program.get_module("node2").get_integer_variable( "x2").expression_variable) < 20 # conditions on the json repr of the state (inefficient, string handling, etc) cond3 = json.loads(str(state_valuation.to_json()))["x1"] < 40 return (cond1 or (cond2 and cond3)) constructor = stormpy.make_sparse_model_builder( prism_program, options, stormpy.StateValuationFunctionActionMaskDouble(permissive_policy)) model = constructor.build() print(model)
def example_building_models_03(): path = stormpy.examples.files.prism_pdtmc_brp prism_program = stormpy.parse_prism_program(path) formula_str = "P=? [F s=5]" properties = stormpy.parse_properties_for_prism_program( formula_str, prism_program) options = stormpy.BuilderOptions([p.raw_formula for p in properties]) options.set_build_state_valuations() model = stormpy.build_sparse_parametric_model_with_options( prism_program, options) valuations = model.state_valuations values2 = json.loads(str(valuations.get_json(2))) print(values2) integer_variables = [] for module in prism_program.modules: print("module {}".format(module.name)) integer_variables += module.integer_variables print(", ".join([ "{}: {}".format( str(iv.name), valuations.get_integer_value(2, iv.expression_variable)) for iv in integer_variables ]))
def example_simulator_01(): path = stormpy.examples.files.prism_mdp_maze prism_program = stormpy.parse_prism_program(path) model = stormpy.build_model(prism_program) simulator = stormpy.simulator.create_simulator(model, seed=42) # 5 paths of at most 20 steps. paths = [] for m in range(5): path = [] state = simulator.restart() path = [f"{state}"] for n in range(20): actions = simulator.available_actions() select_action = random.randint(0,len(actions)-1) #print(f"Randomly select action nr: {select_action} from actions {actions}") path.append(f"--act={actions[select_action]}-->") state = simulator.step(actions[select_action]) #print(state) path.append(f"{state}") if simulator.is_done(): #print("Trapped!") break paths.append(path) for path in paths: print(" ".join(path))
def test_scheduler_ma_via_mdp(self): program = stormpy.parse_prism_program(get_example_path("ma", "simple.ma"), False, True) formulas = stormpy.parse_properties_for_prism_program("Tmin=? [ F s=4 ]", program) ma = stormpy.build_model(program, formulas) assert ma.nr_states == 5 assert ma.nr_transitions == 8 assert ma.model_type == stormpy.ModelType.MA # Convert MA to MDP mdp, mdp_formulas = stormpy.transform_to_discrete_time_model(ma, formulas) assert mdp.nr_states == 5 assert mdp.nr_transitions == 8 assert mdp.model_type == stormpy.ModelType.MDP assert len(mdp.initial_states) == 1 initial_state = mdp.initial_states[0] assert initial_state == 0 result = stormpy.model_checking(mdp, mdp_formulas[0], extract_scheduler=True) assert math.isclose(result.at(initial_state), 0.08333333333) assert result.has_scheduler scheduler = result.scheduler assert scheduler.memoryless assert scheduler.memory_size == 1 assert scheduler.deterministic for state in mdp.states: choice = scheduler.get_choice(state) assert choice.defined assert choice.deterministic action = choice.get_deterministic_choice() if state.id == 0: assert action == 1 else: assert action == 0
def model_checking(tulip_transys, formula, prism_file_path, extract_policy=False): """Model check tulip_transys against formula @type tulip_transys: either a MarkovChain or MarkovDecisionProcess object. @type formula: a string describing PCTL formula according to Prism format. @type prism_file_path: a string indicating the path to export the intermediate prism file (mostly for debugging purpose) @type extract_policy: boolean that indicates whether to extract policy @return result * If extract_policy = False, then for each state in model.states, result[state] is the probability of satisfying the formula starting at state. * If extract_policy = True, then result = (prob,policy) where for each state in model.states, prob[state] is the probability of satisfying the formula starting at state and policy[state] is the action to be applied at state. """ assert type(tulip_transys) == MDP or type(tulip_transys) == MC to_prism_file(tulip_transys, prism_file_path) prism_program = stormpy.parse_prism_program(prism_file_path) stormpy_model = stormpy.build_model(prism_program) properties = stormpy.parse_properties(formula, prism_program) result = stormpy.model_checking( stormpy_model, properties[0], extract_scheduler=extract_policy ) prob = _extract_probability(result, stormpy_model, tulip_transys) if not extract_policy: return prob policy = _extract_policy(result, stormpy_model, tulip_transys) return (prob, policy)
def test_explicit_builder(self): path = stormpy.examples.files.prism_dtmc_die prism_program = stormpy.parse_prism_program(path) formula_str = "P=? [F s=7 & d=2]" properties = stormpy.parse_properties_for_prism_program(formula_str, prism_program) # Fix variables in the program. module = prism_program.modules[0] s_var = module.get_integer_variable("s").expression_variable d_var = module.get_integer_variable("d").expression_variable # Construct the model options = stormpy.BuilderOptions([p.raw_formula for p in properties]) options.set_build_state_valuations() model_builder = stormpy.make_sparse_model_builder(prism_program, options) model = model_builder.build() # and export the model from building state_mapping = model_builder.export_lookup() #lookup 1 state = { s_var : prism_program.expression_manager.create_integer(3), d_var : prism_program.expression_manager.create_integer(0)} id = state_mapping.lookup(state) assert model.state_valuations.get_integer_value(id, s_var) == 3 assert model.state_valuations.get_integer_value(id, d_var) == 0 #lookup 2 state = { s_var : prism_program.expression_manager.create_integer(7), d_var : prism_program.expression_manager.create_integer(3)} id = state_mapping.lookup(state) assert model.state_valuations.get_integer_value(id, s_var) == 7 assert model.state_valuations.get_integer_value(id, d_var) == 3
def example_exploration_02(): """ Example to exploration of POMDPs. :return: """ program = stormpy.parse_prism_program( stormpy.examples.files.prism_pomdp_maze) prop = "R=? [F \"goal\"]" properties = stormpy.parse_properties(prop, program) model = stormpy.build_model(program, properties) print(model.model_type) # Internally, POMDPs are just MDPs with additional observation information. # Thus, data structure exploration for MDPs can be applied as before. initial_state = model.initial_states[0] for state in model.states: if state.id in model.initial_states: print(state) for action in state.actions: for transition in action.transitions: print( "From state {} by action {}, with probability {}, go to state {}" .format(state, action, transition.value(), transition.column)) print(model.nr_observations) for state in model.states: print("State {} has observation id {}".format( state.id, model.observations[state.id]))
def test_change_parametric_matrix_modelchecking(self): import stormpy.logic 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) initial_state = model.initial_states[0] assert initial_state == 0 matrix = model.transition_matrix # Check matrix one_pol = stormpy.RationalRF(1) one_pol = stormpy.FactorizedPolynomial(one_pol) one = stormpy.FactorizedRationalFunction(one_pol, one_pol) for e in matrix: assert e.value() == one or len(e.value().gather_variables()) > 0 # First model checking result = stormpy.model_checking(model, formulas[0]) ratFunc = result.at(initial_state) assert len(ratFunc.gather_variables()) > 0 # Change probabilities two_pol = stormpy.RationalRF(2) two_pol = stormpy.FactorizedPolynomial(two_pol) new_val = stormpy.FactorizedRationalFunction(one_pol, two_pol) for e in matrix: if len(e.value().gather_variables()) > 0: e.set_value(new_val) for e in matrix: assert e.value() == new_val or e.value() == one # Second model checking result = stormpy.model_checking(model, formulas[0]) ratFunc = result.at(initial_state) assert len(ratFunc.gather_variables()) == 0
def example_parametric_models_01(): # Check support for parameters if not config.storm_with_pars: print("Support parameters is missing. Try building storm-pars.") return import stormpy.pars path = stormpy.examples.files.prism_pdtmc_die prism_program = stormpy.parse_prism_program(path) formula_str = "P=? [F s=7 & d=3]" properties = stormpy.parse_properties_for_prism_program(formula_str, prism_program) model = stormpy.build_parametric_model(prism_program, properties) print("Model supports parameters: {}".format(model.supports_parameters)) parameters = model.collect_probability_parameters() assert len(parameters) == 2 instantiator = stormpy.pars.PDtmcInstantiator(model) point = dict() for x in parameters: print(x.name) point[x] = stormpy.RationalRF(0.0) instantiated_model = instantiator.instantiate(point) result = stormpy.model_checking(instantiated_model, properties[0]) print(result)
def example_analysis_02(): path = stormpy.examples.files.prism_dtmc_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_symbolic_model(prism_program, properties) result = stormpy.model_checking(model, properties[0]) filter = stormpy.create_filter_initial_states_symbolic(model) result.filter(filter) assert result.min == result.max print(result.min) # Create an auxiliary mapping to build expressions that matches some state. variables = dict() for m in prism_program.modules: for v in m.integer_variables: variables[v.name] = v.expression_variable.get_expression() expr_manager = prism_program.expression_manager expr_for_state_1 = Expression.Conjunction([ Expression.Eq(variables["s"], expr_manager.create_integer(1)), Expression.Eq(variables["d"], expr_manager.create_integer(0)) ]) expr_for_state_2 = Expression.And( Expression.Eq(variables["s"], expr_manager.create_integer(4)), Expression.Eq(variables["d"], expr_manager.create_integer(0))) result = stormpy.model_checking(model, properties[0]) cached_res = result.clone() cached_res.filter(stormpy.create_filter_symbolic(model, expr_for_state_1)) print(cached_res.min) result.filter(stormpy.create_filter_symbolic(model, expr_for_state_2)) assert result.min == result.max print(result.min)
def test_scheduler_mdp(self): program = stormpy.parse_prism_program( get_example_path("mdp", "coin2-2.nm")) formulas = stormpy.parse_properties_for_prism_program( "Pmin=? [ F \"finished\" & \"all_coins_equal_1\"]", program) model = stormpy.build_model(program, formulas) assert model.nr_states == 272 assert model.nr_transitions == 492 assert len(model.initial_states) == 1 initial_state = model.initial_states[0] assert initial_state == 0 result = stormpy.model_checking(model, formulas[0], extract_scheduler=True) assert result.has_scheduler scheduler = result.scheduler assert scheduler.memoryless assert scheduler.memory_size == 1 assert scheduler.deterministic for state in model.states: choice = scheduler.get_choice(state) assert choice.defined assert choice.deterministic action = choice.get_deterministic_choice() assert 0 <= action assert action < len(state.actions) distribution = choice.get_choice() assert str(distribution).startswith("{[1:")
def test_pla(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 env = stormpy.Environment() checker = stormpy.pars.create_region_checker(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, splitting_threshold=None) result = checker.check_region(env, region) assert result == stormpy.pars.RegionResult.ALLSAT region = stormpy.pars.ParameterRegion.create_from_string( "0.4<=pL<=0.65,0.75<=pK<=0.95", parameters, splitting_threshold=None) result = checker.check_region( env, region, stormpy.pars.RegionResultHypothesis.UNKNOWN, stormpy.pars.RegionResult.UNKNOWN, True) assert result == stormpy.pars.RegionResult.EXISTSBOTH region = stormpy.pars.ParameterRegion.create_from_string( "0.1<=pL<=0.73,0.2<=pK<=0.715", parameters, splitting_threshold=None) result = checker.check_region(env, region) assert result == stormpy.pars.RegionResult.ALLVIOLATED
def test_apply_scheduler_ma(self): program = stormpy.parse_prism_program( get_example_path("ma", "simple.ma"), False, True) formulas = stormpy.parse_properties_for_prism_program( "Tmin=? [ F s=4 ]", program) ma = stormpy.build_model(program, formulas) assert ma.nr_states == 5 assert ma.nr_transitions == 8 assert ma.model_type == stormpy.ModelType.MA initial_state = ma.initial_states[0] assert initial_state == 0 result = stormpy.model_checking(ma, formulas[0], extract_scheduler=True) assert math.isclose(result.at(initial_state), 0.08333333333) assert result.has_scheduler scheduler = result.scheduler assert scheduler.memoryless assert scheduler.memory_size == 1 assert scheduler.deterministic intermediate = ma.apply_scheduler(scheduler) assert intermediate.model_type == stormpy.ModelType.MA assert intermediate.nr_states == 3 assert intermediate.nr_transitions == 4 for state in intermediate.states: assert len(state.actions) == 1
def test_apply_scheduler_mdp(self): program = stormpy.parse_prism_program( get_example_path("mdp", "coin2-2.nm")) formulas = stormpy.parse_properties_for_prism_program( "Pmin=? [ F \"finished\" & \"all_coins_equal_1\"]", program) model = stormpy.build_model(program, formulas) assert model.nr_states == 272 assert model.nr_transitions == 492 assert len(model.initial_states) == 1 initial_state = model.initial_states[0] assert initial_state == 0 result = stormpy.model_checking(model, formulas[0], extract_scheduler=True) assert result.has_scheduler scheduler = result.scheduler assert scheduler.memoryless assert scheduler.memory_size == 1 assert scheduler.deterministic assert not scheduler.partial intermediate = model.apply_scheduler(scheduler, True) assert intermediate.model_type == stormpy.ModelType.DTMC assert intermediate.nr_states == 126 assert intermediate.nr_transitions == 156 for state in intermediate.states: assert len(state.actions) == 1
def load_sketch(self, path, property_path, optimality_path=None, constant_str=""): logger.info("Load sketch from {} with constants {}".format( path, constant_str)) prism_program = stormpy.parse_prism_program(path) self.expression_manager = prism_program.expression_manager self._load_properties_from_file(prism_program, property_path, constant_str) if optimality_path is not None: self._load_optimality(optimality_path, prism_program) all_properties = self.properties + [ self._optimality_setting.criterion ] else: all_properties = self.properties self.sketch, all_properties = prism_program.to_jani(all_properties) if optimality_path is not None: self.properties = all_properties[:-1] self._optimality_setting._criterion = all_properties[-1] else: self.properties = all_properties self._set_constants(constant_str) self._find_holes() self._annotate_properties(constant_str) assert self.expression_manager == self.sketch.expression_manager
def _run_pric3(filename, threshold): settings = Settings(default_oracle_value=Fraction(0), check_inductiveness_if_property_holds=True, check_relative_inductiveness_of_frames=False, obligation_queue_class="RepushingObligationQueue", oracle_type="perfect", number_simulations_for_oracle=100000, max_number_steps_per_simulation=1000000, simulator="cpp", propagate=True, forall_mode=ForallMode.FORALL_GLOBALS.value, inline_goal=True, int_to_real=False, export_to_smt2=False, store_smt_calls=False, generalize=False, depth_for_partly_solving_lqs=200, generalization_method="Hybrid", max_num_ctgs=1, use_states_of_same_kind=True) prism_program = parse_prism_program(filename) input_program = InputProgram(prism_program) smt_program = SmtProgram(input_program, settings.get_smt_settings()) ic3 = PrIC3(smt_program, Fraction(threshold), settings, Statistics(dict())) return ic3.run()
def example_simulator_01(): path = stormpy.examples.files.prism_dtmc_die prism_program = stormpy.parse_prism_program(path) model = stormpy.build_model(prism_program) simulator = stormpy.simulator.create_simulator(model, seed=42) final_outcomes = dict() for n in range(1000): while not simulator.is_done(): observation = simulator.step() if observation not in final_outcomes: final_outcomes[observation] = 1 else: final_outcomes[observation] += 1 simulator.restart() print(final_outcomes) options = stormpy.BuilderOptions([]) options.set_build_state_valuations() model = stormpy.build_sparse_model_with_options(prism_program, options) simulator = stormpy.simulator.create_simulator(model, seed=42) simulator.set_observation_mode(stormpy.simulator.SimulatorObservationMode.PROGRAM_LEVEL) final_outcomes = dict() for n in range(1000): while not simulator.is_done(): observation = simulator.step() if observation not in final_outcomes: final_outcomes[observation] = 1 else: final_outcomes[observation] += 1 simulator.restart() print(", ".join([f"{str(k)}: {v}" for k,v in final_outcomes.items()]))
def example_highlevel_models(): path = stormpy.examples.files.prism_pdtmc_die prism_program = stormpy.parse_prism_program(path) for c in prism_program.constants: print("constant {} with type {} is {} defined".format( c.name, c.type, "" if c.defined else "not")) path = stormpy.examples.files.prism_dtmc_brp prism_program = stormpy.parse_prism_program(path) for module in prism_program.modules: for v in module.integer_variables: print( f"Variable {v.name} has bounds {v.lower_bound_expression} and {v.upper_bound_expression}" ) for v in module.boolean_variables: print(f"Variable {v.name} is Boolean")
def test_model_checking_prob01(self): program = stormpy.parse_prism_program( get_example_path("dtmc", "die.pm")) formulaPhi = stormpy.parse_properties("true")[0] formulaPsi = stormpy.parse_properties("\"six\"")[0] model = stormpy.build_model(program, [formulaPsi]) phiResult = stormpy.model_checking(model, formulaPhi) phiStates = phiResult.get_truth_values() assert phiStates.number_of_set_bits() == model.nr_states psiResult = stormpy.model_checking(model, formulaPsi) psiStates = psiResult.get_truth_values() assert psiStates.number_of_set_bits() == 1 (prob0, prob1) = stormpy.compute_prob01_states(model, phiStates, psiStates) assert prob0.number_of_set_bits() == 9 assert prob1.number_of_set_bits() == 1 (prob0, prob1) = stormpy.compute_prob01min_states(model, phiStates, psiStates) assert prob0.number_of_set_bits() == 9 assert prob1.number_of_set_bits() == 1 (prob0, prob1) = stormpy.compute_prob01max_states(model, phiStates, psiStates) assert prob0.number_of_set_bits() == 9 assert prob1.number_of_set_bits() == 1 labelprop = stormpy.core.Property("cora", formulaPsi.raw_formula) result = stormpy.model_checking(model, labelprop) assert result.get_truth_values().number_of_set_bits() == 1
def test_transform_continuous_to_discrete_time_model_ma(self): program = stormpy.parse_prism_program( get_example_path("ma", "simple.ma"), False, True) formulas = stormpy.parse_properties_for_prism_program( "Tmin=? [ F s=4 ]", program) ma = stormpy.build_model(program, formulas) assert ma.nr_states == 5 assert ma.nr_transitions == 8 assert ma.model_type == stormpy.ModelType.MA assert len(ma.initial_states) == 1 initial_state = ma.initial_states[0] assert initial_state == 0 result = stormpy.model_checking(ma, formulas[0]) assert math.isclose(result.at(initial_state), 0.08333333333) mdp, mdp_formulas = stormpy.transform_to_discrete_time_model( ma, formulas) assert mdp.nr_states == 5 assert mdp.nr_transitions == 8 assert mdp.model_type == stormpy.ModelType.MDP assert len(mdp.initial_states) == 1 initial_state = mdp.initial_states[0] assert initial_state == 0 result = stormpy.model_checking(mdp, mdp_formulas[0]) assert math.isclose(result.at(initial_state), 0.08333333333)
def parse_cap_from_prism(filename): prism_prog = stormpy.parse_prism_program(filename) for cons in prism_prog.constants: if cons.name == "capacity": return cons.definition.evaluate_as_int() return None