Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete planning solving example #43

Closed
inpefess opened this issue Aug 11, 2024 · 2 comments
Closed

Complete planning solving example #43

inpefess opened this issue Aug 11, 2024 · 2 comments

Comments

@inpefess
Copy link

inpefess commented Aug 11, 2024

Part of a JOSS review openjournals/joss-reviews#6468 There is an example of solving a planning problem in ReadMe (https://github.com/IRLL/HierarchyCraft?tab=readme-ov-file#as-a-upf-problem-for-planning) but it's incomplete. For example, when I try adding proposed lines:

problem = env.planning_problem()
problem.solve()

to Minecraft example (https://github.com/IRLL/HierarchyCraft?tab=readme-ov-file#using-the-programmatic-interface) nothing really happens. Moreover, if I try using the plan as suggested in the documentation https://irll.github.io/HierarchyCraft/hcraft/planning.html, it fails with an error (probably because no plan was built):

SequentialPlan:
Traceback (most recent call last):
  File "hcraft-review/venv/lib/python3.12/site-packages/hcraft/env.py", line 402, in step
    action = int(action)
             ^^^^^^^^^^^
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'

Could you please complete the example to get started with solving the planning problem based on Minecraft environment?

@MathisFederico
Copy link
Collaborator

MathisFederico commented Aug 19, 2024

By default, the MineHcraft environment has no goal, as such any plan built will be trivially empty, this is why the action given was None.

I've added a UserWarning if building a planning problem from and environment without goal.

I've updated the documentation to make everything more clear both in the README and in the planning documentation itself.

If you really want to use the MineHCraft example, you can either set a purpose manually or use gym to make an env with predetermined purpose, for example:

import gym

from hcraft.env import HcraftEnv

env: HcraftEnv = gym.make("MineHcraft-Stone-v1")

# Make it into a unified planning problem
planning_problem = env.planning_problem()

# Solve the planning problem and show the plan
planning_problem.solve()
print(planning_problem.plan)

done = False
_observation = env.reset()
while not done:
    action = planning_problem.action_from_plan(env.state)
    if action is None:
        # Plan has ended, no action left
        done = True
        continue
    _observation, _reward, done, _ = env.step(action)

# Goal is achieved == purpose is terminated
if env.purpose.terminated:
    print("Success ! The plan worked in the actual environment !")
else:
    print("Failed ... Something when wrong with the plan.")

@inpefess tell me if you are satisfied and thus if the issue should be closed

@inpefess
Copy link
Author

Great! Now it looks good to me, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants