(physics, bricks, base_pos, base_quat, order, random_state)
Builds a stack of bricks.

  Args:
    physics: Instance of `mjcf.Physics`.
    bricks: Sequence of `composer.Entity` instances corresponding to bricks.
    base_pos: Position of the base brick in the stack; either a (3,) numpy array
      or a `variation.Variation` that yields such arrays.
    base_quat: Quaternion of the base brick in the stack; either a (4,) numpy
      array or a `variation.Variation` that yields such arrays.
    order: Sequence of indices specifying the order in which to stack the
      bricks.
    random_state: An `np.random.RandomState` instance.
Builds a stack of bricks.
Builds a stack of bricks .
def _build_stack(physics, bricks, base_pos, base_quat, order, random_state):
  """Builds a stack of bricks.

  Args:
    physics: Instance of `mjcf.Physics`.
    bricks: Sequence of `composer.Entity` instances corresponding to bricks.
    base_pos: Position of the base brick in the stack; either a (3,) numpy array
      or a `variation.Variation` that yields such arrays.
    base_quat: Quaternion of the base brick in the stack; either a (4,) numpy
      array or a `variation.Variation` that yields such arrays.
    order: Sequence of indices specifying the order in which to stack the
      bricks.
    random_state: An `np.random.RandomState` instance.
  """
  base_pos = variation.evaluate(base_pos, random_state=random_state)
  base_quat = variation.evaluate(base_quat, random_state=random_state)
  bricks[order[0]].set_pose(physics, position=base_pos, quaternion=base_quat)
  for bottom_idx, top_idx in zip(order[:-1], order[1:]):
    bottom = bricks[bottom_idx]
    top = bricks[top_idx]
    stud_pos = physics.bind(bottom.studs[0, 0]).xpos
    _, quat = bottom.get_pose(physics)
    # The reward function treats top left -> top left and top left -> bottom
    # right configurations as identical, so the orientations of the bricks are
    # randomized so that 50% of the time the top brick is rotated 180 degrees
    # relative to the brick below.
    if random_state.rand() < 0.5:
      quat = quat.copy()
      axis = np.array([0., 0., 1.])
      angle = np.pi
      mjlib.mju_quatIntegrate(quat, axis, angle)
      hole_idx = (-1, -1)
    else:
      hole_idx = (0, 0)
    top.set_pose(physics, quaternion=quat)

    # Set the position of the top brick so that its holes line up with the studs
    # of the brick below.
    offset = physics.bind(top.holes[hole_idx]).xpos
    top_pos = stud_pos - offset
    top.set_pose(physics, position=top_pos)
def _build_stack ( physics , bricks , base_pos , base_quat , order , random_state ) : base_pos = variation . evaluate ( base_pos , random_state = random_state ) base_quat = variation . evaluate ( base_quat , random_state = random_state ) bricks [ order [ 0 ] ] . set_pose ( physics , position = base_pos , quaternion = base_quat ) for bottom_idx , top_idx in zip ( order [ : - 1 ] , order [ 1 : ] ) : bottom = bricks [ bottom_idx ] top = bricks [ top_idx ] stud_pos = physics . bind ( bottom . studs [ 0 , 0 ] ) . xpos _ , quat = bottom . get_pose ( physics ) # The reward function treats top left -> top left and top left -> bottom # right configurations as identical, so the orientations of the bricks are # randomized so that 50% of the time the top brick is rotated 180 degrees # relative to the brick below. if random_state . rand ( ) < 0.5 : quat = quat . copy ( ) axis = np . array ( [ 0. , 0. , 1. ] ) angle = np . pi mjlib . mju_quatIntegrate ( quat , axis , angle ) hole_idx = ( - 1 , - 1 ) else : hole_idx = ( 0 , 0 ) top . set_pose ( physics , quaternion = quat ) # Set the position of the top brick so that its holes line up with the studs # of the brick below. offset = physics . bind ( top . holes [ hole_idx ] ) . xpos top_pos = stud_pos - offset top . set_pose ( physics , position = top_pos )