code: def extend_children(children):
      
      new_children = copy(children)
      need_recursion = False
      dtrm_children = set()
  
      for child in children:
          if isinstance(child, Deterministic):
              new_children |= child.children
              dtrm_children.add(child)
              need_recursion = True
  
      new_children -= dtrm_children
  
      if need_recursion:
          new_children = extend_children(new_children)
  
      return new_children
docs: extend_children(children)
  
      Returns a set containing
      nearest conditionally stochastic (Stochastic, not Deterministic) descendants.