code: def generate_trials(
      trial_config=None, statuses=None, exp_config=None, max_attemtps=50
  ):
      """Generate Trials with different configurations"""
      if trial_config is None:
          trial_config = base_trial
  
      if statuses is None:
          statuses = all_status
  
      def _generate(obj, *args, value):
          if obj is None:
              return None
  
          obj = copy.deepcopy(obj)
          data = obj
  
          data[args[-1]] = value
          return obj
  
      new_trials = [
          _generate(trial_config, "status", value=s) for s in statuses
      ]
  
      for i, trial in enumerate(new_trials):
          trial[
              "submit_time"
          ] = datetime.datetime.utcnow() + datetime.timedelta(seconds=i)
          if trial["status"] != "new":
              trial[
                  "start_time"
              ] = datetime.datetime.utcnow() + datetime.timedelta(
                  seconds=i
              )
  
      for i, trial in enumerate(new_trials):
          if trial["status"] == "completed":
              trial[
                  "end_time"
              ] = datetime.datetime.utcnow() + datetime.timedelta(
                  seconds=i
              )
  
      if exp_config:
          space = SpaceBuilder().build(exp_config["space"])
      else:
          space = SpaceBuilder().build({"x": "uniform(0, 200)"})
  
      # make each trial unique
      sampled = set()
      i = 0
      for trial in new_trials:
          if trial["status"] == "completed":
              trial["results"].append(
                  {"name": "loss", "type": "objective", "value": i}
              )
  
          trial_stub = space.sample(seed=i)[0]
          attempts = 0
          while trial_stub.id in sampled and attempts < max_attemtps:
              trial_stub = space.sample(seed=i)[0]
              attempts += 1
              i += 1
  
          if attempts >= max_attemtps:
              raise RuntimeError(
                  f"Cannot sample unique trials in less than {max_attemtps}"
              )
  
          sampled.add(trial_stub.id)
          trial["params"] = trial_stub.to_dict()["params"]
  
      return new_trials
  
imports: import contextlib
  import copy
  import datetime
  import os
  from contextlib import contextmanager
  from falcon import testing
  import orion.algo.space
  import orion.core.io.experiment_builder
  from orion.core.io.space_builder import SpaceBuilder
  from orion.core.worker.producer import Producer
  from orion.serving.webapi import WebApi
  from orion.testing.state import OrionState
label_desc: Use image node_id 2 for calling a global function with example usage: generate_trials(trial_config, statuses, exp_config, max_attemtps) and returns: new_trials, obj, None