code: def vectorize_env(
      env_factory: Callable[..., gym.Env],
      env_type: FiniteEnvType,
      concurrency: int,
      logger: LogWriter | List[LogWriter],
  ) -> FiniteVectorEnv:
      """Helper function to create a vector env. Can be used to replace usual VectorEnv.
  
      For example, once you wrote: ::
  
          DummyVectorEnv([lambda: gym.make(task) for _ in range(env_num)])
  
      Now you can replace it with: ::
  
          finite_env_factory(lambda: gym.make(task), "dummy", env_num, my_logger)
  
      By doing such replacement, you have two additional features enabled (compared to normal VectorEnv):
  
      1. The vector env will check for NaN observation and kill the worker when its found.
         See :class:`FiniteVectorEnv` for why we need this.
      2. A logger to explicit collect logs from environment workers.
  
      Parameters
      ----------
      env_factory
          Callable to instantiate one single ``gym.Env``.
          All concurrent workers will have the same ``env_factory``.
      env_type
          dummy or subproc or shmem. Corresponding to
          `parallelism in tianshou <https://tianshou.readthedocs.io/en/master/api/tianshou.env.html#vectorenv>`_.
      concurrency
          Concurrent environment workers.
      logger
          Log writers.
  
      Warnings
      --------
      Please do not use lambda expression here for ``env_factory`` as it may create incorrectly-shared instances.
  
      Don't do: ::
  
          vectorize_env(lambda: EnvWrapper(...), ...)
  
      Please do: ::
  
          def env_factory(): ...
          vectorize_env(env_factory, ...)
      """
      env_type_cls_mapping: Dict[str, Type[FiniteVectorEnv]] = {
          "dummy": FiniteDummyVectorEnv,
          "subproc": FiniteSubprocVectorEnv,
          "shmem": FiniteShmemVectorEnv,
      }
  
      finite_env_cls = env_type_cls_mapping[env_type]
  
      return finite_env_cls(
          logger, [env_factory for _ in range(concurrency)]
      )
  
imports: from __future__ import annotations
  import copy
  import warnings
  from contextlib import contextmanager
  from typing import Any, Callable, Dict, Generator, List, Optional, Set, Tuple, Type, Union, cast
  import gym
  import numpy
  from tianshou.env import BaseVectorEnv, DummyVectorEnv, ShmemVectorEnv, SubprocVectorEnv
  from qlib.typehint import Literal
  from .log import LogWriter
label_desc: Use image node_id 5 for calling a global function with example usage: vectorize_env(env_factory, env_type, concurrency, logger) and returns: finite_env_cls