code: def trial_from_json(
      experiment: core.experiment.Experiment,
      index: int,
      trial_type: Optional[str],
      status: TrialStatus,
      time_created: datetime,
      time_completed: Optional[datetime],
      time_staged: Optional[datetime],
      time_run_started: Optional[datetime],
      abandoned_reason: Optional[str],
      run_metadata: Optional[Dict[str, Any]],
      generator_run: GeneratorRun,
      runner: Optional[Runner],
      num_arms_created: int,
      # Allowing default values for backwards compatibility with
      # objects stored before these fields were added.
      failed_reason: Optional[str] = None,
      ttl_seconds: Optional[int] = None,
      generation_step_index: Optional[int] = None,
      properties: Optional[Dict[str, Any]] = None,
      stop_metadata: Optional[Dict[str, Any]] = None,
      **kwargs: Any,
  ) -> Trial:
      """Load Ax trial from JSON.
  
      Other classes don't need explicit deserializers, because we can just use
      their constructors (see decoder.py). However, the constructor for Trial
      does not allow us to exactly recreate an existing object.
      """
  
      trial = Trial(
          experiment=experiment,
          generator_run=generator_run,
          ttl_seconds=ttl_seconds,
      )
      trial._index = index
      trial._trial_type = trial_type
      # Swap `DISPATCHED` for `RUNNING`, since `DISPATCHED` is deprecated and nearly
      # equivalent to `RUNNING`.
      trial._status = (
          status
          if status != TrialStatus.DISPATCHED
          else TrialStatus.RUNNING
      )
      trial._time_created = time_created
      trial._time_completed = time_completed
      trial._time_staged = time_staged
      trial._time_run_started = time_run_started
      trial._abandoned_reason = abandoned_reason
      trial._failed_reason = failed_reason
      trial._run_metadata = run_metadata or {}
      trial._stop_metadata = stop_metadata or {}
      trial._runner = runner
      trial._num_arms_created = num_arms_created
      trial._generation_step_index = generation_step_index
      trial._properties = properties or {}
      warn_on_kwargs(callable_with_kwargs=Trial, **kwargs)
      return trial
  
imports: from __future__ import annotations
  import inspect
  import logging
  from datetime import datetime
  from pathlib import Path
  from typing import Any, Dict, Iterable, List, Optional, Type, TYPE_CHECKING, Union
  import torch
  from ax.core.arm import Arm
  from ax.core.base_trial import TrialStatus
  from ax.core.batch_trial import AbandonedArm, BatchTrial, GeneratorRunStruct
  from ax.core.generator_run import GeneratorRun
  from ax.core.runner import Runner
  from ax.core.trial import Trial
  from ax.exceptions.storage import JSONDecodeError
  from ax.modelbridge.transforms.base import Transform
  from ax.storage.botorch_modular_registry import CLASS_TO_REVERSE_REGISTRY, REVERSE_INPUT_TRANSFORM_REGISTRY, REVERSE_OUTCOME_TRANSFORM_REGISTRY
  from ax.storage.transform_registry import REVERSE_TRANSFORM_REGISTRY
  from ax.utils.common.kwargs import warn_on_kwargs
  from ax.utils.common.logger import get_logger
  from ax.utils.common.typeutils import checked_cast
  from ax.utils.common.typeutils_torch import torch_type_from_str
  from botorch.models.transforms.input import ChainedInputTransform, InputTransform
  from botorch.models.transforms.outcome import ChainedOutcomeTransform, OutcomeTransform
label_desc: Use image node_id 2 for calling a global function with example usage: trial_from_json(experiment, index, trial_type, status, time_created, time_completed, time_staged, time_run_started, abandoned_reason, run_metadata, generator_run, runner, num_arms_created, failed_reason, ttl_seconds, generation_step_index, properties, stop_metadata) and returns: trial