Skip to content

Commit

Permalink
Move to pyproject.toml (#44)
Browse files Browse the repository at this point in the history
* adding pyproject.toml

* version

* move pomdp_problems inside pomdp_py

* build ext correction

* dependencies

* move plotting to light_dark

* version correction

* remove test utils

* remove visual

* fix

* fix main
  • Loading branch information
zkytony authored Jan 26, 2024
1 parent b73b52c commit 0fe9bdb
Show file tree
Hide file tree
Showing 107 changed files with 227 additions and 369 deletions.
1 change: 0 additions & 1 deletion pomdp_problems/__init__.py

This file was deleted.

7 changes: 0 additions & 7 deletions pomdp_problems/light_dark/__init__.py

This file was deleted.

1 change: 0 additions & 1 deletion pomdp_problems/tiger/__init__.py

This file was deleted.

1 change: 0 additions & 1 deletion pomdp_py/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from pomdp_py.algorithms.po_uct import POUCT, QNode, VNode, RootVNode,\
RolloutPolicy, RandomRollout, ActionPrior
from pomdp_py.algorithms.bsp.blqr import BLQR
from pomdp_py import visual

# Templates & Utilities
from pomdp_py.utils.templates import *
Expand Down
12 changes: 6 additions & 6 deletions pomdp_py/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
def parse_args():
parser = argparse.ArgumentParser(description="pomdp_py CLI")
parser.add_argument("-r", "--run", type=str,
help="run a pomdp under pomdp_problems."
help="run a pomdp under pomdp_py.problems."
"Available options: {}".format(available_problems))
args = parser.parse_args()
return parser, args
Expand All @@ -20,23 +20,23 @@ def parse_args():
parser, args = parse_args()
if args.run:
if args.run.lower() == "tiger":
from pomdp_problems.tiger.tiger_problem import main
from pomdp_py.problems.tiger.tiger_problem import main
main()

elif args.run.lower() == "rocksample":
from pomdp_problems.rocksample.rocksample_problem import main
from pomdp_py.problems.rocksample.rocksample_problem import main
main()

elif args.run.lower() == "mos":
from pomdp_problems.multi_object_search.problem import unittest
from pomdp_py.problems.multi_object_search.problem import unittest
unittest()

elif args.run.lower() == "tag":
from pomdp_problems.tag.problem import main
from pomdp_py.problems.tag.problem import main
main()

elif args.run.lower() == "load_unload":
from pomdp_problems.load_unload.load_unload import main
from pomdp_py.problems.load_unload.load_unload import main
main()

else:
Expand Down
1 change: 1 addition & 0 deletions pomdp_py/problems/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from pomdp_py.problems import tiger
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions pomdp_py/problems/light_dark/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from pomdp_py.problems.light_dark.env.env import LightDarkEnvironment
from pomdp_py.problems.light_dark.env.visual import LightDarkViz
from pomdp_py.problems.light_dark.domain.state import *
from pomdp_py.problems.light_dark.domain.action import *
from pomdp_py.problems.light_dark.domain.observation import *
from pomdp_py.problems.light_dark.models.transition_model import *
from pomdp_py.problems.light_dark.models.observation_model import *
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"""

import pomdp_py
import pomdp_problems.light_dark as ld
import pomdp_py.problems.light_dark as ld
import numpy as np

class LightDarkEnvironment(pomdp_py.Environment):

def __init__(self,
init_state,
light,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ def plot_points(xvals, yvals, color=None,
plt.ylabel(ylabel)
plt.legend(loc=loc)

def save_plot(path, bbox_inches='tight'):
plt.savefig(path, bbox_inches=bbox_inches)
plt.close()


# Plot polygons with colors
def plot_polygons(verts, colors, ax=None, edgecolor=None):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Plot the light dark environment"""
import matplotlib.pyplot as plt
from matplotlib.collections import PolyCollection
import pomdp_problems.light_dark as ld
import pomdp_py.problems.light_dark as ld
from pomdp_py.utils import plotting, colors
from pomdp_py.utils.misc import remap

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import pomdp_problems.light_dark as ld
import pomdp_py.problems.light_dark as ld
import matplotlib.pyplot as plt
import pomdp_py
import numpy as np
Expand Down Expand Up @@ -77,7 +77,7 @@ def manual_test(blqr):
print(b_1[1])
b_1 = blqr.ekf_update_mlo(b_1, [-1.0, 0.0])
print(b_1[0])
print(b_1[1])
print(b_1[1])
b_1 = blqr.ekf_update_mlo(b_1, [-1.0, 0.0])
print(b_1[0])
print(b_1[1])
Expand Down Expand Up @@ -126,7 +126,7 @@ def manual_test(blqr):
b_traj_light.append(b_tp1)
b_t = b_tp1
bu_traj_light = [(b_traj_light[t], np.array(u_traj_light[t])) for t in range(len(u_traj_light))]

# traj not through light
u_traj_dark = [[-1., -1.], [-1., -1.], [-1., -1.]]
b_t = b_0
Expand All @@ -135,12 +135,12 @@ def manual_test(blqr):
u_t = u_traj_dark[t]
b_tp1 = blqr.ekf_update_mlo(b_t, u_t)
b_traj_dark.append(b_tp1)
b_t = b_tp1
b_t = b_tp1
bu_traj_dark = [(b_traj_dark[t], np.array(u_traj_dark[t])) for t in range(len(u_traj_dark))]


total_light = 0
total_dark = 0
total_dark = 0
for i in range(1000):
cost_light = blqr.segmented_cost_function(bu_traj_light, b_des, [], len(bu_traj_light))
cost_dark = blqr.segmented_cost_function(bu_traj_dark, b_des, [], len(bu_traj_dark))
Expand All @@ -154,7 +154,7 @@ def manual_test(blqr):
viz = ld.LightDarkViz(env, x_range, y_range, 0.1)
viz.set_goal(goal_pos)
viz.set_initial_belief_pos(b_0[0])

# Made up paths
viz.log_position(tuple(b_0[0]), path=2)
viz.log_position(tuple(b_0[0]), path=3)
Expand All @@ -171,7 +171,7 @@ def manual_test(blqr):
for b_t, u_t in bu_traj_dark:
viz.log_position(tuple(b_t[0]), path=4)
viz.log_position(tuple(sysd_b_dark[-1][0]), path=5)
sysd_b_dark.append((func_sysd(sysd_b_dark[-1][0], u_t), 0))
sysd_b_dark.append((func_sysd(sysd_b_dark[-1][0], u_t), 0))

viz.plot(path_colors={2: [(0,0,0), (0,255,0)],
3: [(0,0,0), (0,255,255)],
Expand All @@ -181,7 +181,7 @@ def manual_test(blqr):
3: "-",
4: "--",
5: "-"})
plt.show()
plt.show()



Expand All @@ -197,13 +197,13 @@ def test(blqr):
############
b_0 = (np.array([2.0, 2.0]),
np.array([[5.0, 0.0],
[0.0, 5.0]]))
[0.0, 5.0]]))
x_sol = blqr.create_plan(b_0, b_des, u_des,
num_segments=num_segments,
opt_options={"maxiter": 30},
opt_callback=opt_callback,
control_bounds=(-0.1, 0.1))
with np.printoptions(precision=3, suppress=True):
with np.printoptions(precision=3, suppress=True):
print("SLSQP solution:")
print(x_sol)
plan = blqr.interpret_sqp_plan(x_sol, num_segments)
Expand All @@ -227,22 +227,22 @@ def test(blqr):
1: "-"},
path_widths={0: 4,
1: 1})
plt.show()
plt.show()





if __name__ == "__main__":
test(blqr)
# bt = (np.array([1.3, 2.0]), np.array([[0.5, 0.0], [0.0, 0.5]]))
# ut = np.array([1.5, 0.2])

# func_sysd = env.transition_model.func()
# func_obs = obsmodel.func()
# jac_sysd = env.transition_model.jac_dx()
# jac_sysd_u = env.transition_model.jac_du()
# jac_obs = obsmodel.jac_dx()

# noise_sysd = pomdp_py.Gaussian([0,0], [[0.1,0],
# [0,0.1]]).random()
# noise_obs_cov = obsmodel.noise_covariance(bt[0])
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

# Reuses the actions in the multi object search domain
import pomdp_py
from pomdp_problems.multi_object_search.domain.action\
from pomdp_py.problems.multi_object_search.domain.action\
import MotionAction, MoveForward, MoveBackward, MoveLeft, MoveRight, LookAction
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import pomdp_py
import copy
from pomdp_problems.multi_object_search.models.transition_model import *
from pomdp_problems.multi_object_search.models.reward_model import *
from pomdp_problems.multi_object_search.models.components.sensor import *
from pomdp_problems.multi_object_search.domain.state import *
from pomdp_py.problems.multi_object_search.models.transition_model import *
from pomdp_py.problems.multi_object_search.models.reward_model import *
from pomdp_py.problems.multi_object_search.models.components.sensor import *
from pomdp_py.problems.multi_object_search.domain.state import *

class MosEnvironment(pomdp_py.Environment):
""""""
Expand Down Expand Up @@ -33,7 +33,7 @@ def __init__(self, dim, init_state, sensors, obstacles=set({})):
super().__init__(init_state,
transition_model,
reward_model)

@property
def robot_ids(self):
return set(self.sensors.keys())
Expand Down Expand Up @@ -61,14 +61,14 @@ def state_transition(self, action, execute=True, robot_id=None):
next_state = copy.deepcopy(self.state)
next_state.object_states[robot_id] =\
self.transition_model[robot_id].sample(self.state, action)

reward = self.reward_model.sample(self.state, action, next_state,
robot_id=robot_id)
if execute:
self.apply_transition(next_state)
return reward
else:
return next_state, reward
return next_state, reward

#### Interpret string as an initial world state ####
def interpret(worldstr):
Expand All @@ -77,30 +77,30 @@ def interpret(worldstr):
and returns the corresponding MosEnvironment.
For example: This string
.. code-block:: text
rx...
.x.xT
.....
***
r: laser fov=90 min_range=1 max_range=10
describes a 3 by 5 world where x indicates obsticles and T indicates
the "target object". T could be replaced by any upper-case letter A-Z
which will serve as the object's id. Lower-case letters a-z (except for x)
serve as id for robot(s).
After the world, the :code:`***` signals description of the sensor for each robot.
For example "r laser 90 1 10" means that robot `r` will have a Laser2Dsensor
with fov 90, min_range 1.0, and max_range of 10.0.
with fov 90, min_range 1.0, and max_range of 10.0.
Args:
worldstr (str): a string that describes the initial state of the world.
Returns:
MosEnvironment: the corresponding environment for the world description.
"""
worldlines = []
sensorlines = []
Expand All @@ -115,11 +115,11 @@ def interpret(worldstr):
worldlines.append(line)
if mode == "sensor":
sensorlines.append(line)

lines = [line for line in worldlines
if len(line) > 0]
w, l = len(worldlines[0]), len(worldlines)

objects = {} # objid -> object_state(pose)
obstacles = set({}) # objid
robots = {} # robot_id -> robot_state(pose)
Expand All @@ -137,12 +137,12 @@ def interpret(worldstr):
objid = 1000 + len(obstacles) # obstacle id
objects[objid] = ObjectState(objid, "obstacle", (x,y))
obstacles.add(objid)

elif c.isupper():
# target object
objid = len(objects)
objects[objid] = ObjectState(objid, "target", (x,y))

elif c.islower():
# robot
robot_id = interpret_robot_id(c)
Expand All @@ -162,15 +162,15 @@ def interpret(worldstr):
robot_name = line.split(":")[0].strip()
robot_id = interpret_robot_id(robot_name)
assert robot_id in robots, "Sensor specified for unknown robot %s" % (robot_name)

sensor_setting = line.split(":")[1].strip()
sensor_type = sensor_setting.split(" ")[0].strip()
sensor_params = {}
for token in sensor_setting.split(" ")[1:]:
param_name = token.split("=")[0].strip()
param_value = eval(token.split("=")[1].strip())
sensor_params[param_name] = param_value

if sensor_type == "laser":
sensor = Laser2DSensor(robot_id, **sensor_params)
elif sensor_type == "proximity":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
import numpy as np
import random
import pomdp_py.utils as util
from pomdp_problems.multi_object_search.env.env import *
from pomdp_problems.multi_object_search.domain.observation import *
from pomdp_problems.multi_object_search.domain.action import *
from pomdp_problems.multi_object_search.domain.state import *
from pomdp_problems.multi_object_search.example_worlds import *
from pomdp_py.problems.multi_object_search.env.env import *
from pomdp_py.problems.multi_object_search.domain.observation import *
from pomdp_py.problems.multi_object_search.domain.action import *
from pomdp_py.problems.multi_object_search.domain.state import *
from pomdp_py.problems.multi_object_search.example_worlds import *

# Deterministic way to get object color
def object_color(objid, count):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Optional grid map to assist collision avoidance during planning."""

from pomdp_problems.multi_object_search.models.transition_model import RobotTransitionModel
from pomdp_problems.multi_object_search.domain.action import *
from pomdp_problems.multi_object_search.domain.state import *
from pomdp_py.problems.multi_object_search.models.transition_model import RobotTransitionModel
from pomdp_py.problems.multi_object_search.domain.action import *
from pomdp_py.problems.multi_object_search.domain.state import *

class GridMap:
"""This map assists the agent to avoid planning invalid
Expand All @@ -15,7 +15,7 @@ def __init__(self, width, length, obstacles):
obstacles (dict): Map from objid to (x,y); The object is
supposed to be an obstacle.
width (int): width of the grid map
length (int): length of the grid map
length (int): length of the grid map
"""
self.width = width
self.length = length
Expand All @@ -29,7 +29,7 @@ def __init__(self, width, length, obstacles):
}
# set of obstacle poses
self.obstacle_poses = set({self._obstacles[objid]
for objid in self._obstacles})
for objid in self._obstacles})

def valid_motions(self, robot_id, robot_pose, all_motion_actions):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import math
import numpy as np
from pomdp_problems.multi_object_search.domain.action import *
from pomdp_problems.multi_object_search.domain.observation import *
from pomdp_py.problems.multi_object_search.domain.action import *
from pomdp_py.problems.multi_object_search.domain.observation import *

# Note that the occlusion of an object is implemented based on
# whether a beam will hit an obstacle or some other object before
Expand Down
Loading

0 comments on commit 0fe9bdb

Please sign in to comment.