Skip to content

Commit

Permalink
minor fixes in bumping up version to 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
franklinselva committed Nov 24, 2023
1 parent d2f3eaf commit 0bc7c2d
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 27 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
language_version:
python: $(python3 --version | cut -d' ' -f2)
pyproject_toml: ./pyproject.toml
Expand All @@ -9,7 +9,7 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 23.9.1
rev: 23.11.0
hooks:
- id: black
args: [--config=pyproject.toml]
Expand All @@ -33,7 +33,7 @@ repos:
args: [--settings-path=pyproject.toml]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.5.1" # Use the sha / tag you want to point at
rev: "v1.7.1" # Use the sha / tag you want to point at
hooks:
- id: mypy
files: "up_esb/.*\\.py$"
Expand Down
19 changes: 2 additions & 17 deletions tests/components/test_expression_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ def fluent_arg_int_1_fun(arg: int):
return arg


def fluent_arg_real_1_fun(arg: float):
"""Fluent real 1."""
return arg


def fluent_arg_object(arg: TestObject) -> TestObject:
"""Fluent real 1."""
return arg
Expand All @@ -74,12 +69,10 @@ def setUp(self) -> None:
self._fluent_bool_1 = self.bridge.create_fluent_from_function(fluent_bool_1_fun)
self._fluent_bool_2 = self.bridge.create_fluent_from_function(fluent_bool_2_fun)
self._fluent_int_1 = self.bridge.create_fluent_from_function(fluent_int_1_fun)
# self._fluent_real_1 = self.bridge.create_fluent_from_function(fluent_real_1_fun)
self._fluent_real_1 = self.bridge.create_fluent_from_function(fluent_real_1_fun)

self._fluent_arg_bool_1 = self.bridge.create_fluent_from_function(fluent_arg_bool_1_fun)
self._fluent_arg_int_1 = self.bridge.create_fluent_from_function(fluent_arg_int_1_fun)
# TODO: fix this UP==1.0.0 fails creating with a fluent with a realtype argument
# self._fluent_arg_real_1 = self.bridge.create_fluent_from_function(fluent_arg_real_1_fun)

self.bridge.create_types([TestObject])
self._fluent_arg_object = self.bridge.create_fluent_from_function(fluent_arg_object)
Expand All @@ -105,7 +98,7 @@ def test_simple_nested_fluents(self):
actual = eval(compile(result, filename="<ast>", mode="eval"))
self.assertEqual(actual, False)

# result = self.ast.convert(Not(And(self._fluent_real_1, self._fluent_real_1)))
result = self.ast.convert(Not(And(self._fluent_real_1, self._fluent_real_1)))
actual = eval(compile(result, filename="<ast>", mode="eval"))
self.assertEqual(actual, False)

Expand All @@ -130,19 +123,11 @@ def test_simple_fluents_with_args(self):
actual = eval(compile(result, filename="<ast>", mode="eval"))
self.assertEqual(actual, False)

# result = self.ast.convert(Not(self._fluent_arg_real_1(1)))
actual = eval(compile(result, filename="<ast>", mode="eval"))
self.assertEqual(actual, False)

def test_simple_nested_fluents_with_args(self):
result = self.ast.convert(Not(And(self._fluent_arg_int_1(1), self._fluent_arg_int_1(1))))
actual = eval(compile(result, filename="<ast>", mode="eval"))
self.assertEqual(actual, False)

# result = self.ast.convert(Not(And(self._fluent_arg_real_1(1), self._fluent_arg_real_1(1))))
actual = eval(compile(result, filename="<ast>", mode="eval"))
self.assertEqual(actual, False)

result = self.ast.convert(
Not(And(self._fluent_arg_bool_1(True), self._fluent_arg_bool_1(False)))
)
Expand Down
37 changes: 32 additions & 5 deletions up_esb/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ class Bridge:

def __init__(self) -> None:
# Note: Map from type instead of str to recognize subclasses.
self._types: Dict[type, Type] = {
bool: BoolType(),
int: IntType(lower_bound=0, upper_bound=100),
float: RealType(),
}
self._fluents: Dict[str, Fluent] = {}
self._fluent_functions: Dict[str, Callable[..., object]] = {}
self._api_function_names: Set[str] = set()
Expand All @@ -69,6 +64,38 @@ def __init__(self) -> None:
self._objects: Dict[str, Object] = {}
self._api_objects: Dict[str, object] = {}

self._int_bounds: Tuple[int, int] = (0, 100)
self._real_bounds: Tuple[float, float] = (0, 100)
self._types: Dict[type, Type] = {
bool: BoolType(),
int: IntType(lower_bound=self._int_bounds[0], upper_bound=self._int_bounds[1]),
float: RealType(lower_bound=self._real_bounds[0], upper_bound=self._real_bounds[1]),
}

@property
def int_bounds(self) -> Tuple[int, int]:
"""Return bounds for int type."""
return self._int_bounds

@int_bounds.setter
def int_bounds(self, bounds: Tuple[int, int]) -> None:
"""Set bounds for int type."""
self._int_bounds = bounds
assert bounds[0] <= bounds[1], f"Invalid bounds {bounds}!"
self._types[int] = IntType(lower_bound=bounds[0], upper_bound=bounds[1])

@property
def real_bounds(self) -> Tuple[float, float]:
"""Return bounds for real type."""
return self._real_bounds

@real_bounds.setter
def real_bounds(self, bounds: Tuple[float, float]) -> None:
"""Set bounds for real type."""
self._real_bounds = bounds
assert bounds[0] <= bounds[1], f"Invalid bounds {bounds}!"
self._types[float] = RealType(lower_bound=bounds[0], upper_bound=bounds[1])

@property
def objects(self) -> Dict[str, Object]:
"""Return all UP objects."""
Expand Down
11 changes: 9 additions & 2 deletions up_esb/components/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,11 @@ def _time_triggered_plan_to_dependency_graph(plan: TimeTriggeredPlan) -> nx.DiGr
)
for i, (start, action, duration) in enumerate(plan.timed_actions):
child_id = i + 1
duration = float(duration.numerator) / float(duration.denominator)
# TODO: Handle None Durations as Instantaneous Action Node
if duration:
duration = float(duration.numerator) / float(duration.denominator)
else:
duration = 0.0
parameters, preconditions, postconditions = _process_action(action)

dependency_graph.add_node(
Expand All @@ -179,7 +183,10 @@ def _time_triggered_plan_to_dependency_graph(plan: TimeTriggeredPlan) -> nx.DiGr
dependency_graph.add_edge(parent_id, child_id)
if i + 1 < len(plan.timed_actions):
next_start, next_action, next_duration = plan.timed_actions[i + 1]
next_duration = float(next_duration.numerator) / float(next_duration.denominator)
if next_duration:
next_duration = float(next_duration.numerator) / float(next_duration.denominator)
else:
next_duration = 0.0
if start != next_start:
parent_id = child_id
for next_parent in next_parents:
Expand Down

0 comments on commit 0bc7c2d

Please sign in to comment.