Code Monkey home page Code Monkey logo

phyre's Introduction

GitHub license CircleCI

PHYRE is a benchmark for physical reasoning.

It provides a set of physics puzzles in a simulated 2D world. Each puzzle has a goal state (e.g., make the green ball touch the blue wall) and an initial state in which the goal is not satisfied (see the figure below). A puzzle can be solved by placing one or more new bodies in the environment such that when the physical simulation is run the goal is satisfied. An agent playing this game must solve previously unseen puzzles in as few attempts as possible.

phyre

How to use the PHYRE

Phyre framework could be used for several tasks related to physical reasoning.

  • As a benchmark: Phyre allows to evaluate different reasoning agents on a predefined set of tasks and complexity tiers. You can explore the tasks and try to solve them using the demo.
  • As a task building platform: Phyre contains a framework to create new levels with goals and objects from a way richer set that one used in the standard tiers. This could be used to study specific types of generalization for reasoning agents, performance or forward modelling, or something else, e.g., enable reasoning about physics in natural language. See this doc for details.
  • As an interface to a fast physical engine: Phyre uses Box2d engine under the hood. In the benchmark we hide all details of the simulation. See this doc for details on low level interface.

Getting started

Installation

The simplest way to install PHYRE is via pip. As PHYRE requires Python version 3.6, we recommend installing PHYRE inside a virtual environment, e.g. using Conda.

We provide PHYRE as a pip package for both Linux and Mac OS.

conda create -n phyre python=3.6 && conda activate phyre
pip install phyre

To check that the installation was successful, run python -m phyre.server and open http://localhost:30303. That should start a local demo server.

For instructions on building PHYRE from source and installing in a Docker container, see INSTALLATION.

Notebooks

We provide jupyter notebooks that show how to use PHYRE API (open in Colab) to run simulations and evaluate a random agent and how to use simulation cache (open in Colab) to train agents faster.

Training an agent

We provide a set of baseline agents that are described in the paper. In order to run them, you need to install additional python dependencies with pip install -r requirements.agents.txt.

All the agents are located in agents/ folder. The entry point is train.py that will train an agent on specified eval setup with a specified fold. E.g., the following command will train a memoization agent:

python agents/train.py \
    --output-dir=results/ball_cross_template/0 \
    --eval-setup-name=ball_cross_template \
    --fold-id=0 \
    --mem-rerank-size 100 \
    --agent-type=memoize

File run_experiment.py contains groups of experiments, e.g, sweeping over number of update for DQN-O or training agents on all seeds and eval setups. And train_all_baseline.sh starts experiments to train all baseline algorithms in the paper.

License

PHYRE is released under the Apache license. See LICENSE for additional details.

Citation

If you use PHYRE in your experiments, please cite it:

@article{bakhtin2019phyre,
    title={PHYRE: A New Benchmark for Physical Reasoning},
    author={Anton Bakhtin and Laurens van der Maaten and Justin Johnson and Laura Gustafson and Ross Girshick},
    year={2019},
    journal={arXiv:1908.05656}
}

Related projects

Datasets

Virtual Tools is a similar project aiming to research the structure necessary to capture human-like reasoning in these sorts of physics puzzles.

ESPRIT is a framework based on PHYRE that connects physical reasoning and natural language explanations.

Models

Forward Prediction for Physical Reasoning uses forward-prediction models improve the performance of physical-reasoning agents, particularly on complex tasks that involve many objects.

Solving Physics Puzzles by Reasoning about Paths is a model for goal-driven tasks that requires intuitive physical reasoning and intervention in the scene to achieve a desired end goal.

phyre's People

Contributors

akhti avatar dependabot[bot] avatar eltayebahmed avatar lauragustafson avatar ndrwmlnk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

phyre's Issues

An error occurs in the tutorial colab file.

Hi.
I got an error when I ran the code block two of the tutorial colab file.

ImportError: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.26' not found (required by /usr/local/lib/python3.7/dist-packages/phyre/simulator_bindings.cpython-37m-x86_64-linux-gnu.so)

The error still occurs though I tried to add GLIBCXX_3.4.26.
I added the below scripts before the import scripts.

!add-apt-repository ppa:ubuntu-toolchain-r/test
!apt-get update
!apt-get install gcc-4.9
!apt-get upgrade libstdc++6

After that, I check the version of GLIBCXX.

!strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6 | grep GLIBCXX

GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBCXX_3.4.14
GLIBCXX_3.4.15
GLIBCXX_3.4.16
GLIBCXX_3.4.17
GLIBCXX_3.4.18
GLIBCXX_3.4.19
GLIBCXX_3.4.20
GLIBCXX_3.4.21
GLIBCXX_3.4.22
GLIBCXX_3.4.23
GLIBCXX_3.4.24
GLIBCXX_3.4.25
GLIBCXX_3.4.26
GLIBCXX_3.4.27
GLIBCXX_3.4.28
GLIBCXX_3.4.29
GLIBCXX_DEBUG_MESSAGE_LENGTH

I cannot fix the error though I confirmed GLIBCXX_3.4.26.
How do I fix it?

Python 3.8 Version

Hi there, I'm interested in using Phyre for a project that is in Python 3.8. I can easily pip install the package in a 3.6 env, but not a 3.8 env. Is there anything that would break in 3.8? Can the package be updated to handle this?

Possible problem with ball diameter

An action with diameter one ([0.45, 0.78, 1]) does not seem to result in placing a red ball with diameter one. The following code is an example and the simulation result is attached. How can I place a larger ball or is there a ball size limit in PHYRE?

import math
import phyre
import matplotlib.pyplot as plt

fold_id = 0 
eval_setup = 'ball_within_template'
train_tasks, dev_tasks, test_tasks = phyre.get_fold(eval_setup, fold_id)
action_tier = phyre.eval_setup_to_action_tier(eval_setup)
simulator = phyre.initialize_simulator(['00005:174'], action_tier)

initial_featurized_objects = simulator.initial_featurized_objects[0]
initial_scene = simulator.initial_scenes[0]
simulation = simulator.simulate_action(0, [0.45, 0.78, 1], need_images=True, need_featurized_objects=True)

num_across = 5
height = int(math.ceil(len(simulation.images) / num_across))
fig, axs = plt.subplots(height, num_across, figsize=(20, 15))
fig.tight_layout()
plt.subplots_adjust(hspace=0.2, wspace=0.2)
for i, (ax, image) in enumerate(zip(axs.flatten(), simulation.images)):
    img = phyre.observations_to_float_rgb(image)
    ax.imshow(img)
    ax.title.set_text(f'Timestep {i}')
    ax.get_xaxis().set_ticks([])
    ax.get_yaxis().set_ticks([])
plt.savefig(f'error.jpg')

error

ModuleNotFoundError: No module named 'phyre.interface'

Hi,
Thanks a lot for sharing the code!

I'm trying to import my local phyre module but encountered this error. It seems interface is an alias file and the file it points doesn't exist in the phyre directory.

Thanks for your help in advanced!

Possible Issue with refine_actions

In line 161 of neural_agent.py (in refine_actions), the cross entropy loss is calculated between the logits and a tensor of ones with length len(actions). Wouldn't it make more sense for the length to be len(action_batch)? In the present case, the code only runs without error if the values for the dqn-eval-batch-size and dqn-rank-size flags are equal.

static objects out of bound

Hi, there is a problem in sim.featurized_objects.features, there will be more objects than those we can see in the scene (some static objects are out of the 2-D scene bounding box in some tasks, e.g. Task: 00004:137)

Simulation with no action

Is there a way to run a simulation without taking any action and get the resulting images, similar to pressing "Simulate" in the demo without taking any action?

Missing "task_ids" in the two ball game cache.

Hi.
I finished running the one-ball game using DQN.
However, I got an error when I ran the two-ball game.

KeyError: '00100:000'

This error is thrown by phyre/src/python/phyre/simulation_cache.py.
Then, I checked the cache files (.cache/phyre/offline_simulation/100000/two_balls/simulation_cache.gz).
Consequently, .cache/phyre/offline_simulation/100000/two_balls/simulation_cache.gz did not include any keys of the python dictionary.

Is this bug?
Please teach me the solution.
Thanks.

The splitting to train val test sets and using them

Hi , I'm a bit confused about the usage in the validation and train sets.
First its bee said in the paper:"we use these tuned hyperparameter and train agents on the union of the training and validation sets", so, are you training on the validation set?
Second, in the code: https://github.com/facebookresearch/phyre/blob/master/agents/neural_agent.py#L36
There is a function "create_balanced_eval_set", but it's seems like preparing data for the training procedure.
I'm trying to understand the boundaries if any, of the train/val sets.
Thanks.

phyre.initialize_simulator() is too slow

Hi,

phyre.initialize_simulator() takes ~15 sec, no matter how many tasks we need, e.g. one task or all available tasks.

This is probably due to loading and unpacking of phyre/data/generated_tasks/tasks.bin.lzma
permalink

with lzma.open(path) as stream:
    collection = phyre.simulator.deserialize(task_if.TaskCollection(), stream.read())

while debugging our solver, this every time delay of ~15 sec becomes annoying.

Would you consider e.g., unpacking all the tasks for the first time of usage of PHYRE in a local folder, and loading unpacked tasks from the folder for every further execution of PHYRE? phyre.initialize_simulator() should take ~1 sec then.

Any other ideas/solutions?

Thanks!

Question about the DQN model

Hi, first I'd like to express my appreciation to your work, this kind of datasets really push ai forward.
I have one small question, I have difficult time to understand what is the relation between your DQN and a traditional DQN. I mean DQN gets a state and outputs what is the most probable action to take while your DQN already randomly sample an action and approximate the reward.

Please help me fill in the gap I have.
Thanks.

Fails to build with missing files

Phyre fails to build for a few reasons.

Using the HEAD of the repo, or the branch build-wheel-0.2.1, build fails with missing files:

(27028) cmake_build (main) $ CONDA_PREFIX=$EBROOTTHRIFT cmake .. -DCMAKE_PREFIX_PATH=$VIRTUAL_ENV/lib/python3.8/site-packages
(27028) cmake_build (main) $ make
...
[ 63%] Building CXX object CMakeFiles/thrift_task.dir/gen-cpp/scene_constants.cpp.o
c++: error:  phyre/cmake_build/gen-cpp/scene_constants.cpp: No such file or directory
c++: fatal error: no input files

It seems that the files are not generated from thrift -r --gen cpp phyre/src/if/task.thrift

Also, the README should properly document the required dependencies and how to build from source.
e.g. Boost, Thrift and Pybind11 are required.

Cross-template folds never contain template 6 in test or dev template sets (10 folds)

Hi,

we have a question about the baseline results for cross template cases (PHYRE paper, Table 1, PHYRE-B, DQN, Cross).

Do we understand correct that in each cross-template fold there are 16 training templates and the remaining 9 templates (dev, test) (link) are used for measuring the auccess?

We found that template 6 was never part of the test templates in the 10 cross-template folds provided in the baseline code (link to 'fold method'), thus, template 6 does not contribute to the final cross-template auccess value. Is this intended or that just happened to be?

Error when running 01_phyre_intro notebook

Hi, I am getting the following error when running cell [6]:

TypeError: render(): incompatible function arguments. The following argument types are supported:
1. (arg0: List[int]) -> List[int]
Screenshot_2021-01-17 phyre_intro - Jupyter Notebook

Ground truth object states

Is there an easy way to obtain non-pixel state information eg. (x,y,r) information, for each object? I'd like to use ground truth object information for early proof-of-concept experiments before working directly with pixels

Possible issue with simulate_single()

In action_simulator.py, line 238, the function simulate_single() ends with
return simulation.simulation_status, simulation.images
and I think it's should be corrected to
return simulation.status, simulation.images
since Simulation has now a status attribute and not simulation_status.

Thanks.

incorrect value/need clarification for sim.initial_featurized_objects[0].Xs and Ys

Hello,

In the task number 00018:007 and 00020:000 the value of X and Y for goal object (bar) is more than one. While the value in the other tasks seem to be in the range of [0,1]. The same is reflected if I try to draw using this value on a pix map.

May you clarify how to handle this data or provide a more refined location value for the objects.
Screenshot from 2020-07-06 23-04-26

object-based knowledge representation

Hi,

is it possible to get from the physics engine additional object-based information? For example:

  • objects' (x,y) positions for all time steps (trajectories of all dynamic objects)
  • objects' angles for all time steps
  • a list of interaction events between objects. For example a touch event between object 1 and object 2 at time step 150, at point x, y = 100, 200.

If it is not possible to get this information from the physics engine, could you consider to provide this information in a python variable? For example, the initial x y positions of all objects are already available in variables
simulator.initial_featurized_objects[0].xs and
simulator.initial_featurized_objects[0].ys

I may assume that this additional information is not in the primary focus of the benchmark, but it would benefit a broader community that takes into account object-based knowledge representation.

Thanks!

Migration Website to Docusaurus 2 Alpha

Hi there! The Docusaurus team is currently developing Docusaurus 2 and are almost done with an MVP that doesn't include translations and versioning features, which means there's feature parity with your website's current usage of Docusaurus.

Docusaurus 2 brings about many improvements:

  • Client-side rendering with prerendering (site renders without JavaScript!)
  • More flexible appearance - Customizable layouts, CSS modules, etc
  • Embeddable interactive React components within markdown via MDX

I will be your POC in helping you throughout the migration process. Let me know what you think!

cc @yangshun @endiliey

Unable to build from source

system:
Python: 3.9
thrift: 1.7.0

output:

[ 98%] Built target task_validation_test
/usr/bin/ld: /opt/conda/lib/libthrift.a(TBufferTransports.o): relocation R_X86_64_PC32 against symbol `_ZTVN6apache6thrift9transport19TTransportExceptionE' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
make[3]: *** [CMakeFiles/simulator_bindings.dir/build.make:95: ../src/python/phyre/simulator_bindings.cpython-39-x86_64-linux-gnu.so] Error 1
make[3]: Leaving directory '/home/v-zhichen/phyre/cmake_build'
make[2]: *** [CMakeFiles/Makefile2:575: CMakeFiles/simulator_bindings.dir/all] Error 2
make[2]: Leaving directory '/home/v-zhichen/phyre/cmake_build'
make[1]: *** [Makefile:141: all] Error 2
make[1]: Leaving directory '/home/v-zhichen/phyre/cmake_build'
make: *** [Makefile:27: compile] Error 2

Installing on Mac via pip limited to platform = macosx_10_0

I tried installing phyre locally on my Mac through pip and ran into some issues, which I believe stem from the fact that pypi servers only have wheels built under the assumption that Macs have --platform macosx_10_0_universal, and my computer only has support for 10_4 and above. This would not be a problem on Linux, which has the manylinux support.

Would it be possible to add wheels to pypi with more recent Mac platform support? Thanks!

The relevant output of my pip install -v phyre where it is searching the wheels is below:

image

installation from source failed

I just followed the instruction to install phyre from source, but I got make errors like this:

[ 83%] Building CXX object CMakeFiles/simulator_lib.dir/src/simulator/task_validation.cpp.o
/data/phyre/src/simulator/image_to_box2d.cpp: In function 'void featurizeBody(const scene::Body&, int, int, float*)':
/data/phyre/src/simulator/image_to_box2d.cpp:427:41: error: expected ',' before ')' token
static_assert(kObjectFeatureSize == 14);
^
/data/phyre/src/simulator/image_to_box2d.cpp:427:41: error: expected string-literal before ')' token
CMakeFiles/simulator_lib.dir/build.make:92: recipe for target 'CMakeFiles/simulator_lib.dir/src/simulator/image_to_box2d.cpp.o' failed
make[3]: *** [CMakeFiles/simulator_lib.dir/src/simulator/image_to_box2d.cpp.o] Error 1
make[3]: *** Waiting for unfinished jobs....
[ 84%] Linking CXX static library libgtest.a
make[3]: Leaving directory '/data/phyre/cmake_build'
[ 84%] Built target gtest
make[3]: Entering directory '/data/phyre/cmake_build'
Scanning dependencies of target gtest_main
make[3]: Leaving directory '/data/phyre/cmake_build'
make[3]: Entering directory '/data/phyre/cmake_build'
[ 85%] Building CXX object third-party/googletest/googlemock/gtest/CMakeFiles/gtest_main.dir/src/gtest_main.cc.o
[ 86%] Linking CXX static library libtask_io.a
make[3]: Leaving directory '/data/phyre/cmake_build'
make[3]: Leaving directory '/data/phyre/cmake_build'
CMakeFiles/Makefile2:691: recipe for target 'CMakeFiles/simulator_lib.dir/all' failed
make[2]: *** [CMakeFiles/simulator_lib.dir/all] Error 2
make[2]: *** Waiting for unfinished jobs....
[ 86%] Built target task_io
[ 87%] Linking CXX static library libgtest_main.a
make[3]: Leaving directory '/data/phyre/cmake_build'
[ 87%] Built target gtest_main
make[2]: Leaving directory '/data/phyre/cmake_build'
Makefile:157: recipe for target 'all' failed
make[1]: *** [all] Error 2
make[1]: Leaving directory '/data/phyre/cmake_build'
Makefile:27: recipe for target 'compile' failed
make: *** [compile] Error 2
Traceback (most recent call last):
File "", line 1, in
File "/data/phyre/src/python/setup.py", line 79, in
'License :: OSI Approved :: Apache Software License',
File "/opt/conda/envs/phyre/lib/python3.6/site-packages/setuptools/init.py", line 144, in setup
return distutils.core.setup(**attrs)
File "/opt/conda/envs/phyre/lib/python3.6/distutils/core.py", line 148, in setup
dist.run_commands()
File "/opt/conda/envs/phyre/lib/python3.6/distutils/dist.py", line 955, in run_commands
self.run_command(cmd)
File "/opt/conda/envs/phyre/lib/python3.6/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/opt/conda/envs/phyre/lib/python3.6/site-packages/setuptools/command/develop.py", line 38, in run
self.install_for_development()
File "/opt/conda/envs/phyre/lib/python3.6/site-packages/setuptools/command/develop.py", line 140, in install_for_development
self.run_command('build_ext')
File "/opt/conda/envs/phyre/lib/python3.6/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/opt/conda/envs/phyre/lib/python3.6/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/data/phyre/src/python/setup.py", line 45, in run
subprocess.check_call(command, cwd='../..')
File "/opt/conda/envs/phyre/lib/python3.6/subprocess.py", line 311, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['make', 'develop']' returned non-zero exit status 2.
----------------------------------------
ERROR: Command errored out with exit status 1: /opt/conda/envs/phyre/bin/python3.6 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/data/phyre/src/python/setup.py'"'"'; file='"'"'/data/phyre/src/python/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' develop --no-deps Check the logs for full command output.

How to solve it?
Thank you

Retrieving results from paper using run_experiment.py

Hi, I used run_experiment.py script in order the retrieve the results for dqn.
I used it the following:
python agents/run_experiment.py --use-test-split 1 --arg-generator base_dqn
I've got for the cross template the following scores:
Fold0 - 0.3587
Fold1 - 0.2079
Fold2 - 0.3287
Fold3 - 0.2956
Fold4 - 0.1978
Fold5 - 0.3928
Fold6 - 0.2538
Fold7 - 0.2892
Fold8 - 0.1529
Fold9 - 0.3756
The average is : 0.2853‬, which is lower from the results from the paper which is 36.8±9.7.

What I'm missing?

Thanks for your help.

How is the simulated video length related to the object states?

Hi, thanks for open-sourcing this great work. I have a question regarding the simulated video length. I went through several videos generated by

sim = simulator.simulate_action(task_id, act, stride=60, ...)
video = sim.images

The length of the generated videos varies a lot (seems to be from 6 to 18 or so). So I wonder how is the length determined? I look at the video, it seems that the video ends 3 seconds after the object-of-interest (green and blue/purple ones) come to stable states (e.g. stop moving and in contact)? Is this observation correct? Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.