From 0a5d684127e65275079cf47121b79f6288e0f391 Mon Sep 17 00:00:00 2001 From: Marcell Vazquez-Chanlatte Date: Thu, 26 Oct 2017 22:15:22 -0700 Subject: [PATCH] pytests pass locally --- stl/boolean_eval.py | 1 - stl/utils.py | 28 +++++++++++++++++----------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/stl/boolean_eval.py b/stl/boolean_eval.py index 7dbbd4f..6693d56 100644 --- a/stl/boolean_eval.py +++ b/stl/boolean_eval.py @@ -5,7 +5,6 @@ import operator as op from functools import singledispatch import funcy as fn - import stl import stl.ast from lenses import lens diff --git a/stl/utils.py b/stl/utils.py index 6cd3572..a9ea193 100644 --- a/stl/utils.py +++ b/stl/utils.py @@ -1,18 +1,17 @@ import operator as op from collections import deque from functools import reduce -from typing import Dict, List, Mapping, T, Type, TypeVar +from typing import List, Mapping, Type, TypeVar import funcy as fn -import sympy import traces import lenses import stl.ast from lenses import lens -from stl.ast import (AST, And, AtomicPred, F, G, Interval, LinEq, NaryOpSTL, +from stl.ast import (AST, And, F, G, Interval, LinEq, NaryOpSTL, Neg, Or, Param) -from stl.types import MTL, STL, STL_Generator +from stl.types import STL, STL_Generator Lens = TypeVar('Lens') @@ -40,12 +39,16 @@ def type_pred(*args: List[Type]) -> Mapping[Type, bool]: def ast_lens(phi: STL, bind=True, *, pred=None, focus_lens=None, getter=False) -> Lens: if focus_lens is None: - focus_lens = lambda _: [lens] + def focus_lens(_): + return [lens] + if pred is None: - pred = lambda _: False - l = lenses.bind(phi) if bind else lens + def pred(_): + return False + child_lenses = _ast_lens(phi, pred=pred, focus_lens=focus_lens) - return (l.Tuple if getter else l.Fork)(*child_lenses) + phi = lenses.bind(phi) if bind else lens + return (phi.Tuple if getter else phi.Fork)(*child_lenses) def _ast_lens(phi: STL, pred, focus_lens) -> Lens: @@ -90,8 +93,8 @@ def param_lens(phi: STL) -> Lens: def set_params(phi, val) -> STL: - l = param_lens(phi) if isinstance(phi, AST) else phi - return l.modify(lambda x: float(val.get(x, val.get(str(x), x)))) + phi = param_lens(phi) if isinstance(phi, AST) else phi + return phi.modify(lambda x: float(val.get(x, val.get(str(x), x)))) def f_neg_or_canonical_form(phi: STL) -> STL: @@ -128,7 +131,10 @@ def linear_stl_lipschitz(phi): def inline_context(phi, context): phi2 = None - update = lambda ap: context.get(ap, ap) + + def update(ap): + return context.get(ap, ap) + while phi2 != phi: phi2, phi = phi, AP_lens(phi).modify(update) # TODO: this is hack to flatten the AST. Fix!