code: def _optimal_step_size(
      last_step, error_ratio, safety, ifactor, dfactor, order
  ):
      """Calculate the optimal size for the next step."""
      if error_ratio == 0:
          return last_step * ifactor
      if error_ratio < 1:
          dfactor = torch.ones(
              (), dtype=last_step.dtype, device=last_step.device
          )
      error_ratio = error_ratio.type_as(last_step)
      exponent = torch.tensor(
          order, dtype=last_step.dtype, device=last_step.device
      ).reciprocal()
      factor = torch.min(
          ifactor, torch.max(safety / error_ratio**exponent, dfactor)
      )
      return last_step * factor
  
imports: from enum import Enum
  import math
  import numpy
  import torch
  import warnings
  from .event_handling import combine_event_functions
label_desc: Use image node_id 8 for calling a global function with example usage: _optimal_step_size(last_step, error_ratio, safety, ifactor, dfactor, order) and returns: unknown, unknown