Skip to content

Commit

Permalink
more robust type assertion and runtime checking
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrozum committed May 4, 2023
1 parent c768bda commit 31eb6e0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions nfvsmotifs/interaction_graph_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,11 @@ def feedback_vertex_set(
The method should be deterministic (the same pseudo-optimal FVS is returned every time).
"""
if type(network) == BooleanNetwork:
network = network.graph() # type: ignore
if type(network) == DiGraph:
if isinstance(network, BooleanNetwork):
network = network.graph()
if isinstance(network, DiGraph):
network = _digraph_to_regulatory_graph(network)
assert type(network) == RegulatoryGraph
assert isinstance(network, RegulatoryGraph)
fvs = network.feedback_vertex_set(parity=parity, restriction=subgraph)
return [network.get_variable_name(x) for x in fvs]

Expand Down Expand Up @@ -168,11 +168,11 @@ def independent_cycles(
every time). However, while I believe the sorting should be stable too, please treat the
order of returned cycles with caution :)
"""
if type(network) == BooleanNetwork:
if isinstance(network, BooleanNetwork):
network = network.graph()

# this should never happen, but it's easy enough to convert
if type(network) == DiGraph: # type: ignore
if isinstance(network, DiGraph):
network = _digraph_to_regulatory_graph(network)

ic = network.independent_cycles(parity=parity, restriction=subgraph)
Expand Down
10 changes: 5 additions & 5 deletions nfvsmotifs/trappist_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ def trappist_async(
if avoid_subspaces is None:
avoid_subspaces = []

if type(network) == BooleanNetwork:
if isinstance(network, BooleanNetwork):
bn = network
petri_net = network_to_petrinet(network)
else:
bn = None
petri_net = network

assert type(petri_net) == DiGraph
assert isinstance(petri_net, DiGraph)

if bn is None:
variables = extract_variable_names(petri_net)
Expand All @@ -74,7 +74,7 @@ def trappist_async(

ctl.ground()
result = ctl.solve(yield_=True)
if type(result) == SolveHandle:
if isinstance(result, SolveHandle):
with result as iterator:
for model in iterator:
if not on_solution(_clingo_model_to_space(model)):
Expand Down Expand Up @@ -224,7 +224,7 @@ def _create_clingo_constraints(

free_places: list[str] = []
for node, kind in petri_net.nodes(data="kind"): # type: ignore # noqa
assert type(node) == str # type: ignore[reportUnknownArgumentType] # noqa
assert isinstance(node, str)
if kind == "place":
if place_to_variable(node)[0] not in ensure_subspace:
free_places.append(node)
Expand Down Expand Up @@ -404,7 +404,7 @@ def compute_fixed_point_reduced_STG_async(

ctl.ground([("base", [])])
result = ctl.solve(yield_=True)
if type(result) == SolveHandle:
if isinstance(result, SolveHandle):
with result as iterator:
for model in iterator:
if not on_solution(_clingo_model_to_fixed_point(model)):
Expand Down

1 comment on commit 31eb6e0

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
nfvsmotifs
   SuccessionDiagram.py1352085%6–7, 58, 66–69, 99, 109–110, 158, 188, 198, 202, 212, 216, 296–299, 372
   interaction_graph_utils.py141795%6–8, 56, 69, 94–95
   motif_avoidant.py116497%25, 58, 72, 110
   petri_net_translation.py84693%23–24, 52, 63–64, 94
   pyeda_utils.py953464%12, 56–66, 90, 95, 98–112, 140–144
   space_utils.py1101487%15–16, 36–43, 52, 198, 213, 270
   state_utils.py681282%15, 55–66, 98, 105, 114
   terminal_restriction_space.py44393%6–7, 80
   trappist_core.py1862288%10–11, 39, 41, 81, 122, 182, 184, 186, 221–223, 249, 260–261, 306, 308, 338, 378, 380, 411, 440
nfvsmotifs/FVSpython3
   FVS.py481079%90–91, 97, 133, 183–189
   FVS_localsearch_10_python.py90199%179
TOTAL121413389% 

Tests Skipped Failures Errors Time
220 0 💤 0 ❌ 0 🔥 3m 26s ⏱️

Please sign in to comment.