def example_building_models_01(): path = stormpy.examples.files.drn_ctmc_dft model = stormpy.build_model_from_drn(path) print(model.model_type) print("Number of states: {}".format(model.nr_states)) # And the parametric path = stormpy.examples.files.drn_pdtmc_die model = stormpy.build_parametric_model_from_drn(path) print(model.model_type) print("Number of states: {}".format(model.nr_states)) path = stormpy.examples.files.jani_dtmc_die jani_program, properties = stormpy.parse_jani_model(path) model = stormpy.build_model(jani_program) print(model.model_type) print("Number of states: {}".format(model.nr_states)) # POMDPs should be constructed with choice labels path = stormpy.examples.files.drn_pomdp_maze opts = stormpy.DirectEncodingParserOptions() opts.build_choice_labels = True pomdp = stormpy.build_model_from_drn(stormpy.examples.files.drn_pomdp_maze, opts) # POMDPs need to be in a canonic representation pomdp = stormpy.pomdp.make_canonic(pomdp)
def test_parse_jani_model(self): jani_model, properties = stormpy.parse_jani_model(get_example_path("dtmc", "die.jani")) assert jani_model.name == "die.jani" assert jani_model.model_type == stormpy.JaniModelType.DTMC assert not jani_model.has_undefined_constants description = stormpy.SymbolicModelDescription(jani_model) assert not description.is_prism_program assert description.is_jani_model
def test_build_dtmc_from_jani_model(self): jani_model, properties = stormpy.parse_jani_model(get_example_path("dtmc", "die.jani")) model = stormpy.build_model(jani_model) assert model.nr_states == 13 assert model.nr_transitions == 20 assert model.model_type == stormpy.ModelType.DTMC assert not model.supports_parameters assert type(model) is stormpy.SparseDtmc
def test_choice_origins(self): program, _ = stormpy.parse_jani_model(get_example_path("dtmc", "die.jani")) a = stormpy.FlatSet() options = stormpy.BuilderOptions() options.set_build_with_choice_origins() model = stormpy.build_sparse_model_with_options(program, options) a = model.choice_origins.get_edge_index_set(3)
def test_jani_formula(self): _, properties = stormpy.parse_jani_model(get_example_path("dtmc", "die.jani")) assert len(properties) == 2 prop = properties[0] assert isinstance(prop, stormpy.Property) assert prop.name == "Probability to throw a six" prop = properties[1] assert isinstance(prop, stormpy.Property) assert prop.name == "Expected number of coin flips"
def test_build_dtmc_from_jani_model(self): jani_model, properties = stormpy.parse_jani_model(get_example_path("dtmc", "brp.jani")) 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_symbolic_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.SymbolicSylvanDtmc
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
def load_model(self, model_file): self.properties = None ## Obtain the file type from the path. self.file_type = os.path.splitext(model_file)[1] self.file_path = model_file ## Parse the pomdp model. if self.file_type == ".prism": self.program = stormpy.parse_prism_program(model_file) elif self.file_type == ".drn": self.program = None elif self.file_type == ".jani": self.program, self.properties = stormpy.parse_jani_model( model_file) else: raise Exception("Model file type not supported")
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)
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)
def get_jani_program(path): """ Receives SPN codified in JANI or PNPRO and returns a JANI Model """ if path.lower().endswith(".jani"): jani_program, properties = stormpy.parse_jani_model(path) return jani_program if path.lower().endswith(".pnpro"): gspn_parser = stormpy.gspn.GSPNParser() gspn = gspn_parser.parse(path) jani_builder = stormpy.gspn.GSPNToJaniBuilder(gspn) jani_program = jani_builder.build() return jani_program print("Unsupported file format: {}".format(path)) exit()
def example_building_models_01(): path = stormpy.examples.files.drn_ctmc_dft model = stormpy.build_model_from_drn(path) print(model.model_type) print("Number of states: {}".format(model.nr_states)) # And the parametric path = stormpy.examples.files.drn_pdtmc_die model = stormpy.build_parametric_model_from_drn(path) print(model.model_type) print("Number of states: {}".format(model.nr_states)) path = stormpy.examples.files.jani_dtmc_die jani_program, properties = stormpy.parse_jani_model(path) model = stormpy.build_model(jani_program) print(model.model_type) print("Number of states: {}".format(model.nr_states))
def test_jani_formula(self): _, properties = stormpy.parse_jani_model( get_example_path("dtmc", "brp.jani")) for name, prop in properties.items(): assert "Property_brp_" in name assert isinstance(prop, stormpy.Property)
def test_build_dtmc_with_undefined_constants(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 with pytest.raises(stormpy.StormError): model = stormpy.build_model(jani_model)
def test_information_collection(self): model, properties = stormpy.parse_jani_model(get_example_path("dtmc", "brp.jani")) information = stormpy.collect_information(model) assert information.nr_automata == 5 assert information.nr_edges == 31 assert information.nr_variables == 18