code: def _choose_correct_port(from_port, to_port):
      
      # First we try matching the two 'up' ports.
      T1 = _create_equivalence_transform([(from_port['up'], to_port['up'])])
      new_position = T1.apply_to(np.array(from_port.anchor.pos, ndmin=2))
  
      dist_between_anchors_up_up = norm(new_position[0] - to_port.anchor.pos)
  
      # Then matching a 'down' with an 'up' port.
      T2 = _create_equivalence_transform([(from_port['down'], to_port['up'])])
      new_position = T2.apply_to(np.array(from_port.anchor.pos, ndmin=2))
  
      # Determine which transform places the anchors further away from each other.
      dist_between_anchors_down_up = norm(new_position[0] - to_port.anchor.pos)
      difference_between_distances = dist_between_anchors_down_up - dist_between_anchors_up_up
  
      if difference_between_distances > 0:
          correct_port = from_port['down']
          T = T2
      else:
          correct_port = from_port['up']
          T = T1
      return [(correct_port, to_port['up'])], T
docs: Chooses the direction when using an equivalence transform on two Ports.
  
      Each Port object actually contains 2 sets of 4 atoms, either of which can be
      used to make a connection with an equivalence transform. This function
      chooses the set of 4 atoms that makes the anchor atoms not overlap which is
      the intended behavior for most use-cases.
  
      TODO: -Increase robustness for cases where the anchors are a different
             distance from their respective ports.
            -Provide options in `force_overlap` to override this behavior.
  
      Parameters
      ----------
      from_port : mb.Port
      to_port : mb.Port
  
      Returns
      -------
      equivalence_pairs : tuple of Ports, shape=(2,)
          Technically, a tuple of the Ports' sub-Compounds ('up' or 'down')
          that are used to make the correct connection between components.