class_docstr: A Pytorch implementation of Simulated Annealing compression algorithm.
  
  Parameters
  ----------
  model : pytorch model
      The model to be pruned.
  config_list : list
      Supported keys:
          - sparsity : The target overall sparsity.
          - op_types : The operation type to prune.
  evaluator : function
      Function to evaluate the pruned model.
      This function should include `model` as the only parameter, and returns a scalar value.
      Example::
  
          def evaluator(model):
              device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
              val_loader = ...
              model.eval()
              correct = 0
              with torch.no_grad():
                  for data, target in val_loader:
                      data, target = data.to(device), target.to(device)
                      output = model(data)
                      # get the index of the max log-probability
                      pred = output.argmax(dim=1, keepdim=True)
                      correct += pred.eq(target.view_as(pred)).sum().item()
              accuracy = correct / len(val_loader.dataset)
              return accuracy
  optimize_mode : str
      Optimize mode, `maximize` or `minimize`, by default `maximize`.
  base_algo : str
      Base pruning algorithm. `level`, `l1`, `l2` or `fpgm`, by default `l1`. Given the sparsity distribution among the ops,
      the assigned `base_algo` is used to decide which filters/channels/weights to prune.
  start_temperature : float
      Start temperature of the simulated annealing process.
  stop_temperature : float
      Stop temperature of the simulated annealing process.
  cool_down_rate : float
      Cool down rate of the temperature.
  perturbation_magnitude : float
      Initial perturbation magnitude to the sparsities. The magnitude decreases with current temperature.
  experiment_data_dir : string
      PATH to save experiment data,
      including the config_list generated for the base pruning algorithm, the performance of the pruned model and the pruning history.
class_docstr_tok: ["A","Pytorch","implementation","of","Simulated","Annealing","compression","algorithm",".","Parameters","--","--","--","--","--","model",":","pytorch","model","The","model","to","be","pruned",".","config_list",":","list","Supported","keys",":","-","sparsity",":","The","target","overall","sparsity",".","-","op_types",":","The","operation","type","to","prune",".","evaluator",":","function","Function","to","evaluate","the","pruned","model",".","This","function","should","include","`","model","`","as","the","only","parameter",",","and","returns","a","scalar","value",".","Example",":",":","def","evaluator","(","model",")",":","device","=","torch.device","(","``","cuda","''","if","torch.cuda.is_available","(",")","else","``","cpu","''",")","val_loader","=","...","model.eval","(",")","correct","=","0","with","torch.no_grad","(",")",":","for","data",",","target","in","val_loader",":","data",",","target","=","data.to","(","device",")",",","target.to","(","device",")","output","=","model","(","data",")","#","get","the","index","of","the","max","log-probability","pred","=","output.argmax","(","dim=1",",","keepdim=True",")","correct","+=","pred.eq","(","target.view_as","(","pred",")",")",".sum","(",")",".item","(",")","accuracy","=","correct","\/","len","(","val_loader.dataset",")","return","accuracy","optimize_mode",":","str","Optimize","mode",",","`","maximize","`","or","`","minimize","`",",","by","default","`","maximize","`",".","base_algo",":","str","Base","pruning","algorithm",".","`","level","`",",","`","l1","`",",","`","l2","`","or","`","fpgm","`",",","by","default","`","l1","`",".","Given","the","sparsity","distribution","among","the","ops",",","the","assigned","`","base_algo","`","is","used","to","decide","which","filters\/channels\/weights","to","prune",".","start_temperature",":","float","Start","temperature","of","the","simulated","annealing","process",".","stop_temperature",":","float","Stop","temperature","of","the","simulated","annealing","process",".","cool_down_rate",":","float","Cool","down","rate","of","the","temperature",".","perturbation_magnitude",":","float","Initial","perturbation","magnitude","to","the","sparsities",".","The","magnitude","decreases","with","current","temperature",".","experiment_data_dir",":","string","PATH","to","save","experiment","data",",","including","the","config_list","generated","for","the","base","pruning","algorithm",",","the","performance","of","the","pruned","model","and","the","pruning","history","."]
docstr: convert sparsities vector into config_list for LevelPruner or L1FilterPruner
  
  Parameters
  ----------
  sparsities : list
      list of sparsities
  
  Returns
  -------
  list of dict
      config_list for LevelPruner or L1FilterPruner
docstr_tok: ["convert","sparsities","vector","into","config_list","for","LevelPruner","or","L1FilterPruner","Parameters","--","--","--","--","--","sparsities",":","list","list","of","sparsities","Returns","--","--","--","-","list","of","dict","config_list","for","LevelPruner","or","L1FilterPruner"]
code: def _sparsities_2_config_list(self, sparsities):
      """
      convert sparsities vector into config_list for LevelPruner or L1FilterPruner
  
      Parameters
      ----------
      sparsities : list
          list of sparsities
  
      Returns
      -------
      list of dict
          config_list for LevelPruner or L1FilterPruner
      """
      config_list = []
  
      sparsities = sorted(sparsities)
      self.modules_wrapper = sorted(
          self.modules_wrapper,
          key=lambda wrapper: wrapper.module.weight.data.numel(),
      )
  
      # a layer with more weights will have no less pruning rate
      for idx, wrapper in enumerate(self.get_modules_wrapper()):
          # L1Filter Pruner requires to specify op_types
          if self._base_algo in ["l1", "l2", "fpgm"]:
              config_list.append(
                  {
                      "sparsity": sparsities[idx],
                      "op_types": ["Conv2d"],
                      "op_names": [wrapper.name],
                  }
              )
          elif self._base_algo == "level":
              config_list.append(
                  {
                      "sparsity": sparsities[idx],
                      "op_names": [wrapper.name],
                  }
              )
  
      config_list = [
          val
          for val in config_list
          if not math.isclose(val["sparsity"], 0, abs_tol=1e-6)
      ]
  
      return config_list
  
imports: import logging
  import os
  import math
  import copy
  import csv
  import json
  import numpy
  from schema import And, Optional
  from ..torch_utils import OptimizeMode
  from ..compressor import Pruner
  from ..utils.config_validation import CompressorSchema
  from .constants_pruner import PRUNER_DICT
label_desc: Use image node_id 3 for calling the SimulatedAnnealingPruner obj's underlying member method code with example usage: obj._sparsities_2_config_list(sparsities) and returns: config_list