Skip to content

SymSkill: Symbol and Skill Co-Invention for Data-Efficient and Real-Time Long-Horizon Manipulation

License

Notifications You must be signed in to change notification settings

shaoyifei96/Symskill

Repository files navigation

SymSkill

demo_3_tasks

SymSkill Intsallation Instructions

  1. conda create -c conda-forge -n task_plan_casa_pub python=3.10 && conda activate task_plan_casa_pub
  2. Create a workspace folder. Clone and install robosuite, robocasa, ds_policy(this has further instructions for installation), Symskill (this repo, the python package is called predicators) in sequence, using pip install -e . in each folder, make sure all 4 packages are in the same folder.
  3. cd to robocasa and then download the kitchen assets by running the following commands:
python robocasa/scripts/download_kitchen_assets.py   # Caution: Assets to be downloaded are around 5GB.
python robocasa/scripts/setup_macros.py              # Set up system variables.
  1. put export PYTHONHASHSEED=0 in .bashrc
  2. To save some time, the demos can be predownloaded. clone repo into the workspace folder, you need to also request the license for mosek and put it in /home/$USER/mosek/mosek.lic
  3. In Symskill repo, there is a launch.json file, create a .vscode folder and copy the json file to the folder, change the path of the conda env and then run debug profile Debug Symskill Predicate Invention, you should see an cheese from the counter and put it in the cabinet. (you may need a latex installation for some plot outputs)

Deprecated Instructions for Symskill Predicate Invention

  1. To save some time, the demos can be predownloaded. Make sure you have the datasets downloaded url or repo , in the project folder, one folder above the predicators_robocasa folder (These datasets can also be generated by turning off CFG.robo_kitchen_load_dataset in settings.py, but it takes a while to generate)
  2. Clear the saved_approach folder if there is one. Learn each task one by one, starting with the first one in sequence (setting CFG.robo_kitchen_task to OpenSingleDoor, PnPCounterToCab, CloseSingleDoor), make sure CFG.use_learnt_goal_predicates is True, and --load_approach in Debug Grammer Search Invention launch file is not included. Then learn the OpenSingleDoor a second time, so it takes CloseSingleDoor goal predicate into account during learning.
  3. Set the task to StoreFruit (set the goal so that 2 tasks can be performed in a row), enable --load_approach flag now, and it should be able to first open the door, then pick the cheese on the counter in the cabinet.
  4. Set the task to StoreFruitFull (set the goal so that 3 tasks can be performed in a row), enable --load_approach flag now, and it should be able to first open the door, then pick the cheese on the counter in the cabinet, then close the door. The door closing part is not perfect, and the robot usually meets kinematic constraints in trying to close the door. I think a mobile platform is needed to reduce that problem.

How to test SymSkill code

Before refactoring code, copy files in results/ and paste to a new folder sym_skill_base_results/. These are base log files used for verification. After refactoring code, run pytest predicators_robocasa/tests/test_sym_skill.py.

predicators_robocasa/tests/test_sym_skill.py effectively compare results from new log files with base log files. You can also add more tests in test_main() function.

Learning Predicates for RoboCasa

Robocasa is a mujoco based simulator. For each task, it provides 50 demonstrations, which can be used to learn to plan. This is the same as as in this paper Learning Neuro-Symbolic Skills for Bilevel Planning, where the appendix explored the possibility of using demonstrations to a set of predicates first, by starting with the goal predicates. We are going to approach this problem in a similar way, with high sample efficiency and guaranteed low level action.

  1. Defined the goal predicates for each task (starting with OpenSingleDoor). We can get these from the definition of tasks in each single stage ones. They need to be evaluated, with one of the following approaches: 1) evaluate the predicates during demo loading, since we have the simulator reset to the state, evaluating them is easy. 2) save the relevant states in the state variable, and use the abstract function as intended. The advantage is during predicate invention, we can use the state to evaluate new predicates.
  2. Currently, the InContact is done with approach 1) since it is difficult to evaluate them online given each object has different mesh. Other predicates need to be evaluated online during planning and sampling, going to implement with apporoach 2). The values that need to go from mujoco state to predicator state are: 1) button states (coffee, microwave) 2) knob angle 3) faucet state (can be continuous or already in predicate form on/off, left/right) 4) door and drawer state 5) spatial relationship (in contact, not in contact) 6) position and orientation of the robot
  3. (Optionally) When inventing new predicates, keep InContact predicate since we are using that for trajectory segmentation anyway (TODO: Run Abalation including InContact and excluding InContact)
  4. Run Grammar Invention

Predicators

Repository Description

This codebase implements a framework for bilevel planning with learned neuro-symbolic relational abstractions, as described in the following papers:

  1. Learning Symbolic Operators for Task and Motion Planning. Silver*, Chitnis*, Tenenbaum, Kaelbling, Lozano-Perez. IROS 2021.
  2. Learning Neuro-Symbolic Relational Transition Models for Bilevel Planning. Chitnis*, Silver*, Tenenbaum, Lozano-Perez, Kaelbling. IROS 2022.
  3. Learning Neuro-Symbolic Skills for Bilevel Planning. Silver, Athalye, Tenenbaum, Lozano-Perez, Kaelbling. CoRL 2022.
  4. Predicate Invention for Bilevel Planning. Silver*, Chitnis*, Kumar, McClinton, Lozano-Perez, Kaelbling, Tenenbaum. AAAI 2023.
  5. Embodied Active Learning of Relational State Abstractions for Bilevel Planning. Li, Silver. CoLLAs 2023.
  6. Learning Efficient Abstract Planning Models that Choose What to Predict. Kumar*, McClinton*, Chitnis, Silver, Lozano-Perez, Kaelbling. CoRL 2023.

The codebase is still under active development. Please contact tslvr@mit.edu or njk@mit.edu before attempting to use it for your own research.

Code Structure

In predicators/, the environments are defined in the envs/ directory, and the approaches (both learning-based and not) are defined in the approaches/ directory. The core NSRT learning algorithm happens in predicators/nsrt_learning/nsrt_learning_main.py, which has the following steps:

  • Segment data.
  • Learn how many NSRTs we need, along with the symbolic operator components of each (parameters, preconditions, and effects).
  • Learn options and annotate data with them.
  • Learn samplers.
  • Finalize the NSRTs.

Methods for predicate learning are implemented as Approaches (e.g., predicators/approaches/grammar_search_invention_approach.py), and may interface with the core structure of predicators/nsrt_learning/nsrt_learning_main.py in various ways.

A simple implementation of search-then-sample bilevel planning is provided in predicators/planning.py. This implementation uses the "SeSamE" strategy: SEarch-and-SAMple planning, then Execution.

Installation

  • This repository uses Python versions 3.10-3.11. We recommend 3.10.14.
  • Run pip install -e . to install dependencies.

Instructions For Running Code

PYTHONHASHSEED

Our code assumes that python hashing is deterministic between processes, which is not true by default. Please make sure to export PYTHONHASHSEED=0 when running the code. You can add this line to your bash profile, or prepend export PYTHONHASHSEED=0 to any command line call, e.g., export PYTHONHASHSEED=0 python predicators/main.py --env ....

Locally

  • (recommended) Make a new virtual env or conda env.
  • Run, e.g., python predicators/main.py --env cover --approach oracle --seed 0 to run the system.

Running Experiments on Supercloud

See these instructions.

Instructions For Contributing

  • Run pip install -e .[develop] to install all dependencies for development.
  • You can't push directly to master. Make a new branch in this repository (don't use a fork, since that will not properly trigger the checks when you make a PR). When your code is ready for review, make a PR and request reviews from the appropriate people.
  • To merge a PR, you need at least one approval, and you have to pass the 4 checks defined in .github/workflows/predicators.yml, which you can run locally in one line via ./scripts/run_checks.sh, or individually as follows:
    • pytest -s tests/ --cov-config=.coveragerc --cov=predicators/ --cov=tests/ --cov-fail-under=100 --cov-report=term-missing:skip-covered --durations=0
    • mypy . --config-file mypy.ini
    • pytest . --pylint -m pylint --pylint-rcfile=.predicators_pylintrc
    • ./run_autoformat.sh
  • The first one is the unit testing check, which verifies that unit tests pass and that code is adequately covered. The "100" means that all lines in every file must be covered.
  • The second one is the static typing check, which uses Mypy to verify type annotations. If it doesn't work due to import errors, try mypy -p predicators --config-file predicators/mypy.ini from one directory up.
  • The third one is the linter check, which runs Pylint with the custom config file .predicators_pylintrc in the root of this repository. Feel free to edit this file as necessary.
  • The fourth one is the autoformatting check, which uses the custom config files .style.yapf and .isort.cfg in the root of this repository.

About

SymSkill: Symbol and Skill Co-Invention for Data-Efficient and Real-Time Long-Horizon Manipulation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 24

Languages