Skip to content

Commit

Permalink
stormpy is None if import failed
Browse files Browse the repository at this point in the history
  • Loading branch information
PimLeerkes committed Feb 18, 2025
1 parent c1d2eb3 commit 2603a0b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 21 deletions.
3 changes: 2 additions & 1 deletion pyrightconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"ignore": [
"**/.vscode/**",
"**.ipynb"
]
],
"reportInvalidTypeForm": false
}
17 changes: 13 additions & 4 deletions stormvogel/mapping.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import stormvogel.model

try:
import stormpy.storage

stormpy_installed = True
import stormpy
except ImportError:
stormpy_installed = False
stormpy = None


def stormvogel_to_stormpy(
Expand All @@ -25,6 +23,7 @@ def build_matrix(
Takes a model and creates a stormpy sparsematrix that represents the same transitions
"""

assert stormpy is not None
row_grouping = model.supports_actions()
builder = stormpy.SparseMatrixBuilder(
rows=0,
Expand Down Expand Up @@ -62,6 +61,7 @@ def add_labels(model: stormvogel.model.Model) -> stormpy.storage.StateLabeling:
"""
Takes a model creates a state labelling object that determines which states get which labels in the stormpy representation
"""
assert stormpy is not None

state_labeling = stormpy.storage.StateLabeling(len(model.states))

Expand All @@ -82,6 +82,8 @@ def add_rewards(
"""
Takes a model and creates a dictionary of all the stormpy representations of reward models
"""
assert stormpy is not None

reward_models = {}
for rewardmodel in model.rewards:
reward_models[rewardmodel.name] = stormpy.SparseRewardModel(
Expand All @@ -94,6 +96,7 @@ def map_dtmc(model: stormvogel.model.Model) -> stormpy.storage.SparseDtmc:
"""
Takes a simple representation of a dtmc as input and outputs a dtmc how it is represented in stormpy
"""
assert stormpy is not None

# we first build the SparseMatrix
matrix = build_matrix(model, None)
Expand All @@ -118,6 +121,7 @@ def map_mdp(model: stormvogel.model.Model) -> stormpy.storage.SparseMdp:
"""
Takes a simple representation of an mdp as input and outputs an mdp how it is represented in stormpy
"""
assert stormpy is not None

# we determine the number of choices and the labels
count = 0
Expand Down Expand Up @@ -158,6 +162,7 @@ def map_ctmc(model: stormvogel.model.Model) -> stormpy.storage.SparseCtmc:
"""
Takes a simple representation of a ctmc as input and outputs a ctmc how it is represented in stormpy
"""
assert stormpy is not None

# we first build the SparseMatrix (in stormvogel these are always the rate transitions)
matrix = build_matrix(model, None)
Expand Down Expand Up @@ -186,6 +191,7 @@ def map_pomdp(model: stormvogel.model.Model) -> stormpy.storage.SparsePomdp:
"""
Takes a simple representation of an pomdp as input and outputs an pomdp how it is represented in stormpy
"""
assert stormpy is not None

# we determine the number of choices and the labels
count = 0
Expand Down Expand Up @@ -236,6 +242,7 @@ def map_ma(model: stormvogel.model.Model) -> stormpy.storage.SparseMA:
"""
Takes a simple representation of an ma as input and outputs an ma how it is represented in stormpy
"""
assert stormpy is not None

# we determine the number of choices and the labels
count = 0
Expand Down Expand Up @@ -289,6 +296,8 @@ def map_ma(model: stormvogel.model.Model) -> stormpy.storage.SparseMA:
return ma

if model.all_states_outgoing_transition():
assert stormpy is not None

# we make a mapping between stormvogel and stormpy ids in case they are out of order.
stormpy_id = {}
for index, stormvogel_id in enumerate(model.states.keys()):
Expand Down
6 changes: 1 addition & 5 deletions tests/test_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@
import examples.simple_ma
from stormvogel.model import EmptyAction

try:
import stormpy

stormpy_installed = True
except ImportError:
stormpy_installed = False
import stormpy.storage


def sparse_equal(
Expand Down
7 changes: 1 addition & 6 deletions tests/test_model_checking.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@
import examples.die


try:
import stormpy

stormpy_installed = True
except ImportError:
stormpy_installed = False
import stormpy


def test_model_checking():
Expand Down
6 changes: 1 addition & 5 deletions tests/test_result.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import stormvogel.result
import pytest

try:
import stormpy

stormpy_installed = True
except ImportError:
stormpy_installed = False
import stormpy


def test_convert_model_checker_results_dtmc():
Expand Down

0 comments on commit 2603a0b

Please sign in to comment.