code: def monte_carlo_tree_search(
      model: torch.nn.Module,
      state: torch.Tensor,
      n_sim: int,
      t_time,
      n_steps: int,
      game_tree: Dict,
      state_dict: Dict,
  ):
      """Runs the monte carlo tree search algorithm.
  
      Args:
          model (torch.nn.Module): The model to use for the simulation.
          state (torch.Tensor): The initial state.
          n_sim (int): The number of simulations to run.
          t_time (int): The current time step.
          n_steps (int): The maximum number of steps to simulate.
          game_tree (Dict): The game tree.
          state_dict (Dict): The dictionary containing the states.
      """
      # Note that game tree is not the full tree, but just the one having as root
      #  the current node(state).
      # should we accept also previous updated trajectories for the current node?
      # is it something we should considering when deciding how many simulations
      # we should run? (I think yes)
      state_hash = to_hash(extract_present_state(state))
      if state_hash in state_dict:
          with torch.no_grad():
              N_s_a = state_dict[state_hash][3]
              n_sim -= int(N_s_a.sum())
              n_sim = max(n_sim, 0)
  
      for _ in range(n_sim):
          simulate_game(
              model, state, t_time, n_steps, game_tree, state_dict
          )
      # return next state
      (
          possible_states_dict,
          _,
          repetitions,
          N_s_a,
          q_values,
          _,
      ) = state_dict[state_hash]
      possible_states = _recompose_possible_states(possible_states_dict)
      next_state_idx = select_future_state(
          possible_states, q_values, N_s_a, repetitions, return_idx=True
      )
      next_state = possible_states[next_state_idx]
      return next_state
  
file_path: nebuly/optimization/open_alpha_tensor/open_alpha_tensor/core/actors/stage.py
imports: from typing import Dict, List
  import torch
  from open_alpha_tensor.core.data.utils import get_scalars, map_action_to_triplet
  from open_alpha_tensor.core.modules.alpha_tensor import AlphaTensorModel
label_desc: Use image node_id 13 for calling a global function with example usage: monte_carlo_tree_search(model, state, n_sim, t_time, n_steps, game_tree, state_dict) and returns: next_state