def apply_recursively(
    parent_component: component.Component,
    function_name: str,
    function_arg: str | None = None,
    concurrent_child_calls: bool = False,
) -> None:
  """Recursively applies a function to each component in a tree of components.

  Args:
    parent_component: the component to apply the function to.
    function_name: the name of the function to apply.
    function_arg: the argument to pass to the function.
    concurrent_child_calls: whether to call the function on child components
      concurrently.
  """
  if concurrent_child_calls:
    concurrency.run_tasks({
        f'{child_component.name}.{function_name}': functools.partial(
            apply_recursively,
            parent_component=child_component,
            function_name=function_name,
            function_arg=function_arg,
            concurrent_child_calls=concurrent_child_calls,
        )
        for child_component in parent_component.get_components()
    })
  else:
    for child_component in parent_component.get_components():
      apply_recursively(
          parent_component=child_component,
          function_name=function_name,
          function_arg=function_arg,
      )

  if function_arg is None:
    getattr(parent_component, function_name)()
  else:
    getattr(parent_component, function_name)(function_arg)
Recursively applies a function to each component in a tree of components.

  Args:
    parent_component: the component to apply the function to.
    function_name: the name of the function to apply.
    function_arg: the argument to pass to the function.
    concurrent_child_calls: whether to call the function on child components
      concurrently.
  
concordia/utils/helper_functions.py