Task Difficulty Levels

This notebook demonstrates the different levels of difficulty for each of the construction tasks.

For further details, see the Documentation.

In [0]:
# Copyright 2020 DeepMind Technologies Limited
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#      http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# See the License for the specific language governing permissions and
# limitations under the License.


  1. From the root of this repository, run pip install .[demos] to install both dm_construction and extra dependencies needed to run this notebook.
  2. Install ffmpeg:
    • Cross-platform with Anaconda: conda install ffmpeg
    • Ubuntu: apt-get install ffmpeg
    • Mac with Homebrew: brew install ffmpeg

In [0]:
import matplotlib.pyplot as plt
import dm_construction

In [0]:
def show_difficulties(env_, difficulties=None):
  """Generate and plot episodes at each difficulty level."""
  if not difficulties:
    difficulties = range(0, env_.core_env.max_difficulty + 1)
  frames = []
  for difficulty in difficulties:
    _ = env_.reset(difficulty=difficulty, curriculum_sample=False)

  base_size = 5
  num_frames = len(frames)
  _, axes = plt.subplots(
      1, num_frames, squeeze=False, figsize=(base_size*num_frames, base_size))

  for i, rgb_observation in enumerate(frames):
    ax = axes[0, i]
    if isinstance(difficulties[i], str):
      ax.set_title("difficulty = {}".format(difficulties[i]))

Load Environments

First we will load a copy of each environment. We can reuse the same underlying Unity process for all of them, which makes loading a bit faster.

In [0]:
# Create a new Unity process. Use a higher res on the camera for nicer images.
unity_env = dm_construction.get_unity_environment(width=600, height=600)

# Create one copy of each environment.
envs = {}
env_names = [
    "marble_run", "covering_hard", "covering", "connecting", "silhouette"]
for task in env_names:
  envs[task] = dm_construction.get_environment(
      task, unity_environment=unity_env, curriculum_sample=None,


The difficulty levels of Silhouette involve increasing the number of targets, the number of obstacles, and the maximum height of the targets.

Generalization involves increasing the number of targets beyond what was seen during training.

In [0]:
# Curriculum difficulties.
show_difficulties(envs["silhouette"], difficulties=[0, 1, 2, 3])
show_difficulties(envs["silhouette"], difficulties=[4, 5, 6, 7])

In [0]:
# Generalization.
show_difficulties(envs["silhouette"], difficulties=["double_the_targets"])


The difficulty levels in Connecting involve increasing the number of obstacles, the number of layers of obstacles, and the height of the targets.

Generalization in connecting involves having mixed heights of the targets, or adding an additional layer of obstacles (and also increasing the height of the targets).

In [0]:
# Curriculum difficulties.
show_difficulties(envs["connecting"], difficulties=[0, 1, 2, 3, 4])
show_difficulties(envs["connecting"], difficulties=[5, 6, 7, 8, 9])

In [0]:
# Generalization.
show_difficulties(envs["connecting"], difficulties=["mixed_height_targets", "additional_layer"])


The difficulty levels in the Covering task involves increasing the number of obstacles and the maximum height of the obstacles.

In [0]:
# Curriculum difficulties.

Covering Hard

Like in Covering, the difficulty levels involve increasing the number of obstacles and the maximum height of the obstacles.

In [0]:
# Curriculum difficulties.

Marble Run

The difficulty levels in Marble Run involve the distance between the ball and the goal, the number of obstacles, and the height of the target.

In [0]:
# Curriculum difficulties.
show_difficulties(envs["marble_run"], difficulties=[0, 1, 2, 3, 4])
show_difficulties(envs["marble_run"], difficulties=[5, 6, 7, 8])

Close Environments

The Unity environment won't get garbage collected since it is actually running as a separate process, so make sure to always shut down all environments after they are finished running.

In [0]:
for name, env in envs.items():
  print("Closing '{}'".format(name))

Closing 'marble_run'
Closing 'covering_hard'
Closing 'covering'
Closing 'connecting'
Closing 'silhouette'