class_docstr: A trainer for the DQN algorithm and its variants.
  
  Configures optimizers, builds the losses and train functions for the
  Q-learning based algorithm variants. Supports MaxQ and SARSA style
  TD-learning under both, standard and batch-constrained q-learning.
  During training, updates CPE metrics estimators.
  
  Attributes:
      double_q_learning: a boolean flag whether to use double-q learning.
      minibatch_size: an int number of samples per minibatch.
      minibatches_per_step: an int number of minibatch updates per step.
      q_network: a network object mapping states to q-values of all actions.
      q_network_target: a copy of q-network for training stability used in
          estimating q-values targets.
      q_network_optimizer: an optimizer object for training q-network.
      bcq: a config file for batch-constrained q-learning (BCQ).
      bcq_imitator: if using batch-constrained q-learning, the behavior
          policy used for BCQ training.
      all_action_scores: a torch tensor containing q-network
              predictions from the current states.
docstr: Args:
      q_network: states -> q-value for each action
      q_network_target: copy of q-network for training stability
      reward_network: states -> reward for each action
      q_network_cpe: states -> cpe q-values for each action
      q_network_cpe_target: copy of q_network_cpe for training stability
      metrics_to_score: a list of string reward metrics names.
      imitator (optional): The behavior policy, used for BCQ training
      actions: list of action names
      rl: RLParameters
      double_q_learning: boolean flag to use double-q learning
      bcq: a config file for batch-constrained q-learning, defaults to normal
      minibatch_size: samples per minibatch
      minibatches_per_step: minibatch updates per step
      optimizer: q-network optimizer
      evaluation: evaluation params, primarily whether to use CPE in eval or not
docstr_tok: ["Args",":","q_network",":","states","-",">","q-value","for","each","action","q_network_target",":","copy","of","q-network","for","training","stability","reward_network",":","states","-",">","reward","for","each","action","q_network_cpe",":","states","-",">","cpe","q-values","for","each","action","q_network_cpe_target",":","copy","of","q_network_cpe","for","training","stability","metrics_to_score",":","a","list","of","string","reward","metrics","names",".","imitator","(","optional",")",":","The","behavior","policy",",","used","for","BCQ","training","actions",":","list","of","action","names","rl",":","RLParameters","double_q_learning",":","boolean","flag","to","use","double-q","learning","bcq",":","a","config","file","for","batch-constrained","q-learning",",","defaults","to","normal","minibatch_size",":","samples","per","minibatch","minibatches_per_step",":","minibatch","updates","per","step","optimizer",":","q-network","optimizer","evaluation",":","evaluation","params",",","primarily","whether","to","use","CPE","in","eval","or","not"]
code: def __init__(
      self,
      q_network,
      q_network_target,
      reward_network,
      q_network_cpe=None,
      q_network_cpe_target=None,
      metrics_to_score=None,
      evaluation: EvaluationParameters = field(  # noqa: B008
          default_factory=EvaluationParameters
      ),
      imitator=None,
      # Start DQNTrainerParameters. All parameters above should be
      # in the blocklist for DQNTrainerParameters in parameters.py
      actions: List[str] = field(default_factory=list),  # noqa: B008
      rl: RLParameters = field(
          default_factory=RLParameters
      ),  # noqa: B008
      double_q_learning: bool = True,
      bcq: Optional[BCQConfig] = None,
      minibatch_size: int = 1024,
      minibatches_per_step: int = 1,
      optimizer: Optimizer__Union = field(  # noqa: B008
          default_factory=Optimizer__Union.default
      ),
  ) -> None:
      """
      Args:
          q_network: states -> q-value for each action
          q_network_target: copy of q-network for training stability
          reward_network: states -> reward for each action
          q_network_cpe: states -> cpe q-values for each action
          q_network_cpe_target: copy of q_network_cpe for training stability
          metrics_to_score: a list of string reward metrics names.
          imitator (optional): The behavior policy, used for BCQ training
          actions: list of action names
          rl: RLParameters
          double_q_learning: boolean flag to use double-q learning
          bcq: a config file for batch-constrained q-learning, defaults to normal
          minibatch_size: samples per minibatch
          minibatches_per_step: minibatch updates per step
          optimizer: q-network optimizer
          evaluation: evaluation params, primarily whether to use CPE in eval or not
      """
      super().__init__(
          rl,
          metrics_to_score=metrics_to_score,
          actions=actions,
          evaluation_parameters=evaluation,
      )
      assert (
          self._actions is not None
      ), "Discrete-action DQN needs action names"
      self.double_q_learning = double_q_learning
      self.minibatch_size = minibatch_size
      self.minibatches_per_step = minibatches_per_step or 1
  
      self.q_network = q_network
      self.q_network_target = q_network_target
      self.q_network_optimizer = optimizer
  
      self._initialize_cpe(
          reward_network,
          q_network_cpe,
          q_network_cpe_target,
          optimizer=optimizer,
      )
  
      # Batch constrained q-learning
      self.bcq = bcq is not None
      if self.bcq:
          assert bcq is not None
          self.bcq_drop_threshold = bcq.drop_threshold
          self.bcq_imitator = imitator
  
imports: import logging
  from typing import List, Optional, Tuple
  import reagent.core.types
  import torch
  from reagent.core.configuration import resolve_defaults
  from reagent.core.dataclasses import dataclass, field
  from reagent.core.parameters import EvaluationParameters, RLParameters
  from reagent.optimizer import Optimizer__Union, SoftUpdate
  from reagent.training.dqn_trainer_base import DQNTrainerBaseLightning
  from reagent.training.imitator_training import get_valid_actions_from_imitator
label_desc: Use image node_id 1 to create a new DQNTrainer object from inherited base classes: DQNTrainerBaseLightning with example: obj = DQNTrainer(q_network, q_network_target, reward_network, q_network_cpe, q_network_cpe_target, metrics_to_score, evaluation, imitator, actions, rl, double_q_learning, bcq, minibatch_size, minibatches_per_step, optimizer)