code: def _get_optimization_history_info_list(
      study: Study | Sequence[Study],
      target: Callable[[FrozenTrial], float] | None,
      target_name: str,
      error_bar: bool,
  ) -> list[_OptimizationHistoryInfo]:
      _check_plot_args(study, target, target_name)
      if isinstance(study, Study):
          studies = [study]
      else:
          studies = list(study)
  
      info_list: list[_OptimizationHistoryInfo] = []
      for study in studies:
          trials = study.get_trials()
          label_name = (
              target_name
              if len(studies) == 1
              else f"{target_name} of {study.study_name}"
          )
          values = []
          value_states = []
          for trial in trials:
              if trial.state != TrialState.COMPLETE:
                  values.append(float("nan"))
                  value_states.append(_ValueState.Incomplete)
                  continue
              constraints = trial.system_attrs.get(_CONSTRAINTS_KEY)
              if constraints is None or all(
                  [x <= 0.0 for x in constraints]
              ):
                  value_states.append(_ValueState.Feasible)
              else:
                  value_states.append(_ValueState.Infeasible)
              if target is not None:
                  values.append(target(trial))
              else:
                  values.append(cast(float, trial.value))
          if target is not None:
              # We don't calculate best for user-defined target function since we cannot tell
              # which direction is better.
              best_values_info: _ValuesInfo | None = None
          else:
              feasible_best_values = []
              if study.direction == StudyDirection.MINIMIZE:
                  feasible_best_values = [
                      v if s == _ValueState.Feasible else float("inf")
                      for v, s in zip(values, value_states)
                  ]
                  best_values = list(
                      np.minimum.accumulate(feasible_best_values)
                  )
              else:
                  feasible_best_values = [
                      v if s == _ValueState.Feasible else -float("inf")
                      for v, s in zip(values, value_states)
                  ]
                  best_values = list(
                      np.maximum.accumulate(feasible_best_values)
                  )
              best_label_name = (
                  "Best Value"
                  if len(studies) == 1
                  else f"Best Value of {study.study_name}"
              )
              best_values_info = _ValuesInfo(
                  best_values, None, best_label_name, value_states
              )
          info_list.append(
              _OptimizationHistoryInfo(
                  trial_numbers=[t.number for t in trials],
                  values_info=_ValuesInfo(
                      values, None, label_name, value_states
                  ),
                  best_values_info=best_values_info,
              )
          )
  
      if len(info_list) == 0:
          _logger.warning("There are no studies.")
  
      feasible_trial_count = sum(
          info.values_info.states.count(_ValueState.Feasible)
          for info in info_list
      )
      infeasible_trial_count = sum(
          info.values_info.states.count(_ValueState.Infeasible)
          for info in info_list
      )
      if feasible_trial_count + infeasible_trial_count == 0:
          _logger.warning("There are no complete trials.")
          info_list.clear()
  
      if not error_bar:
          return info_list
  
      # When error_bar=True, a list of 0 or 1 element is returned.
      if len(info_list) == 0:
          return []
      if feasible_trial_count == 0:
          _logger.warning("There are no feasible trials.")
          return []
  
      all_trial_numbers = [
          number for info in info_list for number in info.trial_numbers
      ]
      max_num_trial = max(all_trial_numbers) + 1
  
      def _aggregate(
          label_name: str, use_best_value: bool
      ) -> tuple[list[int], _ValuesInfo]:
          # Calculate mean and std of values for each trial number.
          values: list[list[float]] = [[] for _ in range(max_num_trial)]
          states: list[list[_ValueState]] = [
              [] for _ in range(max_num_trial)
          ]
          assert info_list is not None
          for trial_numbers, values_info, best_values_info in info_list:
              if use_best_value:
                  assert best_values_info is not None
                  values_info = best_values_info
              for n, v, s in zip(
                  trial_numbers, values_info.values, values_info.states
              ):
                  if not math.isinf(v):
                      if (
                          not use_best_value
                          and s == _ValueState.Feasible
                      ):
                          values[n].append(v)
                      elif use_best_value:
                          values[n].append(v)
                  states[n].append(s)
          trial_numbers_union: list[int] = []
          value_states: list[_ValueState] = []
          value_means: list[float] = []
          value_stds: list[float] = []
          for i in range(max_num_trial):
              if (
                  len(states[i]) > 0
                  and _ValueState.Feasible in states[i]
              ):
                  value_states.append(_ValueState.Feasible)
                  trial_numbers_union.append(i)
                  value_means.append(np.mean(values[i]).item())
                  value_stds.append(np.std(values[i]).item())
              else:
                  value_states.append(_ValueState.Infeasible)
          return trial_numbers_union, _ValuesInfo(
              value_means, value_stds, label_name, value_states
          )
  
      eb_trial_numbers, eb_values_info = _aggregate(target_name, False)
      eb_best_values_info: _ValuesInfo | None = None
      if target is None:
          _, eb_best_values_info = _aggregate("Best Value", True)
      return [
          _OptimizationHistoryInfo(
              eb_trial_numbers, eb_values_info, eb_best_values_info
          )
      ]
  
imports: from __future__ import annotations
  from collections.abc import Callable
  from collections.abc import Sequence
  from enum import Enum
  import math
  from typing import cast
  from typing import NamedTuple
  import numpy
  from optuna.logging import get_logger
  from optuna.samplers._base import _CONSTRAINTS_KEY
  from optuna.study import Study
  from optuna.study._study_direction import StudyDirection
  from optuna.trial import FrozenTrial
  from optuna.trial import TrialState
  from optuna.visualization._plotly_imports import _imports
  from optuna.visualization._utils import _check_plot_args
label_desc: Use image node_id 1 for calling a global function with example usage: _get_optimization_history_info_list(study, target, target_name, error_bar) and returns: list, info_list, list, list, trial_numbers_union,  _ValuesInfo