code: def trial_ls(args):
      """List trial"""
  
      def final_metric_data_cmp(lhs, rhs):
          metric_l = json.loads(
              json.loads(lhs["finalMetricData"][0]["data"])
          )
          metric_r = json.loads(
              json.loads(rhs["finalMetricData"][0]["data"])
          )
          if isinstance(metric_l, float):
              return metric_l - metric_r
          elif isinstance(metric_l, dict):
              return metric_l["default"] - metric_r["default"]
          else:
              print_error(
                  "Unexpected data format. Please check your data."
              )
              raise ValueError
  
      if args.head and args.tail:
          print_error("Head and tail cannot be set at the same time.")
          return
      experiments_config = Experiments()
      experiments_dict = experiments_config.get_all_experiments()
      experiment_id = get_config_filename(args)
      rest_port = experiments_dict.get(experiment_id).get("port")
      rest_pid = experiments_dict.get(experiment_id).get("pid")
      if not detect_process(rest_pid):
          print_error("Experiment is not running...")
          return
      running, response = check_rest_server_quick(rest_port)
      if running:
          response = rest_get(trial_jobs_url(rest_port), REST_TIME_OUT)
          if response and check_response(response):
              content = json.loads(response.text)
              if args.head:
                  assert (
                      args.head > 0
                  ), "The number of requested data must be greater than 0."
                  content = sorted(
                      filter(lambda x: "finalMetricData" in x, content),
                      key=cmp_to_key(final_metric_data_cmp),
                      reverse=True,
                  )[: args.head]
              elif args.tail:
                  assert (
                      args.tail > 0
                  ), "The number of requested data must be greater than 0."
                  content = sorted(
                      filter(lambda x: "finalMetricData" in x, content),
                      key=cmp_to_key(final_metric_data_cmp),
                  )[: args.tail]
              for index, value in enumerate(content):
                  content[index] = convert_time_stamp_to_date(value)
              print(
                  json.dumps(
                      content,
                      indent=4,
                      sort_keys=True,
                      separators=(",", ":"),
                  )
              )
              return content
          else:
              print_error("List trial failed...")
      else:
          print_error("Restful server is not running...")
      return None
  
imports: import csv
  import os
  import sys
  import json
  import time
  import shutil
  import subprocess
  from functools import cmp_to_key
  import traceback
  from datetime import datetime, timezone
  from subprocess import Popen
  from .rest_utils import rest_get, rest_delete, check_rest_server_quick, check_response
  from .url_utils import trial_jobs_url, experiment_url, trial_job_id_url, export_data_url, metric_data_url
  from .config_utils import Config, Experiments
  from .constants import NNI_HOME_DIR, EXPERIMENT_INFORMATION_FORMAT, EXPERIMENT_DETAIL_FORMAT, EXPERIMENT_MONITOR_INFO, TRIAL_MONITOR_HEAD, TRIAL_MONITOR_CONTENT, TRIAL_MONITOR_TAIL, REST_TIME_OUT
  from .common_utils import print_normal, print_error, print_warning, detect_process, get_yml_content, generate_temp_dir
  from .common_utils import print_green
  from .command_utils import check_output_command, kill_command
  from .ssh_utils import create_ssh_sftp_client, remove_remote_directory
label_desc: Use image node_id 11 for calling a global function with example usage: trial_ls(args) and returns: None, unknown, content, unknown