Skip to content

Commit

Permalink
chore: dirty fix of types (needs cleanup)
Browse files Browse the repository at this point in the history
  • Loading branch information
koehlma committed Feb 5, 2024
1 parent f709d1a commit 4d90d12
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 44 deletions.
11 changes: 7 additions & 4 deletions momba/engine/__main__.py
Expand Up @@ -2,8 +2,11 @@
#
# Copyright (C) 2021, Maximilian Köhl <koehl@cs.uni-saarland.de>


from __future__ import annotations

import typing as t

import pathlib

import click
Expand All @@ -20,20 +23,20 @@ def main() -> None:
"""


def is_float(string):
def is_float(string: str) -> bool:
if string.replace(".", "").isnumeric():
return True
else:
return False


def parse_constants(cmd_input: str) -> dict:
def parse_constants(cmd_input: str) -> t.Any:
"""
Input expected:
Cons_1:Val_1,...,Const_k:Val_k.
And for all i Val_i in (Int, Bool)
"""
data = {}
data: t.Dict[str, t.Union[bool, int, float]] = {}
for l in cmd_input.split(","): # noqa: E741
idx = l.split("=")[0].strip()
if l.split("=")[1].isnumeric():
Expand Down Expand Up @@ -65,7 +68,7 @@ def parse_constants(cmd_input: str) -> dict:
type=click.Path(exists=False, dir_okay=True, writable=True),
)
@click.option("-c", "--consts")
def translate(model_path: str, output_path: str, consts=None) -> None:
def translate(model_path: str, output_path: str, consts: t.Any = None) -> None:
"""
Translates a MOML model to MombaIR.
"""
Expand Down
78 changes: 39 additions & 39 deletions momba/engine/objectives.py
Expand Up @@ -48,12 +48,12 @@ def extract_objective(prop: model.Expression) -> Objective:
prop = prop.values

if isinstance(prop, model.properties.Probability):
match prop.operator:
case MinMax.MIN:
op = prop.operator.MIN.name
case MinMax.MAX:
op = prop.operator.MAX.name

# match prop.operator:
# case MinMax.MIN:
# op = prop.operator.MIN.name
# case MinMax.MAX:
# op = prop.operator.MAX.name
op = prop.operator
prop = prop.formula

if isinstance(prop, model.properties.UnaryPathFormula):
Expand All @@ -72,38 +72,38 @@ def extract_objective(prop: model.Expression) -> Objective:
return Objective(
goal_predicate=right, dead_predicate=model.expressions.logic_not(lft), op=op
)
elif isinstance(prop, model.properties.ExpectedReward):
match prop.operator:
case MinMax.MIN:
op = prop.operator.MIN.name
case MinMax.MAX:
op = prop.operator.MAX.name
# TODO: change this, we need to support it but this its not the way.
return Objective(
goal_predicate=prop.reachability,
dead_predicate=model.ensure_expr(False),
op=op,
)
elif isinstance(prop, model.expressions.Comparison):
# TODO: change this, we need to support it but this its not the way.
"""
For example, the first 3 properties of the firewire model are a composition
of expression with probabilities.
"""
subprop_l = prop.left

if isinstance(subprop_l.formula, model.properties.BinaryPathFormula):
assert (
subprop_l.formula.operator is model.operators.BinaryPathOperator.UNTIL
), "Unsupported unary path formula."
lft = prop.left
right = prop.right
obj = Objective(
goal_predicate=lft,
dead_predicate=model.expressions.logic_not(lft),
op=op,
)

return obj
# elif isinstance(prop, model.properties.ExpectedReward):
# match prop.operator:
# case MinMax.MIN:
# op = prop.operator.MIN.name
# case MinMax.MAX:
# op = prop.operator.MAX.name
# # TODO: change this, we need to support it but this its not the way.
# return Objective(
# goal_predicate=prop.reachability,
# dead_predicate=model.ensure_expr(False),
# op=op,
# )
# elif isinstance(prop, model.expressions.Comparison):
# # TODO: change this, we need to support it but this its not the way.
# """
# For example, the first 3 properties of the firewire model are a composition
# of expression with probabilities.
# """
# subprop_l = prop.left

# if isinstance(subprop_l.formula, model.properties.BinaryPathFormula):
# assert (
# subprop_l.formula.operator is model.operators.BinaryPathOperator.UNTIL
# ), "Unsupported unary path formula."
# lft = prop.left
# right = prop.right
# obj = Objective(
# goal_predicate=lft,
# dead_predicate=model.expressions.logic_not(lft),
# op=op,
# )

# return obj
else:
raise Exception("Unsupported property!")
2 changes: 1 addition & 1 deletion momba/model/operators.py
Expand Up @@ -24,7 +24,7 @@ class Operator:
Symbol associated with the operator.
"""

name: str
# name: str
symbol: str

def __init__(self, symbol: str):
Expand Down

0 comments on commit 4d90d12

Please sign in to comment.