Skip to content

Commit

Permalink
fix(interpreted functions): fixing tests - infix operators
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Gobbi committed Nov 7, 2024
1 parent 24fd6e1 commit a874fea
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,9 @@ def _compile(
else:
conds.append((t, new_c))

# get all effects
for time, ef in self.get_effects(a):
ifuns = self.interpreted_functions_extractor.get(ef.value)
# check if they contain IFs
if len(ifuns) != 0:
# if they do save them to ifs with type.EFFECT
ifs.append((time, ef.value, ifuns, c_type.EFFECT, ef))
else:
effs.append((time, ef))
Expand Down
1 change: 0 additions & 1 deletion unified_planning/model/interpreted_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# copyright info is not up to date as of september 27th 2024
"""
This module defines the InterpretedFunction class.
An InterpretedFunction has a name, a return type, a signature
Expand Down
3 changes: 0 additions & 3 deletions unified_planning/model/walkers/quantifier_simplifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ def _compute_node_result(self, expression: "FNode", **kwargs):
self.memoization[key] = f(expression, args=expression.args, **kwargs)
else:
pass
# NOTE - not clean implementation
for key in self.memoization:
if key.is_interpreted_function_exp():
args_values = [
Expand All @@ -121,8 +120,6 @@ def _compute_node_result(self, expression: "FNode", **kwargs):
new_key = temp_key(*args_values)
if new_key not in self.if_values.keys():
self.if_values[new_key] = result
# print ("quantifier simplifier")
# print (self.if_values) # here it works

def _deep_subs_simplify(
self,
Expand Down
4 changes: 2 additions & 2 deletions unified_planning/model/walkers/simplifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def walk_fluent_exp(self, expression: FNode, args: List[FNode]) -> FNode:
else: # value is static but is not defined in the initial state
return new_exp

def walk_interpreted_function_exp( # code here is not clean but should work
def walk_interpreted_function_exp(
self, expression: FNode, args: List[FNode]
) -> FNode:
new_exp = self.manager.InterpretedFunctionExp(
Expand All @@ -355,7 +355,7 @@ def walk_interpreted_function_exp( # code here is not clean but should work
constantval = self.manager.Real((Fraction(constantval)))
elif (

Check warning on line 356 in unified_planning/model/walkers/simplifier.py

View check run for this annotation

Codecov / codecov/patch

unified_planning/model/walkers/simplifier.py#L355-L356

Added lines #L355 - L356 were not covered by tests
expression.interpreted_function().return_type.is_user_type()
): # not sure this works and idk how to check
): # NOTE - not tested

constantval = self.manager.ObjectExp((constantval))

Check warning on line 360 in unified_planning/model/walkers/simplifier.py

View check run for this annotation

Codecov / codecov/patch

unified_planning/model/walkers/simplifier.py#L360

Added line #L360 was not covered by tests
else:
Expand Down
22 changes: 21 additions & 1 deletion unified_planning/test/test_infix_notation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import unified_planning
from unified_planning.shortcuts import *
from unified_planning.test import unittest_TestCase
from typing import List, Tuple
from typing import List, OrderedDict, Tuple


class TestInfixNotation(unittest_TestCase):
Expand Down Expand Up @@ -64,6 +64,26 @@ def test_infix_with_parameters(self):
b_3 = Parameter("b_3", BoolType(), environment)
self._test_helper_function(i_1, r_1, i_2, r_2, b_1, b_2, b_3)

def test_infix_with_interpreted_functions(self):
def if_bool():
return True

Check warning on line 69 in unified_planning/test/test_infix_notation.py

View check run for this annotation

Codecov / codecov/patch

unified_planning/test/test_infix_notation.py#L69

Added line #L69 was not covered by tests

def if_int():
return 3

Check warning on line 72 in unified_planning/test/test_infix_notation.py

View check run for this annotation

Codecov / codecov/patch

unified_planning/test/test_infix_notation.py#L72

Added line #L72 was not covered by tests

def if_real():
return Fraction(2, 5)

Check warning on line 75 in unified_planning/test/test_infix_notation.py

View check run for this annotation

Codecov / codecov/patch

unified_planning/test/test_infix_notation.py#L75

Added line #L75 was not covered by tests

signature_empty: OrderedDict = OrderedDict()
i_1 = InterpretedFunction("i_1", IntType(), signature_empty, if_int)
r_1 = InterpretedFunction("r_1", RealType(), signature_empty, if_real)
i_2 = InterpretedFunction("i_2", IntType(), signature_empty, if_int)
r_2 = InterpretedFunction("r_2", RealType(), signature_empty, if_real)
b_1 = InterpretedFunction("b_1", BoolType(), signature_empty, if_bool)
b_2 = InterpretedFunction("b_2", BoolType(), signature_empty, if_bool)
b_3 = InterpretedFunction("b_3", BoolType(), signature_empty, if_bool)
self._test_helper_function(i_1, r_1, i_2, r_2, b_1, b_2, b_3)

def test_infix_on_objects(self):
ut = UserType("ut")
o_1 = Object("o_1", ut)
Expand Down
7 changes: 3 additions & 4 deletions unified_planning/test/test_plan_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def test_all_from_factory(self):
if not pv.supports(p.problem.kind):
continue
if not p.valid_plans:
# after adding an always impossible problem we have to make sure we skip it
continue
problem, plan = p.problem, p.valid_plans[0]
validation_result = pv.validate(problem, plan)
Expand Down Expand Up @@ -155,8 +154,8 @@ def test_state_invariants(self):
self.assertEqual(validation_result.status, ValidationResultStatus.VALID)

def test_with_interpreted_functions_time_triggered(self):
ttv = SequentialPlanValidator(environment=get_environment())
p = self.problems["interpreted_functions_in_conditions"]
ttv = TimeTriggeredPlanValidator(environment=get_environment())
p = self.problems["go_home_with_rain_and_interpreted_functions"]
problem = p.problem
for plan in p.valid_plans:
validation_result = ttv.validate(problem, plan)
Expand All @@ -168,7 +167,7 @@ def test_with_interpreted_functions_time_triggered(self):
def test_with_interpreted_functions_sequential(self):
spv = SequentialPlanValidator(environment=get_environment())

p = self.problems["interpreted_functions_in_conditions"]
p = self.problems["IF_in_conditions_complex_1"]
problem = p.problem
for plan in p.valid_plans:
validation_result = spv.validate(problem, plan)
Expand Down

0 comments on commit a874fea

Please sign in to comment.