Skip to content

Commit

Permalink
Hotfix (#49)
Browse files Browse the repository at this point in the history
* hotfix

* hotfox (needed by python3.12)

* random sample only works on sequences after >py3.9

* manifest

* random sample needs sequence (in rocksample)
  • Loading branch information
zkytony committed Jan 27, 2024
1 parent 767d523 commit 606fae7
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 13 deletions.
4 changes: 2 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ include ./pomdp_py/representations/distribution/histogram.pxd
include ./pomdp_py/framework/planner.pxd
include ./pomdp_py/framework/basics.pxd
include ./pomdp_py/framework/oopomdp.pxd
include ./pomdp_problems/rocksample/cythonize/rocksample_problem.pyx
include ./pomdp_problems/tiger/cythonize/tiger_problem.pyx
include ./pomdp_py/utils/cython_utils.pyx
include ./pomdp_py/problems/rocksample/cythonize/rocksample_problem.pyx
include ./pomdp_py/problems/tiger/cythonize/tiger_problem.pyx
include ./pomdp_py/algorithms/value_iteration.pyx
include ./pomdp_py/algorithms/pomcp.pyx
include ./pomdp_py/algorithms/po_rollout.pyx
Expand Down
4 changes: 2 additions & 2 deletions pomdp_py/problems/multi_object_search/domain/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ def __init__(self):
Find = FindAction()

if MOTION_SCHEME == "xy":
ALL_MOTION_ACTIONS = {MoveEast, MoveWest, MoveNorth, MoveSouth}
ALL_MOTION_ACTIONS = [MoveEast, MoveWest, MoveNorth, MoveSouth]
elif MOTION_SCHEME == "vw":
ALL_MOTION_ACTIONS = {MoveForward, MoveBackward, MoveLeft, MoveRight}
ALL_MOTION_ACTIONS = [MoveForward, MoveBackward, MoveLeft, MoveRight]
else:
raise ValueError("motion scheme '%s' is invalid" % MOTION_SCHEME)
8 changes: 4 additions & 4 deletions pomdp_py/problems/multi_object_search/models/policy_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ def get_all_actions(self, state=None, history=None):
last_action = history[-1][0]
if isinstance(last_action, LookAction):
can_find = True
find_action = set({Find}) if can_find else set({})
find_action = [Find] if can_find else []
if state is None:
return ALL_MOTION_ACTIONS | {Look} | find_action
return ALL_MOTION_ACTIONS + [Look] + find_action
else:
if self._grid_map is not None:
valid_motions = self._grid_map.valid_motions(
self.robot_id, state.pose(self.robot_id), ALL_MOTION_ACTIONS
)
return valid_motions | {Look} | find_action
return list(valid_motions) + [Look] + find_action
else:
return ALL_MOTION_ACTIONS | {Look} | find_action
return ALL_MOTION_ACTIONS + [Look] + find_action

def rollout(self, state, history=None):
return random.sample(self.get_all_actions(state=state, history=history), 1)[0]
2 changes: 1 addition & 1 deletion pomdp_py/problems/multi_object_search/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def solve(
visualize (bool) if True, show the pygame visualization.
"""

random_objid = random.sample(problem.env.target_objects, 1)[0]
random_objid = random.sample(sorted(problem.env.target_objects), 1)[0]
random_object_belief = problem.agent.belief.object_beliefs[random_objid]
if isinstance(random_object_belief, pomdp_py.Histogram):
# Use POUCT
Expand Down
6 changes: 3 additions & 3 deletions pomdp_py/problems/rocksample/rocksample_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ def argmax(self, state, normalized=False, **kwargs):
def get_all_actions(self, **kwargs):
state = kwargs.get("state", None)
if state is None:
return self._all_actions
return list(self._all_actions)
else:
motions = set(self._all_actions)
rover_x, rover_y = state.position
Expand All @@ -355,7 +355,7 @@ def get_all_actions(self, **kwargs):
motions.remove(MoveNorth)
if rover_y == self._n - 1:
motions.remove(MoveSouth)
return motions | self._other_actions
return list(motions | self._other_actions)

def rollout(self, state, history=None):
return random.sample(self.get_all_actions(state=state), 1)[0]
Expand Down Expand Up @@ -529,7 +529,7 @@ def main():

print("*** Testing POMCP ***")
pomcp = pomdp_py.POMCP(
max_depth=20,
max_depth=12,
discount_factor=0.95,
num_sims=10000,
exploration_const=20,
Expand Down
2 changes: 1 addition & 1 deletion pomdp_py/representations/distribution/gaussian.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ from pomdp_py.framework.basics cimport GenerativeDistribution
import numpy as np

# Check if scipy exists
import importlib
import importlib.util
scipy_spec = importlib.util.find_spec("scipy")
if scipy_spec is not None:
from scipy.linalg import sqrtm
Expand Down
1 change: 1 addition & 0 deletions tests/test_conversion_pomdp-solve.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import io
import sys
import glob
import pomdp_py
import subprocess
import inspect
Expand Down

0 comments on commit 606fae7

Please sign in to comment.