




'''simple docstring'''





import gc
import threading
import time

import psutil
import torch

class        _a    :






     def __init__(			self   )							->      Dict:
          _snake_case							=				psutil.Process()
          _snake_case							=				False






     def     _lowercase     (			self   )							->      List[Any]:
          _snake_case							=				-1

          while True:
               _snake_case							=				max(self.process.memory_info().rss ,self.cpu_memory_peak   )

               # can't sleep or will not catch the peak right (this comment is here on purpose)
               if not self.peak_monitoring:
                    break






     def     _lowercase     (			self   )							->      List[Any]:
          _snake_case							=				True
          _snake_case							=				threading.Thread(target=self.peak_monitor   )
          _snake_case							=				True
          self.thread.start()






     def     _lowercase     (			self   )							->      Dict:
          _snake_case							=				False
          self.thread.join()
          return self.cpu_memory_peak







UpperCamelCase_						:      List[Any]       =						PeakCPUMemory()





def      __a     (       )						->			Any:

     """simple docstring"""




     _snake_case							=				{"time": time.time()}

     gc.collect()
     torch.cuda.empty_cache()

     # CPU mem
     _snake_case							=				psutil.Process().memory_info().rss
     cpu_peak_tracker.start()

     # GPU mem
     for i in range(torch.cuda.device_count()   ):
          _snake_case							=				torch.cuda.memory_allocated(_UpperCamelCase   )
     torch.cuda.reset_peak_memory_stats()

     return measures





def      __a     (       _UpperCamelCase:   Any   )						->			Tuple:

     """simple docstring"""




     _snake_case							=				{"time": time.time() - start_measures["time"]}

     gc.collect()
     torch.cuda.empty_cache()

     # CPU mem
     _snake_case							=				(psutil.Process().memory_info().rss - start_measures["cpu"]) / 2**20
     _snake_case							=				(cpu_peak_tracker.stop() - start_measures["cpu"]) / 2**20

     # GPU mem
     for i in range(torch.cuda.device_count()   ):
          _snake_case							=				(torch.cuda.memory_allocated(_UpperCamelCase   ) - start_measures[str(_UpperCamelCase   )]) / 2**20
          _snake_case							=				(torch.cuda.max_memory_allocated(_UpperCamelCase   ) - start_measures[str(_UpperCamelCase   )]) / 2**20

     return measures





def      __a     (       _UpperCamelCase:   Union[str, Any] ,						_UpperCamelCase:   Union[str, Any]   )						->			Union[str, Any]:

     """simple docstring"""




     print(F"""{description}:"""   )
     print(F"""- Time: {measures['time']:.2f}s"""   )
     for i in range(torch.cuda.device_count()   ):
          print(F"""- GPU {i} allocated: {measures[str(_UpperCamelCase   )]:.2f}MiB"""   )
          _snake_case							=				measures[F"""{i}-peak"""]
          print(F"""- GPU {i} peak: {peak:.2f}MiB"""   )
     print(F"""- CPU RAM allocated: {measures['cpu']:.2f}MiB"""   )
     print(F"""- CPU RAM peak: {measures['cpu-peak']:.2f}MiB"""   )








'''simple docstring'''





from __future__ import annotations

from typing import Any





def      __a     (       _UpperCamelCase:   list[Any]   )						->			None:

     """simple docstring"""




     create_state_space_tree(_UpperCamelCase ,						[] ,						0   )





def      __a     (       _UpperCamelCase:   list[Any] ,						_UpperCamelCase:   list[Any] ,						_UpperCamelCase:   int   )						->			None:

     """simple docstring"""




     if index == len(_UpperCamelCase   ):
          print(_UpperCamelCase   )
          return

     create_state_space_tree(_UpperCamelCase ,						_UpperCamelCase ,						index + 1   )
     current_subsequence.append(sequence[index]   )
     create_state_space_tree(_UpperCamelCase ,						_UpperCamelCase ,						index + 1   )
     current_subsequence.pop()


if __name__ == "__main__":
   UpperCamelCase_						:      list[Any]       =						[3, 1, 2, 4]
   generate_all_subsequences(seq)

   seq.clear()
   seq.extend(['''A''', '''B''', '''C'''])
   generate_all_subsequences(seq)


