Browse Source

Changes according to DFT loading in Storm

refactoring
Matthias Volk 6 years ago
parent
commit
1308fe2e93
  1. 8
      doc/source/doc/dfts.rst
  2. 4
      examples/dfts/01-dfts.py
  3. 8
      src/dft/io.cpp
  4. 6
      tests/dft/test_build.py

8
doc/source/doc/dfts.rst

@ -7,7 +7,9 @@ Building DFTs
============= =============
.. seealso:: `01-dfts.py <https://github.com/moves-rwth/stormpy/blob/master/examples/dfts/01-dfts.py>`_ .. seealso:: `01-dfts.py <https://github.com/moves-rwth/stormpy/blob/master/examples/dfts/01-dfts.py>`_
Dynamic fault trees can be loaded from either the Galileo format via ``load_dft_json(path)`` or from a custom JSON format via ``load_dft_galileo(path)``.
Dynamic fault trees can be loaded from either the Galileo format or from a custom JSON form.
A file containing the DFT in the Galileo format can be loaded via ``load_dft_galileo_file(path)``.
The custom JSON format can be loaded from a file via ``load_dft_json_file(path)`` or directly from a string via ``load_dft_json_string(path)``.
We start by loading a simple DFT containing an AND gate from JSON:: We start by loading a simple DFT containing an AND gate from JSON::
>>> import stormpy >>> import stormpy
@ -15,14 +17,14 @@ We start by loading a simple DFT containing an AND gate from JSON::
>>> import stormpy.examples >>> import stormpy.examples
>>> import stormpy.examples.files >>> import stormpy.examples.files
>>> path_json = stormpy.examples.files.dft_json_and >>> path_json = stormpy.examples.files.dft_json_and
>>> dft_small = stormpy.dft.load_dft_json(path_json)
>>> dft_small = stormpy.dft.load_dft_json_file(path_json)
>>> print(dft_small) >>> print(dft_small)
Top level index: 2, Nr BEs2 Top level index: 2, Nr BEs2
Next we load a more complex DFT from the Galileo format:: Next we load a more complex DFT from the Galileo format::
>>> path_galileo = stormpy.examples.files.dft_galileo_hecs >>> path_galileo = stormpy.examples.files.dft_galileo_hecs
>>> dft = stormpy.dft.load_dft_galileo(path_galileo)
>>> dft = stormpy.dft.load_dft_galileo_file(path_galileo)
After loading the DFT, we can display some common statistics about the model:: After loading the DFT, we can display some common statistics about the model::

4
examples/dfts/01-dfts.py

@ -8,12 +8,12 @@ import stormpy.examples.files
def example_dfts_01(): def example_dfts_01():
# Load from JSON # Load from JSON
path_json = stormpy.examples.files.dft_json_and path_json = stormpy.examples.files.dft_json_and
dft_small = stormpy.dft.load_dft_json(path_json)
dft_small = stormpy.dft.load_dft_json_file(path_json)
print(dft_small) print(dft_small)
# Load from Galileo # Load from Galileo
path = stormpy.examples.files.dft_galileo_hecs path = stormpy.examples.files.dft_galileo_hecs
dft = stormpy.dft.load_dft_galileo(path)
dft = stormpy.dft.load_dft_galileo_file(path)
print("DFT with {} elements.".format(dft.nr_elements())) print("DFT with {} elements.".format(dft.nr_elements()))
print("DFT has {} BEs and {} dynamic elements.".format(dft.nr_be(), dft.nr_dynamic())) print("DFT has {} BEs and {} dynamic elements.".format(dft.nr_be(), dft.nr_dynamic()))

8
src/dft/io.cpp

@ -6,13 +6,15 @@
void define_input(py::module& m) { void define_input(py::module& m) {
// Load DFT input // Load DFT input
m.def("load_dft_galileo", &storm::api::loadDFTGalileo<double>, "Load DFT from Galileo file", py::arg("path"));
m.def("load_dft_galileo_file", &storm::api::loadDFTGalileoFile<double>, "Load DFT from Galileo file", py::arg("path"));
// Parse Jani model // Parse Jani model
m.def("load_dft_json", &storm::api::loadDFTJson<double>, "Load DFT from JSON file", py::arg("path"));
m.def("load_dft_json_file", &storm::api::loadDFTJsonFile<double>, "Load DFT from JSON file", py::arg("path"));
m.def("load_dft_json_string", &storm::api::loadDFTJsonString<double>, "Load DFT from JSON string", py::arg("json_string"));
} }
void define_output(py::module& m) { void define_output(py::module& m) {
// Export DFT // Export DFT
m.def("export_dft_json", &storm::api::exportDFTToJson<double>, "Export DFT to JSON file", py::arg("dft"), py::arg("path"));
m.def("export_dft_json_file", &storm::api::exportDFTToJsonFile<double>, "Export DFT to JSON file", py::arg("dft"), py::arg("path"));
m.def("export_dft_json_string", &storm::api::exportDFTToJsonString<double>, "Export DFT to JSON string", py::arg("dft"));
} }

6
tests/dft/test_build.py

@ -9,21 +9,21 @@ from configurations import dft
@dft @dft
class TestBuild: class TestBuild:
def test_load_dft_json(self): def test_load_dft_json(self):
dft = stormpy.dft.load_dft_json(get_example_path("dft", "and.json"))
dft = stormpy.dft.load_dft_json_file(get_example_path("dft", "and.json"))
assert dft.nr_elements() == 3 assert dft.nr_elements() == 3
assert dft.nr_be() == 2 assert dft.nr_be() == 2
assert dft.nr_dynamic() == 0 assert dft.nr_dynamic() == 0
assert not dft.can_have_nondeterminism() assert not dft.can_have_nondeterminism()
def test_load_dft_galileo(self): def test_load_dft_galileo(self):
dft = stormpy.dft.load_dft_galileo(get_example_path("dft", "hecs.dft"))
dft = stormpy.dft.load_dft_galileo_file(get_example_path("dft", "hecs.dft"))
assert dft.nr_elements() == 23 assert dft.nr_elements() == 23
assert dft.nr_be() == 13 assert dft.nr_be() == 13
assert dft.nr_dynamic() == 2 assert dft.nr_dynamic() == 2
assert not dft.can_have_nondeterminism() assert not dft.can_have_nondeterminism()
def test_analyze_mttf(self): def test_analyze_mttf(self):
dft = stormpy.dft.load_dft_json(get_example_path("dft", "and.json"))
dft = stormpy.dft.load_dft_json_file(get_example_path("dft", "and.json"))
formulas = stormpy.parse_properties("T=? [ F \"failed\" ]") formulas = stormpy.parse_properties("T=? [ F \"failed\" ]")
assert dft.nr_elements() == 3 assert dft.nr_elements() == 3
results = stormpy.dft.analyze_dft(dft, [formulas[0].raw_formula]) results = stormpy.dft.analyze_dft(dft, [formulas[0].raw_formula])

Loading…
Cancel
Save