def run_arxiv_cleaner(parameters):
  """Core of the code, runs the actual arXiv cleaner."""

  files_to_delete = [
      r'\.aux$',
      r'\.sh$',
      r'\.blg$',
      r'\.brf$',
      r'\.log$',
      r'\.out$',
      r'\.ps$',
      r'\.dvi$',
      r'\.synctex.gz$',
      '~$',
      r'\.backup$',
      r'\.gitignore$',
      r'\.DS_Store$',
      r'\.svg$',
      r'^\.idea',
      r'\.dpth$',
      r'\.md5$',
      r'\.dep$',
      r'\.auxlock$',
      r'\.fls$',
      r'\.fdb_latexmk$',
  ]

  if not parameters['keep_bib']:
    files_to_delete.append(r'\.bib$')

  parameters.update({
      'to_delete': files_to_delete,
      'figures_to_copy_if_referenced': [
          r'\.png$',
          r'\.jpg$',
          r'\.jpeg$',
          r'\.pdf$',
      ],
  })

  logging.info('Collecting file structure.')
  parameters['output_folder'] = _create_out_folder(parameters['input_folder'])

  from_zip = parameters['input_folder'].endswith('.zip')
  tempdir_context = (
      tempfile.TemporaryDirectory() if from_zip else contextlib.suppress()
  )

  with tempdir_context as tempdir:

    if from_zip:
      logging.info('Unzipping input folder.')
      shutil.unpack_archive(parameters['input_folder'], tempdir)
      parameters['input_folder'] = tempdir

    splits = _split_all_files(parameters)

    logging.info('Reading all tex files')
    tex_contents = _read_all_tex_contents(
        splits['tex_in_root'] + splits['tex_not_in_root'], parameters
    )

    for tex_file in tex_contents:
      logging.info('Removing comments in file %s.', tex_file)
      tex_contents[tex_file] = _remove_comments_and_commands_to_delete(
          tex_contents[tex_file], parameters
      )

    for tex_file in tex_contents:
      logging.info('Replacing \\includesvg calls in file %s.', tex_file)
      tex_contents[tex_file] = _replace_includesvg(
          tex_contents[tex_file], splits['svg_inkscape']
      )

    for tex_file in tex_contents:
      logging.info('Replacing Tikz Pictures in file %s.', tex_file)
      content = _replace_tikzpictures(
          tex_contents[tex_file], splits['external_tikz_figures']
      )
      # If file ends with '\n' already, the split in last line would add an extra
      # '\n', so we remove it.
      tex_contents[tex_file] = content.split('\n')

    _keep_only_referenced_tex(tex_contents, splits)
    _add_root_tex_files(splits)

    for tex_file in splits['tex_to_copy']:
      logging.info('Replacing patterns in file %s.', tex_file)
      content = '\n'.join(tex_contents[tex_file])
      content = _find_and_replace_patterns(
          content, parameters.get('patterns_and_insertions', list())
      )
      tex_contents[tex_file] = content
      new_path = os.path.join(parameters['output_folder'], tex_file)
      logging.info('Writing modified contents to %s.', new_path)
      _write_file_content(
          content,
          new_path,
      )

    full_content = '\n'.join(
        ''.join(tex_contents[fn]) for fn in splits['tex_to_copy']
    )
    _copy_only_referenced_non_tex_not_in_root(parameters, full_content, splits)
    for non_tex_file in splits['non_tex_in_root']:
      logging.info('Copying non-tex file %s.', non_tex_file)
      _copy_file(non_tex_file, parameters)

    _resize_and_copy_figures_if_referenced(parameters, full_content, splits)
    logging.info('Outputs written to %s', parameters['output_folder'])

run_arxiv_cleaner(parameters={'input_folder': 'tex', 'images_allowlist': {'images/im2_included.jpg': 200, 'images/im3_included.png': 400}, 'resize_images': True, 'im_size': 100, 'compress_pdf': False, 'pdf_im_resolution': 500, 'commands_to_delete': ['mytodo'], 'commands_only_to_delete': ['red'], 'environments_to_delete': ['mynote'], 'use_external_tikz': 'ext_tikz', 'keep_bib': False})

{'main.tex': ['\\begin{document}', 'Text', '', 'Text%', '', '', 'This is a percent \\%.', '\\includegraphics{images/im1_included.png}', '\\includegraphics{images/im3_included.png}', '\\includegraphics{%', '  images/im4_included.png%', '  }', '\\includegraphics[width=.5\\linewidth]{%', '  images/im5_included.jpg}', '', '\\includegraphics{./images/im3_included.png}', '', 'This line should not be separated', '%', 'from this one.', '', '', '', '\\newif\\ifvar', '', '\\ifvar', '\\fi', '', '\\newcommand{\\red}[1]{{\\color{red} #1}}', 'hello test hello', 'test hello', 'test', '', '', '\\input{figures/figure_included.tex}', '', '\\includegraphics{ext_tikz/test1.pdf}', '', '\\input{figures/figure_included.tikz}', '', '\\begin{tikzpicture}', '    \\node (test) at (0,0) {Test3};', '\\end{tikzpicture}', '', '\\tikzsetnextfilename{test_no_match}', '\\begin{tikzpicture}', '    \\node (test) at (0,0) {Test4};', '\\end{tikzpicture}', '', '\\end{document}', ''], 'figures/figure_not_included.tex': ['\\addplot{figures/data_not_included.txt}', '\\input{figures/figure_not_included_2.tex}', ''], 'figures/figure_not_included_2.tex': [''], 'figures/figure_included.tikz': ['\ufeff\\includegraphics{ext_tikz/test2.pdf}', ''], 'figures/figure_included.tex': ['\\includegraphics{images/im2_included.jpg}', '\\addplot{figures/data_included.txt}', '']}

{'all': ['main.bib', 'main.bbl', 'main.tex', 'main.aux', 'ext_tikz/test2.pdf', 'ext_tikz/test1.pdf', 'ext_tikz/figure_not_included.pdf', 'figures/data_not_included.txt', 'figures/figure_not_included.tex', 'figures/figure_not_included_2.tex', 'figures/figure_included.tikz', 'figures/figure_included.tex', 'figures/data_included.txt', 'not_included/figures/data_included.txt', 'images/im4_included.png', 'images/im1.png', 'images/im4_not_included.png', 'images/im3_included.png', 'images/im2_included.jpg', 'images/im5_not_included.jpg', 'images/im5_included.jpg', 'images/im1_included.png', 'images/im_not_included.png', 'images/include/images/im3_included.png'], 'in_root': ['main.bib', 'main.bbl', 'main.tex', 'main.aux'], 'not_in_root': ['ext_tikz/test2.pdf', 'ext_tikz/test1.pdf', 'ext_tikz/figure_not_included.pdf', 'figures/data_not_included.txt', 'figures/figure_not_included.tex', 'figures/figure_not_included_2.tex', 'figures/figure_included.tikz', 'figures/figure_included.tex', 'figures/data_included.txt', 'not_included/figures/data_included.txt', 'images/im4_included.png', 'images/im1.png', 'images/im4_not_included.png', 'images/im3_included.png', 'images/im2_included.jpg', 'images/im5_not_included.jpg', 'images/im5_included.jpg', 'images/im1_included.png', 'images/im_not_included.png', 'images/include/images/im3_included.png'], 'to_copy_in_root': ['main.bbl', 'main.tex'], 'to_copy_not_in_root': ['figures/data_not_included.txt', 'figures/figure_not_included.tex', 'figures/figure_not_included_2.tex', 'figures/figure_included.tikz', 'figures/figure_included.tex', 'figures/data_included.txt', 'not_included/figures/data_included.txt'], 'figures': ['ext_tikz/test2.pdf', 'ext_tikz/test1.pdf', 'ext_tikz/figure_not_included.pdf', 'images/im4_included.png', 'images/im1.png', 'images/im4_not_included.png', 'images/im3_included.png', 'images/im2_included.jpg', 'images/im5_not_included.jpg', 'images/im5_included.jpg', 'images/im1_included.png', 'images/im_not_included.png', 'images/include/images/im3_included.png'], 'tex_in_root': ['main.tex'], 'tex_not_in_root': ['figures/figure_not_included.tex', 'figures/figure_not_included_2.tex', 'figures/figure_included.tikz', 'figures/figure_included.tex'], 'non_tex_in_root': ['main.bbl'], 'non_tex_not_in_root': ['figures/data_not_included.txt', 'figures/data_included.txt', 'not_included/figures/data_included.txt'], 'external_tikz_figures': ['ext_tikz/test2.pdf', 'ext_tikz/test1.pdf', 'ext_tikz/figure_not_included.pdf'], 'svg_inkscape': []}

{'all': ['main.bib', 'main.bbl', 'main.tex', 'main.aux', 'ext_tikz/test2.pdf', 'ext_tikz/test1.pdf', 'ext_tikz/figure_not_included.pdf', 'figures/data_not_included.txt', 'figures/figure_not_included.tex', 'figures/figure_not_included_2.tex', 'figures/figure_included.tikz', 'figures/figure_included.tex', 'figures/data_included.txt', 'not_included/figures/data_included.txt', 'images/im4_included.png', 'images/im1.png', 'images/im4_not_included.png', 'images/im3_included.png', 'images/im2_included.jpg', 'images/im5_not_included.jpg', 'images/im5_included.jpg', 'images/im1_included.png', 'images/im_not_included.png', 'images/include/images/im3_included.png'], 'in_root': ['main.bib', 'main.bbl', 'main.tex', 'main.aux'], 'not_in_root': ['ext_tikz/test2.pdf', 'ext_tikz/test1.pdf', 'ext_tikz/figure_not_included.pdf', 'figures/data_not_included.txt', 'figures/figure_not_included.tex', 'figures/figure_not_included_2.tex', 'figures/figure_included.tikz', 'figures/figure_included.tex', 'figures/data_included.txt', 'not_included/figures/data_included.txt', 'images/im4_included.png', 'images/im1.png', 'images/im4_not_included.png', 'images/im3_included.png', 'images/im2_included.jpg', 'images/im5_not_included.jpg', 'images/im5_included.jpg', 'images/im1_included.png', 'images/im_not_included.png', 'images/include/images/im3_included.png'], 'to_copy_in_root': ['main.bbl', 'main.tex'], 'to_copy_not_in_root': ['figures/data_not_included.txt', 'figures/figure_not_included.tex', 'figures/figure_not_included_2.tex', 'figures/figure_included.tikz', 'figures/figure_included.tex', 'figures/data_included.txt', 'not_included/figures/data_included.txt'], 'figures': ['ext_tikz/test2.pdf', 'ext_tikz/test1.pdf', 'ext_tikz/figure_not_included.pdf', 'images/im4_included.png', 'images/im1.png', 'images/im4_not_included.png', 'images/im3_included.png', 'images/im2_included.jpg', 'images/im5_not_included.jpg', 'images/im5_included.jpg', 'images/im1_included.png', 'images/im_not_included.png', 'images/include/images/im3_included.png'], 'tex_in_root': ['main.tex'], 'tex_not_in_root': ['figures/figure_not_included.tex', 'figures/figure_not_included_2.tex', 'figures/figure_included.tikz', 'figures/figure_included.tex'], 'non_tex_in_root': ['main.bbl'], 'non_tex_not_in_root': ['figures/data_not_included.txt', 'figures/data_included.txt', 'not_included/figures/data_included.txt'], 'external_tikz_figures': ['ext_tikz/test2.pdf', 'ext_tikz/test1.pdf', 'ext_tikz/figure_not_included.pdf'], 'svg_inkscape': [], 'tex_to_copy': ['figures/figure_included.tex', 'figures/figure_included.tikz', 'main.tex']}

{'input_folder': 'tex', 'images_allowlist': {'images/im2_included.jpg': 200, 'images/im3_included.png': 400}, 'resize_images': True, 'im_size': 100, 'compress_pdf': False, 'pdf_im_resolution': 500, 'commands_to_delete': ['mytodo'], 'commands_only_to_delete': ['red'], 'environments_to_delete': ['mynote'], 'use_external_tikz': 'ext_tikz', 'keep_bib': False, 'to_delete': ['\\.aux$', '\\.sh$', '\\.blg$', '\\.brf$', '\\.log$', '\\.out$', '\\.ps$', '\\.dvi$', '\\.synctex.gz$', '~$', '\\.backup$', '\\.gitignore$', '\\.DS_Store$', '\\.svg$', '^\\.idea', '\\.dpth$', '\\.md5$', '\\.dep$', '\\.auxlock$', '\\.fls$', '\\.fdb_latexmk$', '\\.bib$'], 'figures_to_copy_if_referenced': ['\\.png$', '\\.jpg$', '\\.jpeg$', '\\.pdf$']}

{'input_folder': 'tex', 'images_allowlist': {'images/im2_included.jpg': 200, 'images/im3_included.png': 400}, 'resize_images': True, 'im_size': 100, 'compress_pdf': False, 'pdf_im_resolution': 500, 'commands_to_delete': ['mytodo'], 'commands_only_to_delete': ['red'], 'environments_to_delete': ['mynote'], 'use_external_tikz': 'ext_tikz', 'keep_bib': False, 'to_delete': ['\\.aux$', '\\.sh$', '\\.blg$', '\\.brf$', '\\.log$', '\\.out$', '\\.ps$', '\\.dvi$', '\\.synctex.gz$', '~$', '\\.backup$', '\\.gitignore$', '\\.DS_Store$', '\\.svg$', '^\\.idea', '\\.dpth$', '\\.md5$', '\\.dep$', '\\.auxlock$', '\\.fls$', '\\.fdb_latexmk$', '\\.bib$'], 'figures_to_copy_if_referenced': ['\\.png$', '\\.jpg$', '\\.jpeg$', '\\.pdf$'], 'output_folder': '/local/rcs/XXX/code/pytrace-collector/logs/self_collected/tried/google-research+arxiv-latex-cleaner/google-research+arxiv-latex-cleaner/tex_arXiv'}

{'main.tex': ['\\begin{document}\n', 'Text\n', '% Whole line comment\n', '\n', 'Text% Inline comment\n', '\\begin{comment}\n', 'This is an environment comment.\n', '\\end{comment}\n', '\n', 'This is a percent \\%.\n', '% Whole line comment without newline\n', '\\includegraphics{images/im1_included.png}\n', '%\\includegraphics{images/im_not_included}\n', '\\includegraphics{images/im3_included.png}\n', '\\includegraphics{%\n', '  images/im4_included.png%\n', '  }\n', '\\includegraphics[width=.5\\linewidth]{%\n', '  images/im5_included.jpg}\n', '%\\includegraphics{%\n', '%  images/im4_not_included.png\n', '%  }\n', '%\\includegraphics[width=.5\\linewidth]{%\n', '%  images/im5_not_included.jpg}\n', '\n', '% test whatever the path satrting with dot works when include graphics\n', '\\includegraphics{./images/im3_included.png}\n', '\n', 'This line should\\mytodo{Do this later} not be separated\n', '\\mytodo{This is a todo command with a nested \\textit{command}.\n', 'Please remember that up to \\texttt{2 levels} of \\textit{nesting} are supported.}\n', 'from this one.\n', '\n', '\\begin{mynote}\n', '  This is a custom environment that could be excluded.\n', '\\end{mynote}\n', '\n', '\\newif\\ifvar\n', '\n', '\\ifvar\n', '\\if    false\n', '\\if false\n', '\\if 0\n', '\\iffalse\n', '\\ifvar\n', 'Text\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\\fi\n', '\n', '\\newcommand{\\red}[1]{{\\color{red} #1}}\n', 'hello test \\red{hello\n', 'test \\red{hello}}\n', 'test\n', '\n', '% content after this line should not be cleaned if \\end{document} is in a comment\n', '\n', '\\input{figures/figure_included.tex}\n', '% \\input{figures/figure_not_included.tex}\n', '\n', '% Test for tikzpicture feature\n', '% should be replaced\n', '\\tikzsetnextfilename{test1}\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test1};\n', '\\end{tikzpicture}\n', '\n', '% should be replaced in included file\n', '\\input{figures/figure_included.tikz}\n', '\n', '% should not be be replaced - no preceding tikzsetnextfilename command\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test3};\n', '\\end{tikzpicture}\n', '\n', '\\tikzsetnextfilename{test_no_match}\n', '\\begin{tikzpicture}\n', '    \\node (test) at (0,0) {Test4};\n', '\\end{tikzpicture}\n', '\n', '\\end{document}\n'], 'figures/figure_not_included.tex': ['\\addplot{figures/data_not_included.txt}\n', '\\input{figures/figure_not_included_2.tex}\n'], 'figures/figure_not_included_2.tex': [], 'figures/figure_included.tikz': ['\ufeff\\tikzsetnextfilename{test2}\n', '\\begin{tikzpicture}\n', '\\node {root}\n', 'child {node {left}}\n', 'child {node {right}\n', 'child {node {child}}\n', 'child {node {child}}\n', '};\n', '\\end{tikzpicture}'], 'figures/figure_included.tex': ['\\includegraphics{images/im2_included.jpg}\n', '\\addplot{figures/data_included.txt}\n']}

{'main.tex': '\\begin{document}\nText\n\nText%\n\n\nThis is a percent \\%.\n\\includegraphics{images/im1_included.png}\n\\includegraphics{images/im3_included.png}\n\\includegraphics{%\n  images/im4_included.png%\n  }\n\\includegraphics[width=.5\\linewidth]{%\n  images/im5_included.jpg}\n\n\\includegraphics{./images/im3_included.png}\n\nThis line should not be separated\n%\nfrom this one.\n\n\n\n\\newif\\ifvar\n\n\\ifvar\n\\fi\n\n\\newcommand{\\red}[1]{{\\color{red} #1}}\nhello test hello\ntest hello\ntest\n\n\n\\input{figures/figure_included.tex}\n\n\\tikzsetnextfilename{test1}\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test1};\n\\end{tikzpicture}\n\n\\input{figures/figure_included.tikz}\n\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test3};\n\\end{tikzpicture}\n\n\\tikzsetnextfilename{test_no_match}\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test4};\n\\end{tikzpicture}\n\n\\end{document}\n', 'figures/figure_not_included.tex': ['\\addplot{figures/data_not_included.txt}\n', '\\input{figures/figure_not_included_2.tex}\n'], 'figures/figure_not_included_2.tex': [], 'figures/figure_included.tikz': ['\ufeff\\tikzsetnextfilename{test2}\n', '\\begin{tikzpicture}\n', '\\node {root}\n', 'child {node {left}}\n', 'child {node {right}\n', 'child {node {child}}\n', 'child {node {child}}\n', '};\n', '\\end{tikzpicture}'], 'figures/figure_included.tex': ['\\includegraphics{images/im2_included.jpg}\n', '\\addplot{figures/data_included.txt}\n']}

{'main.tex': '\\begin{document}\nText\n\nText%\n\n\nThis is a percent \\%.\n\\includegraphics{images/im1_included.png}\n\\includegraphics{images/im3_included.png}\n\\includegraphics{%\n  images/im4_included.png%\n  }\n\\includegraphics[width=.5\\linewidth]{%\n  images/im5_included.jpg}\n\n\\includegraphics{./images/im3_included.png}\n\nThis line should not be separated\n%\nfrom this one.\n\n\n\n\\newif\\ifvar\n\n\\ifvar\n\\fi\n\n\\newcommand{\\red}[1]{{\\color{red} #1}}\nhello test hello\ntest hello\ntest\n\n\n\\input{figures/figure_included.tex}\n\n\\tikzsetnextfilename{test1}\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test1};\n\\end{tikzpicture}\n\n\\input{figures/figure_included.tikz}\n\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test3};\n\\end{tikzpicture}\n\n\\tikzsetnextfilename{test_no_match}\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test4};\n\\end{tikzpicture}\n\n\\end{document}\n', 'figures/figure_not_included.tex': '\\addplot{figures/data_not_included.txt}\n\\input{figures/figure_not_included_2.tex}\n', 'figures/figure_not_included_2.tex': [], 'figures/figure_included.tikz': ['\ufeff\\tikzsetnextfilename{test2}\n', '\\begin{tikzpicture}\n', '\\node {root}\n', 'child {node {left}}\n', 'child {node {right}\n', 'child {node {child}}\n', 'child {node {child}}\n', '};\n', '\\end{tikzpicture}'], 'figures/figure_included.tex': ['\\includegraphics{images/im2_included.jpg}\n', '\\addplot{figures/data_included.txt}\n']}

{'main.tex': '\\begin{document}\nText\n\nText%\n\n\nThis is a percent \\%.\n\\includegraphics{images/im1_included.png}\n\\includegraphics{images/im3_included.png}\n\\includegraphics{%\n  images/im4_included.png%\n  }\n\\includegraphics[width=.5\\linewidth]{%\n  images/im5_included.jpg}\n\n\\includegraphics{./images/im3_included.png}\n\nThis line should not be separated\n%\nfrom this one.\n\n\n\n\\newif\\ifvar\n\n\\ifvar\n\\fi\n\n\\newcommand{\\red}[1]{{\\color{red} #1}}\nhello test hello\ntest hello\ntest\n\n\n\\input{figures/figure_included.tex}\n\n\\tikzsetnextfilename{test1}\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test1};\n\\end{tikzpicture}\n\n\\input{figures/figure_included.tikz}\n\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test3};\n\\end{tikzpicture}\n\n\\tikzsetnextfilename{test_no_match}\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test4};\n\\end{tikzpicture}\n\n\\end{document}\n', 'figures/figure_not_included.tex': '\\addplot{figures/data_not_included.txt}\n\\input{figures/figure_not_included_2.tex}\n', 'figures/figure_not_included_2.tex': '', 'figures/figure_included.tikz': ['\ufeff\\tikzsetnextfilename{test2}\n', '\\begin{tikzpicture}\n', '\\node {root}\n', 'child {node {left}}\n', 'child {node {right}\n', 'child {node {child}}\n', 'child {node {child}}\n', '};\n', '\\end{tikzpicture}'], 'figures/figure_included.tex': ['\\includegraphics{images/im2_included.jpg}\n', '\\addplot{figures/data_included.txt}\n']}

{'main.tex': '\\begin{document}\nText\n\nText%\n\n\nThis is a percent \\%.\n\\includegraphics{images/im1_included.png}\n\\includegraphics{images/im3_included.png}\n\\includegraphics{%\n  images/im4_included.png%\n  }\n\\includegraphics[width=.5\\linewidth]{%\n  images/im5_included.jpg}\n\n\\includegraphics{./images/im3_included.png}\n\nThis line should not be separated\n%\nfrom this one.\n\n\n\n\\newif\\ifvar\n\n\\ifvar\n\\fi\n\n\\newcommand{\\red}[1]{{\\color{red} #1}}\nhello test hello\ntest hello\ntest\n\n\n\\input{figures/figure_included.tex}\n\n\\tikzsetnextfilename{test1}\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test1};\n\\end{tikzpicture}\n\n\\input{figures/figure_included.tikz}\n\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test3};\n\\end{tikzpicture}\n\n\\tikzsetnextfilename{test_no_match}\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test4};\n\\end{tikzpicture}\n\n\\end{document}\n', 'figures/figure_not_included.tex': '\\addplot{figures/data_not_included.txt}\n\\input{figures/figure_not_included_2.tex}\n', 'figures/figure_not_included_2.tex': '', 'figures/figure_included.tikz': '\ufeff\\tikzsetnextfilename{test2}\n\\begin{tikzpicture}\n\\node {root}\nchild {node {left}}\nchild {node {right}\nchild {node {child}}\nchild {node {child}}\n};\n\\end{tikzpicture}\n', 'figures/figure_included.tex': ['\\includegraphics{images/im2_included.jpg}\n', '\\addplot{figures/data_included.txt}\n']}

{'main.tex': '\\begin{document}\nText\n\nText%\n\n\nThis is a percent \\%.\n\\includegraphics{images/im1_included.png}\n\\includegraphics{images/im3_included.png}\n\\includegraphics{%\n  images/im4_included.png%\n  }\n\\includegraphics[width=.5\\linewidth]{%\n  images/im5_included.jpg}\n\n\\includegraphics{./images/im3_included.png}\n\nThis line should not be separated\n%\nfrom this one.\n\n\n\n\\newif\\ifvar\n\n\\ifvar\n\\fi\n\n\\newcommand{\\red}[1]{{\\color{red} #1}}\nhello test hello\ntest hello\ntest\n\n\n\\input{figures/figure_included.tex}\n\n\\tikzsetnextfilename{test1}\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test1};\n\\end{tikzpicture}\n\n\\input{figures/figure_included.tikz}\n\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test3};\n\\end{tikzpicture}\n\n\\tikzsetnextfilename{test_no_match}\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test4};\n\\end{tikzpicture}\n\n\\end{document}\n', 'figures/figure_not_included.tex': '\\addplot{figures/data_not_included.txt}\n\\input{figures/figure_not_included_2.tex}\n', 'figures/figure_not_included_2.tex': '', 'figures/figure_included.tikz': '\ufeff\\tikzsetnextfilename{test2}\n\\begin{tikzpicture}\n\\node {root}\nchild {node {left}}\nchild {node {right}\nchild {node {child}}\nchild {node {child}}\n};\n\\end{tikzpicture}\n', 'figures/figure_included.tex': '\\includegraphics{images/im2_included.jpg}\n\\addplot{figures/data_included.txt}\n'}

{'main.tex': ['\\begin{document}', 'Text', '', 'Text%', '', '', 'This is a percent \\%.', '\\includegraphics{images/im1_included.png}', '\\includegraphics{images/im3_included.png}', '\\includegraphics{%', '  images/im4_included.png%', '  }', '\\includegraphics[width=.5\\linewidth]{%', '  images/im5_included.jpg}', '', '\\includegraphics{./images/im3_included.png}', '', 'This line should not be separated', '%', 'from this one.', '', '', '', '\\newif\\ifvar', '', '\\ifvar', '\\fi', '', '\\newcommand{\\red}[1]{{\\color{red} #1}}', 'hello test hello', 'test hello', 'test', '', '', '\\input{figures/figure_included.tex}', '', '\\includegraphics{ext_tikz/test1.pdf}', '', '\\input{figures/figure_included.tikz}', '', '\\begin{tikzpicture}', '    \\node (test) at (0,0) {Test3};', '\\end{tikzpicture}', '', '\\tikzsetnextfilename{test_no_match}', '\\begin{tikzpicture}', '    \\node (test) at (0,0) {Test4};', '\\end{tikzpicture}', '', '\\end{document}', ''], 'figures/figure_not_included.tex': '\\addplot{figures/data_not_included.txt}\n\\input{figures/figure_not_included_2.tex}\n', 'figures/figure_not_included_2.tex': '', 'figures/figure_included.tikz': '\ufeff\\tikzsetnextfilename{test2}\n\\begin{tikzpicture}\n\\node {root}\nchild {node {left}}\nchild {node {right}\nchild {node {child}}\nchild {node {child}}\n};\n\\end{tikzpicture}\n', 'figures/figure_included.tex': '\\includegraphics{images/im2_included.jpg}\n\\addplot{figures/data_included.txt}\n'}

{'main.tex': ['\\begin{document}', 'Text', '', 'Text%', '', '', 'This is a percent \\%.', '\\includegraphics{images/im1_included.png}', '\\includegraphics{images/im3_included.png}', '\\includegraphics{%', '  images/im4_included.png%', '  }', '\\includegraphics[width=.5\\linewidth]{%', '  images/im5_included.jpg}', '', '\\includegraphics{./images/im3_included.png}', '', 'This line should not be separated', '%', 'from this one.', '', '', '', '\\newif\\ifvar', '', '\\ifvar', '\\fi', '', '\\newcommand{\\red}[1]{{\\color{red} #1}}', 'hello test hello', 'test hello', 'test', '', '', '\\input{figures/figure_included.tex}', '', '\\includegraphics{ext_tikz/test1.pdf}', '', '\\input{figures/figure_included.tikz}', '', '\\begin{tikzpicture}', '    \\node (test) at (0,0) {Test3};', '\\end{tikzpicture}', '', '\\tikzsetnextfilename{test_no_match}', '\\begin{tikzpicture}', '    \\node (test) at (0,0) {Test4};', '\\end{tikzpicture}', '', '\\end{document}', ''], 'figures/figure_not_included.tex': ['\\addplot{figures/data_not_included.txt}', '\\input{figures/figure_not_included_2.tex}', ''], 'figures/figure_not_included_2.tex': '', 'figures/figure_included.tikz': '\ufeff\\tikzsetnextfilename{test2}\n\\begin{tikzpicture}\n\\node {root}\nchild {node {left}}\nchild {node {right}\nchild {node {child}}\nchild {node {child}}\n};\n\\end{tikzpicture}\n', 'figures/figure_included.tex': '\\includegraphics{images/im2_included.jpg}\n\\addplot{figures/data_included.txt}\n'}

{'main.tex': ['\\begin{document}', 'Text', '', 'Text%', '', '', 'This is a percent \\%.', '\\includegraphics{images/im1_included.png}', '\\includegraphics{images/im3_included.png}', '\\includegraphics{%', '  images/im4_included.png%', '  }', '\\includegraphics[width=.5\\linewidth]{%', '  images/im5_included.jpg}', '', '\\includegraphics{./images/im3_included.png}', '', 'This line should not be separated', '%', 'from this one.', '', '', '', '\\newif\\ifvar', '', '\\ifvar', '\\fi', '', '\\newcommand{\\red}[1]{{\\color{red} #1}}', 'hello test hello', 'test hello', 'test', '', '', '\\input{figures/figure_included.tex}', '', '\\includegraphics{ext_tikz/test1.pdf}', '', '\\input{figures/figure_included.tikz}', '', '\\begin{tikzpicture}', '    \\node (test) at (0,0) {Test3};', '\\end{tikzpicture}', '', '\\tikzsetnextfilename{test_no_match}', '\\begin{tikzpicture}', '    \\node (test) at (0,0) {Test4};', '\\end{tikzpicture}', '', '\\end{document}', ''], 'figures/figure_not_included.tex': ['\\addplot{figures/data_not_included.txt}', '\\input{figures/figure_not_included_2.tex}', ''], 'figures/figure_not_included_2.tex': [''], 'figures/figure_included.tikz': '\ufeff\\tikzsetnextfilename{test2}\n\\begin{tikzpicture}\n\\node {root}\nchild {node {left}}\nchild {node {right}\nchild {node {child}}\nchild {node {child}}\n};\n\\end{tikzpicture}\n', 'figures/figure_included.tex': '\\includegraphics{images/im2_included.jpg}\n\\addplot{figures/data_included.txt}\n'}

{'main.tex': ['\\begin{document}', 'Text', '', 'Text%', '', '', 'This is a percent \\%.', '\\includegraphics{images/im1_included.png}', '\\includegraphics{images/im3_included.png}', '\\includegraphics{%', '  images/im4_included.png%', '  }', '\\includegraphics[width=.5\\linewidth]{%', '  images/im5_included.jpg}', '', '\\includegraphics{./images/im3_included.png}', '', 'This line should not be separated', '%', 'from this one.', '', '', '', '\\newif\\ifvar', '', '\\ifvar', '\\fi', '', '\\newcommand{\\red}[1]{{\\color{red} #1}}', 'hello test hello', 'test hello', 'test', '', '', '\\input{figures/figure_included.tex}', '', '\\includegraphics{ext_tikz/test1.pdf}', '', '\\input{figures/figure_included.tikz}', '', '\\begin{tikzpicture}', '    \\node (test) at (0,0) {Test3};', '\\end{tikzpicture}', '', '\\tikzsetnextfilename{test_no_match}', '\\begin{tikzpicture}', '    \\node (test) at (0,0) {Test4};', '\\end{tikzpicture}', '', '\\end{document}', ''], 'figures/figure_not_included.tex': ['\\addplot{figures/data_not_included.txt}', '\\input{figures/figure_not_included_2.tex}', ''], 'figures/figure_not_included_2.tex': [''], 'figures/figure_included.tikz': ['\ufeff\\includegraphics{ext_tikz/test2.pdf}', ''], 'figures/figure_included.tex': '\\includegraphics{images/im2_included.jpg}\n\\addplot{figures/data_included.txt}\n'}

{'main.tex': ['\\begin{document}', 'Text', '', 'Text%', '', '', 'This is a percent \\%.', '\\includegraphics{images/im1_included.png}', '\\includegraphics{images/im3_included.png}', '\\includegraphics{%', '  images/im4_included.png%', '  }', '\\includegraphics[width=.5\\linewidth]{%', '  images/im5_included.jpg}', '', '\\includegraphics{./images/im3_included.png}', '', 'This line should not be separated', '%', 'from this one.', '', '', '', '\\newif\\ifvar', '', '\\ifvar', '\\fi', '', '\\newcommand{\\red}[1]{{\\color{red} #1}}', 'hello test hello', 'test hello', 'test', '', '', '\\input{figures/figure_included.tex}', '', '\\includegraphics{ext_tikz/test1.pdf}', '', '\\input{figures/figure_included.tikz}', '', '\\begin{tikzpicture}', '    \\node (test) at (0,0) {Test3};', '\\end{tikzpicture}', '', '\\tikzsetnextfilename{test_no_match}', '\\begin{tikzpicture}', '    \\node (test) at (0,0) {Test4};', '\\end{tikzpicture}', '', '\\end{document}', ''], 'figures/figure_not_included.tex': ['\\addplot{figures/data_not_included.txt}', '\\input{figures/figure_not_included_2.tex}', ''], 'figures/figure_not_included_2.tex': [''], 'figures/figure_included.tikz': '\ufeff\\includegraphics{ext_tikz/test2.pdf}\n', 'figures/figure_included.tex': '\\includegraphics{images/im2_included.jpg}\n\\addplot{figures/data_included.txt}\n'}

{'main.tex': '\\begin{document}\nText\n\nText%\n\n\nThis is a percent \\%.\n\\includegraphics{images/im1_included.png}\n\\includegraphics{images/im3_included.png}\n\\includegraphics{%\n  images/im4_included.png%\n  }\n\\includegraphics[width=.5\\linewidth]{%\n  images/im5_included.jpg}\n\n\\includegraphics{./images/im3_included.png}\n\nThis line should not be separated\n%\nfrom this one.\n\n\n\n\\newif\\ifvar\n\n\\ifvar\n\\fi\n\n\\newcommand{\\red}[1]{{\\color{red} #1}}\nhello test hello\ntest hello\ntest\n\n\n\\input{figures/figure_included.tex}\n\n\\includegraphics{ext_tikz/test1.pdf}\n\n\\input{figures/figure_included.tikz}\n\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test3};\n\\end{tikzpicture}\n\n\\tikzsetnextfilename{test_no_match}\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test4};\n\\end{tikzpicture}\n\n\\end{document}\n', 'figures/figure_not_included.tex': ['\\addplot{figures/data_not_included.txt}', '\\input{figures/figure_not_included_2.tex}', ''], 'figures/figure_not_included_2.tex': [''], 'figures/figure_included.tikz': '\ufeff\\includegraphics{ext_tikz/test2.pdf}\n', 'figures/figure_included.tex': '\\includegraphics{images/im2_included.jpg}\n\\addplot{figures/data_included.txt}\n'}

'\\includegraphics{images/im2_included.jpg}\n\\addplot{figures/data_included.txt}\n\n\ufeff\\includegraphics{ext_tikz/test2.pdf}\n\n\\begin{document}\nText\n\nText%\n\n\nThis is a percent \\%.\n\\includegraphics{images/im1_included.png}\n\\includegraphics{images/im3_included.png}\n\\includegraphics{%\n  images/im4_included.png%\n  }\n\\includegraphics[width=.5\\linewidth]{%\n  images/im5_included.jpg}\n\n\\includegraphics{./images/im3_included.png}\n\nThis line should not be separated\n%\nfrom this one.\n\n\n\n\\newif\\ifvar\n\n\\ifvar\n\\fi\n\n\\newcommand{\\red}[1]{{\\color{red} #1}}\nhello test hello\ntest hello\ntest\n\n\n\\input{figures/figure_included.tex}\n\n\\includegraphics{ext_tikz/test1.pdf}\n\n\\input{figures/figure_included.tikz}\n\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test3};\n\\end{tikzpicture}\n\n\\tikzsetnextfilename{test_no_match}\n\\begin{tikzpicture}\n    \\node (test) at (0,0) {Test4};\n\\end{tikzpicture}\n\n\\end{document}\n'


def perfect_replace(whole_lines, part_lines, replace_lines):
    part_tup = tuple(part_lines)
    part_len = len(part_lines)

    for i in range(len(whole_lines) - part_len + 1):
        whole_tup = tuple(whole_lines[i : i + part_len])
        if part_tup == whole_tup:
            res = whole_lines[:i] + replace_lines + whole_lines[i + part_len :]
            return "".join(res)

perfect_replace(whole_lines=['two\n'], part_lines=['two\n'], replace_lines=['three\n'])


def bit_length(num):
    # http://docs.python.org/dev/library/stdtypes.html#int.bit_length
    s = bin(num)  # binary representation:  bin(-37) --> '-0b100101'
    s = s.lstrip('-0b')  # remove leading zeros and minus sign
    return len(s)

bit_length(num=115792089237316195423570985008687907852837564279074904382605163141518161494337)


def ffmpeg_write_image(filename, image, logfile=False, pixel_format=None):
    """Writes an image (HxWx3 or HxWx4 numpy array) to a file, using ffmpeg.

    Parameters
    ----------

    filename : str
        Path to the output file.

    image : np.ndarray
        Numpy array with the image data.

    logfile : bool, optional
        Writes the ffmpeg output inside a logging file (``True``) or not
        (``False``).

    pixel_format : str, optional
        Pixel format for ffmpeg. If not defined, it will be discovered checking
        if the image data contains an alpha channel (``"rgba"``) or not
        (``"rgb24"``).
    """
    if image.dtype != "uint8":
        image = image.astype("uint8")
    if not pixel_format:
        pixel_format = "rgba" if (image.shape[2] == 4) else "rgb24"

    cmd = [
        FFMPEG_BINARY,
        "-y",
        "-s",
        "%dx%d" % (image.shape[:2][::-1]),
        "-f",
        "rawvideo",
        "-pix_fmt",
        pixel_format,
        "-i",
        "-",
        filename,
    ]

    if logfile:
        log_file = open(filename + ".log", "w+")
    else:
        log_file = sp.PIPE

    popen_params = cross_platform_popen_params(
        {"stdout": sp.DEVNULL, "stderr": log_file, "stdin": sp.PIPE}
    )

    proc = sp.Popen(cmd, **popen_params)
    out, err = proc.communicate(image.tobytes())

    if proc.returncode:
        error = (
            f"{err}\n\nMoviePy error: FFMPEG encountered the following error while "
            f"writing file {filename} with command {cmd}:\n\n {err.decode()}"
        )

        raise IOError(error)

    del proc

ffmpeg_write_image(filename='/tmp/moviepy_ffmpeg_write_image.png', image=array([[[  0., 255.,   0.],        [ 51., 204.,   0.],        [102., 153.,   0.],        [153., 102.,   0.],        [204.,  51.,   0.]]]), logfile=False, pixel_format=None)

['/local/rcs/XXX/miniforge3/envs/Zulko+moviepy/lib/python3.9/site-packages/imageio_ffmpeg/binaries/ffmpeg-linux64-v4.2.2', '-y', '-s', '5x1', '-f', 'rawvideo', '-pix_fmt', 'rgb24', '-i', '-', '/tmp/moviepy_ffmpeg_write_image.png']

<Popen: returncode: None args: ['/local/rcs/XXX/miniforge3/envs/Zulko+mov...>

<Popen: returncode: 0 args: ['/local/rcs/XXX/miniforge3/envs/Zulko+moviep...>

b"ffmpeg version 4.2.2-static https://johnvansickle.com/ffmpeg/  Copyright (c) 2000-2019 the FFmpeg developers\n  built with gcc 8 (Debian 8.3.0-6)\n  configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gmp --enable-libgme --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libvmaf --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libdav1d --enable-libxvid --enable-libzvbi --enable-libzimg\n  libavutil      56. 31.100 / 56. 31.100\n  libavcodec     58. 54.100 / 58. 54.100\n  libavformat    58. 29.100 / 58. 29.100\n  libavdevice    58.  8.100 / 58.  8.100\n  libavfilter     7. 57.100 /  7. 57.100\n  libswscale      5.  5.100 /  5.  5.100\n  libswresample   3.  5.100 /  3.  5.100\n  libpostproc    55.  5.100 / 55.  5.100\nInput #0, rawvideo, from 'pipe:':\n  Duration: N/A, start: 0.000000, bitrate: 3 kb/s\n    Stream #0:0: Video: rawvideo (RGB[24] / 0x18424752), rgb24, 5x1, 3 kb/s, 25 tbr, 25 tbn, 25 tbc\nStream mapping:\n  Stream #0:0 -> #0:0 (rawvideo (native) -> png (native))\nOutput #0, image2, to '/tmp/moviepy_ffmpeg_write_image.png':\n  Metadata:\n    encoder         : Lavf58.29.100\n    Stream #0:0: Video: png, rgb24, 5x1, q=2-31, 200 kb/s, 25 fps, 25 tbn, 25 tbc\n    Metadata:\n      encoder         : Lavc58.54.100 png\nframe=    1 fps=0.0 q=-0.0 Lsize=N/A time=00:00:00.04 bitrate=N/A speed=1.64x    \nvideo:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown\n"


def _load_local_committers(path: str, path_to_project_root: str) -> List[Committer]:
    lines = read_lines(path)
    committers = []
    for line in lines:
        initials, name, email = line.rstrip().split(',')
        committers.append(LocalCommitter(initials=initials, name=name, email=email, project_root=path_to_project_root))
    return committers

_load_local_committers(path='/path/to/project/root/.guet/committers', path_to_project_root='/path/to/project/root')

[<guet.committers.local_committer.LocalCommitter object at 0x7fc0ad2c3d00>]


def encode_z1(self, input: Tensor, z2: Tensor) -> List[Tensor]:
        x = self.embed_data(input)
        z2 = self.embed_z2_code(z2)
        z2 = z2.view(-1, self.img_size, self.img_size).unsqueeze(1)
        result = torch.cat([x, z2], dim=1)

        result = self.encoder_z1_layers(result)
        result = torch.flatten(result, start_dim=1)
        z1_mu = self.fc_z1_mu(result)
        z1_log_var = self.fc_z1_var(result)

        return [z1_mu, z1_log_var]

encode_z1(self=HVAE(  (encoder_z2_layers): Sequential(    (0): Sequential(      (0): Conv2d(3, 32, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))      (1): BatchNorm2d(32, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)      (2): LeakyReLU(negative_slope=0.01)    )    (1): Sequential(      (0): Conv2d(32, 64, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))      (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)      (2): LeakyReLU(negative_slope=0.01)    )    (2): Sequential(      (0): Conv2d(64, 128, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))      (1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)      (2): LeakyReLU(negative_slope=0.01)    )    (3): Sequential(      (0): Conv2d(128, 256, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))      (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)      (2): LeakyReLU(negative_slope=0.01)    )    (4): Sequential(      (0): Conv2d(256, 512, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))      (1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)      (2): LeakyReLU(negative_slope=0.01)    )  )  (fc_z2_mu): Linear(in_features=2048, out_features=20, bias=True)  (fc_z2_var): Linear(in_features=2048, out_features=20, bias=True)  (embed_z2_code): Linear(in_features=20, out_features=4096, bias=True)  (embed_data): Conv2d(3, 3, kernel_size=(1, 1), stride=(1, 1))  (encoder_z1_layers): Sequential(    (0): Sequential(      (0): Conv2d(4, 32, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))      (1): BatchNorm2d(32, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)      (2): LeakyReLU(negative_slope=0.01)    )    (1): Sequential(      (0): Conv2d(32, 64, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))      (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)      (2): LeakyReLU(negative_slope=0.01)    )    (2): Sequential(      (0): Conv2d(64, 128, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))      (1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)      (2): LeakyReLU(negative_slope=0.01)    )    (3): Sequential(      (0): Conv2d(128, 256, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))      (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)      (2): LeakyReLU(negative_slope=0.01)    )    (4): Sequential(      (0): Conv2d(256, 512, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))      (1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)      (2): LeakyReLU(negative_slope=0.01)    )  )  (fc_z1_mu): Linear(in_features=2048, out_features=10, bias=True)  (fc_z1_var): Linear(in_features=2048, out_features=10, bias=True)  (recons_z1_mu): Linear(in_features=20, out_features=10, bias=True)  (recons_z1_log_var): Linear(in_features=20, out_features=10, bias=True)  (debed_z1_code): Linear(in_features=10, out_features=1024, bias=True)  (debed_z2_code): Linear(in_features=20, out_features=1024, bias=True)  (decoder): Sequential(    (0): Sequential(      (0): ConvTranspose2d(512, 256, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), output_padding=(1, 1))      (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)      (2): LeakyReLU(negative_slope=0.01)    )    (1): Sequential(      (0): ConvTranspose2d(256, 128, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), output_padding=(1, 1))      (1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)      (2): LeakyReLU(negative_slope=0.01)    )    (2): Sequential(      (0): ConvTranspose2d(128, 64, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), output_padding=(1, 1))      (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)      (2): LeakyReLU(negative_slope=0.01)    )    (3): Sequential(      (0): ConvTranspose2d(64, 32, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), output_padding=(1, 1))      (1): BatchNorm2d(32, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)      (2): LeakyReLU(negative_slope=0.01)    )  )  (final_layer): Sequential(    (0): ConvTranspose2d(32, 32, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), output_padding=(1, 1))    (1): BatchNorm2d(32, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)    (2): LeakyReLU(negative_slope=0.01)    (3): Conv2d(32, 3, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))    (4): Tanh()  )), input=tensor([[[[-1.8936,  0.4196,  1.2842,  ...,  1.2066,  0.7782,  1.3469],          [-0.8224,  0.4527, -0.0577,  ...,  1.4756,  1.1761, -0.7108],          [-1.6315,  0.8043,  2.6413,  ..., -1.3240,  0.9065, -0.8693],          ...,          [ 0.0383,  1.3328, -0.1353,  ..., -1.1770, -0.1116, -0.3206],          [-1.0151,  0.2528, -0.3343,  ..., -0.0416, -0.9868,  1.1128],          [-1.0028, -1.1892,  0.7485,  ...,  0.7481,  0.0498, -0.0744]],         [[-0.2884, -0.2759,  1.1363,  ...,  1.1605,  0.0775, -1.4702],          [-1.6069, -0.0638, -0.8533,  ...,  0.2473,  1.4863,  0.0158],          [ 2.5342,  0.6854,  1.1528,  ...,  0.6568, -0.5946,  0.1834],          ...,          [ 0.3353,  0.0865, -0.9538,  ..., -1.2018, -1.4665, -0.3575],          [-0.3430, -1.4583, -0.7826,  ...,  2.1256, -0.3949,  0.1570],          [ 0.9678, -1.7589,  0.9122,  ...,  0.4558,  1.4173,  1.6013]],         [[-0.7772,  0.4630,  0.6564,  ..., -1.8964, -2.1647, -0.5534],          [ 0.4105,  0.5011,  1.2573,  ...,  0.3236,  0.9842,  1.0977],          [-0.7429,  1.0571,  0.6543,  ...,  0.3400, -0.2293, -0.5091],          ...,          [ 0.1505, -0.3082,  0.3324,  ...,  0.6619, -0.0814,  0.6934],          [-1.7772, -1.9982,  0.5367,  ...,  0.1102, -0.7138,  0.8455],          [ 0.0332, -0.3734, -1.5362,  ..., -1.2318, -0.4791, -1.6185]]],        [[[ 0.0160,  0.7455,  0.3158,  ..., -0.0860,  0.2626,  1.1479],          [-0.4146,  1.8953,  0.0897,  ..., -0.3885,  1.2116, -1.0973],          [-0.6872, -1.8162,  0.1554,  ..., -1.7179,  1.0908,  0.8081],          ...,          [ 0.1696, -1.8558,  0.1469,  ...,  0.3142,  2.3475,  0.4731],          [ 0.1529, -1.0062,  0.7995,  ...,  0.2377,  0.8177,  0.9386],          [ 0.0217, -0.4921, -0.8103,  ...,  2.6341, -0.5868, -0.0105]],         [[ 1.4296,  0.8156, -0.1442,  ..., -1.5969,  0.2655,  1.3892],          [ 0.0990, -0.1513, -0.2613,  ..., -0.5251, -0.1855, -0.1718],          [ 1.4328,  0.2132, -1.6794,  ...,  0.8488,  1.4868, -1.7160],          ...,          [-0.0693,  0.1337,  1.1090,  ..., -1.3724, -2.5672,  1.0906],          [ 0.2655,  0.3716, -0.1245,  ...,  0.7961, -0.3946,  1.0061],          [-0.8810,  0.1413, -0.6222,  ..., -0.4905, -0.3606, -1.0626]],         [[-0.0948, -0.0486,  0.0157,  ...,  2.1004, -1.5879, -0.2739],          [-0.2656,  1.1246,  1.0048,  ...,  0.4671, -0.1705, -0.7745],          [-0.3759,  0.2029, -1.7732,  ..., -0.2653, -2.3626, -1.0251],          ...,          [ 1.4900, -1.3544,  1.5717,  ..., -1.9406,  0.7142, -0.6601],          [ 0.0120,  0.9058,  0.0421,  ...,  1.5632,  1.1624,  0.1822],          [-0.9256,  0.8344, -0.9597,  ..., -0.4188,  0.2051,  0.6043]]],        [[[-0.6292,  1.5933,  1.1558,  ..., -1.0939,  0.3556, -1.9305],          [ 2.2168,  0.9184, -0.6098,  ...,  0.1250,  0.2496,  0.5268],          [ 0.6035, -0.7713,  0.4179,  ...,  0.1061,  0.2763, -1.1580],          ...,          [ 0.6361, -0.9818,  0.2838,  ..., -0.1032, -0.1063,  0.2971],          [-0.9087, -0.8842,  1.3305,  ...,  0.7932,  1.0652, -0.1426],          [-2.2427, -0.6605,  0.9667,  ..., -0.4021, -1.1495, -0.0572]],         [[-0.1344,  0.6562,  0.4687,  ...,  0.1312,  0.5327,  0.3450],          [ 0.4334,  1.3153,  1.9282,  ...,  0.5667,  1.4108,  0.4699],          [ 0.5254, -0.2920,  1.7819,  ..., -0.5157, -0.3931, -0.8093],          ...,          [-0.5848,  0.6157,  1.1588,  ...,  0.5449, -1.0721,  0.5217],          [ 0.3995,  0.2235,  0.2506,  ..., -0.3272,  0.8440,  0.4930],          [-0.8263, -0.0577, -0.9538,  ..., -1.2877,  1.6349,  1.3202]],         [[ 0.6381, -1.4398, -0.7744,  ...,  1.2140,  0.9096, -0.6753],          [ 0.4048, -2.5466,  1.1450,  ...,  0.5030,  0.4698,  0.5673],          [-0.0358,  0.2170, -0.6245,  ..., -0.4325,  0.5767, -0.2755],          ...,          [ 0.3158, -1.6521,  0.9919,  ...,  2.0221, -1.2303,  0.4039],          [ 0.2354, -0.9477, -0.6534,  ..., -0.5600, -1.3333,  0.5403],          [ 1.1120, -2.0893, -1.3755,  ...,  1.9954,  0.8662, -1.6815]]],        ...,        [[[ 1.2590,  0.1363, -0.6754,  ..., -0.8791,  1.2095, -0.1012],          [ 2.3050, -0.1425, -0.9242,  ..., -0.7649, -0.7488,  0.6949],          [ 0.4214,  0.3215, -2.3866,  ..., -0.5338,  0.4479, -0.8477],          ...,          [ 0.1499, -0.5690,  0.0180,  ...,  1.6823,  0.3056, -0.6216],          [-0.3886,  0.6260, -0.6109,  ...,  0.0346,  0.2253, -0.5103],          [-0.1228,  0.1755,  0.1834,  ..., -2.4334, -0.4735,  0.3909]],         [[-0.5463,  0.1758,  0.3594,  ..., -1.5349, -0.1570,  0.0686],          [-0.1374,  1.0209, -0.5383,  ..., -0.9182, -0.2435, -0.2757],          [ 0.6611, -0.2038, -1.1446,  ..., -1.4481,  0.6467, -0.6618],          ...,          [-0.2686,  0.0405, -0.1467,  ...,  1.0902,  0.5896, -0.7653],          [-1.9040,  0.0179,  1.1207,  ..., -0.2288, -1.6366,  1.1901],          [ 0.1832,  0.3417,  0.9626,  ...,  0.3803,  0.7350, -0.3099]],         [[-0.9969, -0.5508, -0.4998,  ...,  0.6936,  1.6136,  0.3220],          [-0.0770,  1.3169,  0.1651,  ...,  1.7485,  0.7226, -0.2574],          [ 0.0803, -0.9462,  1.2021,  ..., -0.0972,  0.0682,  0.1344],          ...,          [-1.7403,  1.7113,  3.0679,  ...,  1.0908,  1.0581, -0.5222],          [ 0.4028, -1.0059, -2.1630,  ..., -0.0682,  0.5164,  1.6635],          [ 2.7208, -0.5648, -0.1862,  ..., -1.5719, -0.3802,  0.2935]]],        [[[ 0.8409, -0.7438, -1.0032,  ...,  0.1318, -0.4320,  0.4415],          [ 1.5099, -1.1524,  1.1499,  ..., -1.6440, -0.0798,  0.6606],          [ 1.0045, -0.9537,  1.1316,  ..., -1.3674, -0.9758, -0.0078],          ...,          [ 0.3468,  0.5475, -0.7472,  ...,  1.5581,  0.2254,  0.8593],          [-0.0717,  0.4480,  1.3726,  ...,  0.6523, -1.1766, -0.3996],          [-1.6755, -0.8156,  0.5543,  ..., -1.4320,  0.4414, -0.1122]],         [[ 1.3380, -1.1875,  0.5178,  ...,  0.3197, -0.7422,  0.5158],          [-1.1908,  1.4007,  0.8123,  ..., -1.4919, -1.7273, -0.0800],          [-1.3901, -0.3755,  0.0897,  ...,  1.6764, -1.3049, -0.0079],          ...,          [-0.1568, -1.4188, -0.7429,  ..., -1.6218,  0.6604,  1.6529],          [ 0.6247,  0.6867, -1.0114,  ..., -0.0381,  0.1275, -0.8645],          [-0.0610,  0.5389,  0.3990,  ..., -1.0361, -2.4215, -0.6971]],         [[ 0.7516, -1.9676,  1.4015,  ...,  0.5336,  1.0704,  1.7422],          [-1.6988, -1.2900, -0.6327,  ..., -0.9592,  1.5238,  0.2264],          [ 1.0729,  0.8629, -0.5775,  ..., -0.7702, -0.0271,  0.7063],          ...,          [ 0.4322,  1.7422,  0.5302,  ...,  1.7000,  1.1956,  0.4742],          [ 0.4945,  0.2216, -1.3425,  ..., -0.9851,  0.1730,  1.0625],          [-0.6886, -0.1384, -0.4764,  ...,  0.3615,  0.5811,  0.4600]]],        [[[-0.8843,  0.8162, -0.5182,  ...,  0.3598, -0.5506, -0.5101],          [-0.4878, -1.6419, -0.5060,  ...,  1.8825, -0.1327,  0.3133],          [ 0.4729,  0.4339,  1.0820,  ..., -1.3299, -0.7871, -0.6630],          ...,          [-1.1407,  0.0937,  1.0086,  ...,  0.2854,  0.4308,  1.1841],          [ 0.3772, -0.8250,  1.1873,  ...,  0.1146, -0.7267,  0.4953],          [-0.3229, -1.0868, -0.0125,  ..., -0.6451,  1.2862, -1.9553]],         [[-0.4689, -0.3666, -0.3470,  ..., -0.0699, -1.9161, -0.4589],          [-0.4437,  0.9324, -2.2532,  ...,  0.1354,  1.1196, -0.0070],          [ 1.1838,  0.3169,  1.2460,  ..., -0.9694,  0.3669,  0.7385],          ...,          [-1.7229,  0.6705,  0.0683,  ...,  1.0143,  0.6204, -1.1060],          [ 0.2528, -2.3181, -0.0774,  ..., -0.3610,  0.4452, -0.3837],          [-1.2532, -0.3006,  0.6067,  ..., -0.8430, -0.5149,  0.8442]],         [[-1.8861, -0.4756,  0.9849,  ...,  0.7845, -0.8080, -0.6442],          [-0.7163,  0.8101, -0.1905,  ...,  0.3361,  0.6133, -0.1919],          [-0.7476, -0.5810, -0.1615,  ..., -0.5631,  0.0637, -0.1969],          ...,          [-0.9449, -0.9001,  1.0701,  ...,  0.4150,  0.1768, -0.4086],          [ 0.5126,  1.4135,  1.6389,  ..., -0.6361, -0.3524, -0.2547],          [ 0.0541, -1.5909, -1.5796,  ..., -0.1662, -0.7188, -0.6655]]]]), z2=tensor([[-1.2900e+00, -1.9974e+00, -1.2873e+00,  6.8312e-01,  1.1999e+00,          5.2038e-01, -1.1960e+00,  5.8112e-01,  1.0388e-01, -1.2854e-01,          4.6986e-01,  4.9946e-01,  7.0090e-01,  3.2990e-01,  6.1682e-01,          4.5016e-01,  6.5489e-01, -3.5582e-01, -5.0099e-01,  8.5103e-01],        [-6.6771e-01, -1.3980e+00, -4.8212e-01, -2.3246e-01,  5.8675e-01,         -4.5213e-01, -5.7778e-02, -9.8022e-02, -2.0276e+00, -2.1314e+00,         -6.2125e-01,  1.7824e+00, -9.2441e-02, -5.5198e-01,  3.9835e-01,         -8.2421e-02,  4.7706e-01, -7.4640e-02, -9.8138e-01,  1.1754e+00],        [-1.9242e-01,  4.4564e-01, -1.7303e-01,  1.7473e+00, -1.4152e+00,          8.4109e-01, -1.9819e+00,  2.4425e+00,  7.1755e-01, -9.0582e-01,         -5.1756e-01,  1.8689e+00, -6.7044e-01, -1.3858e+00, -1.6933e-01,         -6.0295e-01, -3.1655e-01, -9.6165e-01,  1.0204e+00, -6.7928e-01],        [-9.2453e-01,  9.0098e-01,  4.8510e-01,  9.0699e-01, -7.1865e-01,          3.9064e-01, -1.9083e+00, -1.1505e+00,  7.4294e-01, -3.6578e-02,         -5.0377e-02, -1.4724e+00,  1.4315e+00, -1.1902e-01, -2.1044e-01,         -9.7274e-02,  1.4786e+00,  5.8825e-01,  2.4738e-01,  4.7886e-01],        [-5.2584e-01, -5.9981e-02,  9.6410e-02,  1.4674e-01, -2.5624e+00,         -1.2189e+00,  3.6519e-01,  1.9240e+00,  2.7167e+00, -8.9335e-01,         -8.4352e-01,  3.2160e-01,  2.1540e+00,  1.9824e+00,  9.2087e-01,          1.2441e-01, -3.8424e-01,  1.0510e+00, -1.6387e+00, -6.6610e-01],        [ 1.9033e-02, -8.3761e-01, -1.7144e+00, -2.1722e-01,  5.7782e-01,         -8.5884e-01,  1.5352e-01, -3.2194e-02,  1.7006e+00,  2.2611e-01,         -6.6798e-01,  4.2757e-01,  1.1844e+00, -8.2032e-01,  8.5881e-01,         -1.6389e+00, -1.1470e-01,  4.3548e-01, -4.9292e-01, -1.4239e+00],        [-1.8718e-03,  5.0300e-01,  9.4769e-01,  1.3772e-01,  1.2630e+00,          4.9913e-01, -1.8855e+00, -3.6696e-01, -2.0715e-01, -1.8160e-01,          2.6803e-01, -1.7591e-01, -1.1231e+00,  2.9996e-01,  3.0419e-01,          3.2485e-01, -7.8852e-01, -1.3825e+00,  1.5446e+00, -1.5957e+00],        [ 1.2224e+00,  5.4267e-02, -2.8773e-01, -7.6571e-01,  1.3390e-01,          6.8962e-01,  1.7844e-01, -3.5639e-01, -4.0127e-02, -9.6210e-01,         -5.4299e-01,  5.6972e-01,  1.4236e+00, -4.4062e-01,  1.2558e+00,          9.4424e-01,  7.9834e-01, -1.9353e+00,  2.2831e-02,  1.1698e+00],        [ 3.0282e-01,  4.6073e-01, -1.0822e+00, -3.9287e-01, -5.2540e-01,         -6.2057e-01, -1.0958e+00, -1.3846e-01,  9.9414e-01,  1.3613e+00,         -1.3443e+00,  4.5995e-01,  7.6624e-01, -1.8855e+00,  4.2138e-01,          8.1800e-02,  1.0457e+00, -1.3314e+00, -1.4370e+00, -2.2902e-02],        [-1.2029e+00, -4.5437e-01,  2.1817e-01,  5.0700e-01,  2.3848e-01,         -1.5998e+00,  3.1236e+00,  3.2451e-01,  1.0552e+00, -1.3499e-01,         -2.4435e+00,  6.1070e-01,  1.7400e+00, -8.0414e-01, -9.5173e-01,         -3.1292e-01,  2.3043e+00, -1.5358e+00, -1.0775e-01, -1.1630e+00],        [-1.1019e+00,  1.6819e+00, -4.5248e-01,  8.8460e-01, -1.1410e-01,         -1.0526e+00, -8.9691e-01,  4.4700e-01,  3.9597e-01, -8.3095e-01,         -2.4551e+00,  1.1435e-01, -2.9407e-01, -1.2293e+00, -2.8295e+00,         -3.0189e-01,  1.6674e-02, -1.5991e+00,  1.5892e-01, -4.5429e-01],        [ 1.5585e+00, -1.6472e-02, -1.7998e-01, -7.0806e-01, -1.9840e+00,         -5.5717e-01,  7.8396e-01,  4.3221e-01,  1.9304e-02, -8.3582e-01,          3.1031e-01, -4.0005e-01,  2.2043e-01,  4.4766e-01,  1.3857e-01,         -1.0083e+00,  5.1706e-02, -1.2183e+00, -1.8305e-01, -8.0962e-01],        [ 1.1933e+00, -1.9682e-01,  3.0758e-01, -9.4026e-01, -1.5966e-01,          1.2627e+00,  9.4436e-01,  2.0236e-01, -1.1885e+00,  6.8988e-01,         -1.0912e+00, -6.8157e-02,  1.9551e+00, -1.6896e+00, -2.6537e-01,         -1.5902e+00,  1.8715e-02, -1.7566e+00, -4.4485e-01, -2.9117e-01],        [-2.2808e+00, -1.3932e+00, -2.1048e-01, -2.3856e+00,  3.1914e-01,         -6.4313e-01, -8.6689e-01, -1.2414e+00, -9.7393e-01, -1.1433e+00,          1.5302e-01,  6.6312e-01, -1.9848e-01, -1.2353e+00,  2.5797e-01,         -6.6730e-01,  2.6706e-01, -2.6511e+00, -1.1872e+00, -1.0793e+00],        [-9.9676e-01,  4.2526e-01,  1.8178e+00, -9.1751e-03,  8.7009e-01,         -3.2026e-01, -1.0095e+00,  3.5825e-01,  8.4667e-01, -2.8318e-02,          4.1016e-01, -1.4537e+00,  3.3764e+00, -1.7832e+00, -1.0972e+00,          3.9235e-01,  4.3836e-01,  1.4538e-01, -1.1909e+00,  9.7822e-01],        [ 1.2616e+00, -1.4657e-01, -2.5914e+00, -7.2625e-01,  1.2653e+00,         -2.3051e+00,  1.6718e-01, -5.7320e-01, -2.1863e-01, -1.9877e+00,         -1.3305e+00, -1.1724e-01,  1.8090e+00, -5.3239e-01,  2.1936e-01,         -2.3490e+00, -1.7993e+00, -2.7736e+00, -2.0880e-01,  1.0949e+00]],       grad_fn=<AddBackward0>), self._backward_hooks=OrderedDict(), self._backward_pre_hooks=OrderedDict(), self._buffers=OrderedDict(), self._forward_hooks=OrderedDict(), self._forward_hooks_always_called=OrderedDict(), self._forward_hooks_with_kwargs=OrderedDict(), self._forward_pre_hooks=OrderedDict(), self._forward_pre_hooks_with_kwargs=OrderedDict(), self._is_full_backward_hook=None, self._load_state_dict_post_hooks=OrderedDict(), self._load_state_dict_pre_hooks=OrderedDict(), self._modules=OrderedDict([('encoder_z2_layers', Sequential(  (0): Sequential(    (0): Conv2d(3, 32, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))    (1): BatchNorm2d(32, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)    (2): LeakyReLU(negative_slope=0.01)  )  (1): Sequential(    (0): Conv2d(32, 64, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))    (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)    (2): LeakyReLU(negative_slope=0.01)  )  (2): Sequential(    (0): Conv2d(64, 128, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))    (1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)    (2): LeakyReLU(negative_slope=0.01)  )  (3): Sequential(    (0): Conv2d(128, 256, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))    (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)    (2): LeakyReLU(negative_slope=0.01)  )  (4): Sequential(    (0): Conv2d(256, 512, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))    (1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)    (2): LeakyReLU(negative_slope=0.01)  ))), ('fc_z2_mu', Linear(in_features=2048, out_features=20, bias=True)), ('fc_z2_var', Linear(in_features=2048, out_features=20, bias=True)), ('embed_z2_code', Linear(in_features=20, out_features=4096, bias=True)), ('embed_data', Conv2d(3, 3, kernel_size=(1, 1), stride=(1, 1))), ('encoder_z1_layers', Sequential(  (0): Sequential(    (0): Conv2d(4, 32, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))    (1): BatchNorm2d(32, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)    (2): LeakyReLU(negative_slope=0.01)  )  (1): Sequential(    (0): Conv2d(32, 64, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))    (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)    (2): LeakyReLU(negative_slope=0.01)  )  (2): Sequential(    (0): Conv2d(64, 128, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))    (1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)    (2): LeakyReLU(negative_slope=0.01)  )  (3): Sequential(    (0): Conv2d(128, 256, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))    (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)    (2): LeakyReLU(negative_slope=0.01)  )  (4): Sequential(    (0): Conv2d(256, 512, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1))    (1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)    (2): LeakyReLU(negative_slope=0.01)  ))), ('fc_z1_mu', Linear(in_features=2048, out_features=10, bias=True)), ('fc_z1_var', Linear(in_features=2048, out_features=10, bias=True)), ('recons_z1_mu', Linear(in_features=20, out_features=10, bias=True)), ('recons_z1_log_var', Linear(in_features=20, out_features=10, bias=True)), ('debed_z1_code', Linear(in_features=10, out_features=1024, bias=True)), ('debed_z2_code', Linear(in_features=20, out_features=1024, bias=True)), ('decoder', Sequential(  (0): Sequential(    (0): ConvTranspose2d(512, 256, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), output_padding=(1, 1))    (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)    (2): LeakyReLU(negative_slope=0.01)  )  (1): Sequential(    (0): ConvTranspose2d(256, 128, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), output_padding=(1, 1))    (1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)    (2): LeakyReLU(negative_slope=0.01)  )  (2): Sequential(    (0): ConvTranspose2d(128, 64, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), output_padding=(1, 1))    (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)    (2): LeakyReLU(negative_slope=0.01)  )  (3): Sequential(    (0): ConvTranspose2d(64, 32, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), output_padding=(1, 1))    (1): BatchNorm2d(32, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)    (2): LeakyReLU(negative_slope=0.01)  ))), ('final_layer', Sequential(  (0): ConvTranspose2d(32, 32, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), output_padding=(1, 1))  (1): BatchNorm2d(32, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)  (2): LeakyReLU(negative_slope=0.01)  (3): Conv2d(32, 3, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))  (4): Tanh()))]), self._non_persistent_buffers_set=set(), self._parameters=OrderedDict(), self._state_dict_hooks=OrderedDict(), self._state_dict_pre_hooks=OrderedDict(), self.img_size=64, self.latent1_dim=10, self.latent2_dim=20, self.training=True)

Input: tensor([[[[-1.8936,  0.4196,  1.2842,  ...,  1.2066,  0.7782,  1.3469],          [-0.8224,  0.4527, -0.0577,  ...,  1.4756,  1.1761, -0.7108],          [-1.6315,  0.8043,  2.6413,  ..., -1.3240,  0.9065, -0.8693],          ...,          [ 0.0383,  1.3328, -0.1353,  ..., -1.1770, -0.1116, -0.3206],          [-1.0151,  0.2528, -0.3343,  ..., -0.0416, -0.9868,  1.1128],          [-1.0028, -1.1892,  0.7485,  ...,  0.7481,  0.0498, -0.0744]],         [[-0.2884, -0.2759,  1.1363,  ...,  1.1605,  0.0775, -1.4702],          [-1.6069, -0.0638, -0.8533,  ...,  0.2473,  1.4863,  0.0158],          [ 2.5342,  0.6854,  1.1528,  ...,  0.6568, -0.5946,  0.1834],          ...,          [ 0.3353,  0.0865, -0.9538,  ..., -1.2018, -1.4665, -0.3575],          [-0.3430, -1.4583, -0.7826,  ...,  2.1256, -0.3949,  0.1570],          [ 0.9678, -1.7589,  0.9122,  ...,  0.4558,  1.4173,  1.6013]],         [[-0.7772,  0.4630,  0.6564,  ..., -1.8964, -2.1647, -0.5534],          [ 0.4105,  0.5011,  1.2573,  ...,  0.3236,  0.9842,  1.0977],          [-0.7429,  1.0571,  0.6543,  ...,  0.3400, -0.2293, -0.5091],          ...,          [ 0.1505, -0.3082,  0.3324,  ...,  0.6619, -0.0814,  0.6934],          [-1.7772, -1.9982,  0.5367,  ...,  0.1102, -0.7138,  0.8455],          [ 0.0332, -0.3734, -1.5362,  ..., -1.2318, -0.4791, -1.6185]]],        [[[ 0.0160,  0.7455,  0.3158,  ..., -0.0860,  0.2626,  1.1479],          [-0.4146,  1.8953,  0.0897,  ..., -0.3885,  1.2116, -1.0973],          [-0.6872, -1.8162,  0.1554,  ..., -1.7179,  1.0908,  0.8081],          ...,          [ 0.1696, -1.8558,  0.1469,  ...,  0.3142,  2.3475,  0.4731],          [ 0.1529, -1.0062,  0.7995,  ...,  0.2377,  0.8177,  0.9386],          [ 0.0217, -0.4921, -0.8103,  ...,  2.6341, -0.5868, -0.0105]],         [[ 1.4296,  0.8156, -0.1442,  ..., -1.5969,  0.2655,  1.3892],          [ 0.0990, -0.1513, -0.2613,  ..., -0.5251, -0.1855, -0.1718],          [ 1.4328,  0.2132, -1.6794,  ...,  0.8488,  1.4868, -1.7160],          ...,          [-0.0693,  0.1337,  1.1090,  ..., -1.3724, -2.5672,  1.0906],          [ 0.2655,  0.3716, -0.1245,  ...,  0.7961, -0.3946,  1.0061],          [-0.8810,  0.1413, -0.6222,  ..., -0.4905, -0.3606, -1.0626]],         [[-0.0948, -0.0486,  0.0157,  ...,  2.1004, -1.5879, -0.2739],          [-0.2656,  1.1246,  1.0048,  ...,  0.4671, -0.1705, -0.7745],          [-0.3759,  0.2029, -1.7732,  ..., -0.2653, -2.3626, -1.0251],          ...,          [ 1.4900, -1.3544,  1.5717,  ..., -1.9406,  0.7142, -0.6601],          [ 0.0120,  0.9058,  0.0421,  ...,  1.5632,  1.1624,  0.1822],          [-0.9256,  0.8344, -0.9597,  ..., -0.4188,  0.2051,  0.6043]]],        [[[-0.6292,  1.5933,  1.1558,  ..., -1.0939,  0.3556, -1.9305],          [ 2.2168,  0.9184, -0.6098,  ...,  0.1250,  0.2496,  0.5268],          [ 0.6035, -0.7713,  0.4179,  ...,  0.1061,  0.2763, -1.1580],          ...,          [ 0.6361, -0.9818,  0.2838,  ..., -0.1032, -0.1063,  0.2971],          [-0.9087, -0.8842,  1.3305,  ...,  0.7932,  1.0652, -0.1426],          [-2.2427, -0.6605,  0.9667,  ..., -0.4021, -1.1495, -0.0572]],         [[-0.1344,  0.6562,  0.4687,  ...,  0.1312,  0.5327,  0.3450],          [ 0.4334,  1.3153,  1.9282,  ...,  0.5667,  1.4108,  0.4699],          [ 0.5254, -0.2920,  1.7819,  ..., -0.5157, -0.3931, -0.8093],          ...,          [-0.5848,  0.6157,  1.1588,  ...,  0.5449, -1.0721,  0.5217],          [ 0.3995,  0.2235,  0.2506,  ..., -0.3272,  0.8440,  0.4930],          [-0.8263, -0.0577, -0.9538,  ..., -1.2877,  1.6349,  1.3202]],         [[ 0.6381, -1.4398, -0.7744,  ...,  1.2140,  0.9096, -0.6753],          [ 0.4048, -2.5466,  1.1450,  ...,  0.5030,  0.4698,  0.5673],          [-0.0358,  0.2170, -0.6245,  ..., -0.4325,  0.5767, -0.2755],          ...,          [ 0.3158, -1.6521,  0.9919,  ...,  2.0221, -1.2303,  0.4039],          [ 0.2354, -0.9477, -0.6534,  ..., -0.5600, -1.3333,  0.5403],          [ 1.1120, -2.0893, -1.3755,  ...,  1.9954,  0.8662, -1.6815]]],        ...,        [[[ 1.2590,  0.1363, -0.6754,  ..., -0.8791,  1.2095, -0.1012],          [ 2.3050, -0.1425, -0.9242,  ..., -0.7649, -0.7488,  0.6949],          [ 0.4214,  0.3215, -2.3866,  ..., -0.5338,  0.4479, -0.8477],          ...,          [ 0.1499, -0.5690,  0.0180,  ...,  1.6823,  0.3056, -0.6216],          [-0.3886,  0.6260, -0.6109,  ...,  0.0346,  0.2253, -0.5103],          [-0.1228,  0.1755,  0.1834,  ..., -2.4334, -0.4735,  0.3909]],         [[-0.5463,  0.1758,  0.3594,  ..., -1.5349, -0.1570,  0.0686],          [-0.1374,  1.0209, -0.5383,  ..., -0.9182, -0.2435, -0.2757],          [ 0.6611, -0.2038, -1.1446,  ..., -1.4481,  0.6467, -0.6618],          ...,          [-0.2686,  0.0405, -0.1467,  ...,  1.0902,  0.5896, -0.7653],          [-1.9040,  0.0179,  1.1207,  ..., -0.2288, -1.6366,  1.1901],          [ 0.1832,  0.3417,  0.9626,  ...,  0.3803,  0.7350, -0.3099]],         [[-0.9969, -0.5508, -0.4998,  ...,  0.6936,  1.6136,  0.3220],          [-0.0770,  1.3169,  0.1651,  ...,  1.7485,  0.7226, -0.2574],          [ 0.0803, -0.9462,  1.2021,  ..., -0.0972,  0.0682,  0.1344],          ...,          [-1.7403,  1.7113,  3.0679,  ...,  1.0908,  1.0581, -0.5222],          [ 0.4028, -1.0059, -2.1630,  ..., -0.0682,  0.5164,  1.6635],          [ 2.7208, -0.5648, -0.1862,  ..., -1.5719, -0.3802,  0.2935]]],        [[[ 0.8409, -0.7438, -1.0032,  ...,  0.1318, -0.4320,  0.4415],          [ 1.5099, -1.1524,  1.1499,  ..., -1.6440, -0.0798,  0.6606],          [ 1.0045, -0.9537,  1.1316,  ..., -1.3674, -0.9758, -0.0078],          ...,          [ 0.3468,  0.5475, -0.7472,  ...,  1.5581,  0.2254,  0.8593],          [-0.0717,  0.4480,  1.3726,  ...,  0.6523, -1.1766, -0.3996],          [-1.6755, -0.8156,  0.5543,  ..., -1.4320,  0.4414, -0.1122]],         [[ 1.3380, -1.1875,  0.5178,  ...,  0.3197, -0.7422,  0.5158],          [-1.1908,  1.4007,  0.8123,  ..., -1.4919, -1.7273, -0.0800],          [-1.3901, -0.3755,  0.0897,  ...,  1.6764, -1.3049, -0.0079],          ...,          [-0.1568, -1.4188, -0.7429,  ..., -1.6218,  0.6604,  1.6529],          [ 0.6247,  0.6867, -1.0114,  ..., -0.0381,  0.1275, -0.8645],          [-0.0610,  0.5389,  0.3990,  ..., -1.0361, -2.4215, -0.6971]],         [[ 0.7516, -1.9676,  1.4015,  ...,  0.5336,  1.0704,  1.7422],          [-1.6988, -1.2900, -0.6327,  ..., -0.9592,  1.5238,  0.2264],          [ 1.0729,  0.8629, -0.5775,  ..., -0.7702, -0.0271,  0.7063],          ...,          [ 0.4322,  1.7422,  0.5302,  ...,  1.7000,  1.1956,  0.4742],          [ 0.4945,  0.2216, -1.3425,  ..., -0.9851,  0.1730,  1.0625],          [-0.6886, -0.1384, -0.4764,  ...,  0.3615,  0.5811,  0.4600]]],        [[[-0.8843,  0.8162, -0.5182,  ...,  0.3598, -0.5506, -0.5101],          [-0.4878, -1.6419, -0.5060,  ...,  1.8825, -0.1327,  0.3133],          [ 0.4729,  0.4339,  1.0820,  ..., -1.3299, -0.7871, -0.6630],          ...,          [-1.1407,  0.0937,  1.0086,  ...,  0.2854,  0.4308,  1.1841],          [ 0.3772, -0.8250,  1.1873,  ...,  0.1146, -0.7267,  0.4953],          [-0.3229, -1.0868, -0.0125,  ..., -0.6451,  1.2862, -1.9553]],         [[-0.4689, -0.3666, -0.3470,  ..., -0.0699, -1.9161, -0.4589],          [-0.4437,  0.9324, -2.2532,  ...,  0.1354,  1.1196, -0.0070],          [ 1.1838,  0.3169,  1.2460,  ..., -0.9694,  0.3669,  0.7385],          ...,          [-1.7229,  0.6705,  0.0683,  ...,  1.0143,  0.6204, -1.1060],          [ 0.2528, -2.3181, -0.0774,  ..., -0.3610,  0.4452, -0.3837],          [-1.2532, -0.3006,  0.6067,  ..., -0.8430, -0.5149,  0.8442]],         [[-1.8861, -0.4756,  0.9849,  ...,  0.7845, -0.8080, -0.6442],          [-0.7163,  0.8101, -0.1905,  ...,  0.3361,  0.6133, -0.1919],          [-0.7476, -0.5810, -0.1615,  ..., -0.5631,  0.0637, -0.1969],          ...,          [-0.9449, -0.9001,  1.0701,  ...,  0.4150,  0.1768, -0.4086],          [ 0.5126,  1.4135,  1.6389,  ..., -0.6361, -0.3524, -0.2547],          [ 0.0541, -1.5909, -1.5796,  ..., -0.1662, -0.7188, -0.6655]]]])

Input: tensor([[[[-1.8936,  0.4196,  1.2842,  ...,  1.2066,  0.7782,  1.3469],          [-0.8224,  0.4527, -0.0577,  ...,  1.4756,  1.1761, -0.7108],          [-1.6315,  0.8043,  2.6413,  ..., -1.3240,  0.9065, -0.8693],          ...,          [ 0.0383,  1.3328, -0.1353,  ..., -1.1770, -0.1116, -0.3206],          [-1.0151,  0.2528, -0.3343,  ..., -0.0416, -0.9868,  1.1128],          [-1.0028, -1.1892,  0.7485,  ...,  0.7481,  0.0498, -0.0744]],         [[-0.2884, -0.2759,  1.1363,  ...,  1.1605,  0.0775, -1.4702],          [-1.6069, -0.0638, -0.8533,  ...,  0.2473,  1.4863,  0.0158],          [ 2.5342,  0.6854,  1.1528,  ...,  0.6568, -0.5946,  0.1834],          ...,          [ 0.3353,  0.0865, -0.9538,  ..., -1.2018, -1.4665, -0.3575],          [-0.3430, -1.4583, -0.7826,  ...,  2.1256, -0.3949,  0.1570],          [ 0.9678, -1.7589,  0.9122,  ...,  0.4558,  1.4173,  1.6013]],         [[-0.7772,  0.4630,  0.6564,  ..., -1.8964, -2.1647, -0.5534],          [ 0.4105,  0.5011,  1.2573,  ...,  0.3236,  0.9842,  1.0977],          [-0.7429,  1.0571,  0.6543,  ...,  0.3400, -0.2293, -0.5091],          ...,          [ 0.1505, -0.3082,  0.3324,  ...,  0.6619, -0.0814,  0.6934],          [-1.7772, -1.9982,  0.5367,  ...,  0.1102, -0.7138,  0.8455],          [ 0.0332, -0.3734, -1.5362,  ..., -1.2318, -0.4791, -1.6185]]],        [[[ 0.0160,  0.7455,  0.3158,  ..., -0.0860,  0.2626,  1.1479],          [-0.4146,  1.8953,  0.0897,  ..., -0.3885,  1.2116, -1.0973],          [-0.6872, -1.8162,  0.1554,  ..., -1.7179,  1.0908,  0.8081],          ...,          [ 0.1696, -1.8558,  0.1469,  ...,  0.3142,  2.3475,  0.4731],          [ 0.1529, -1.0062,  0.7995,  ...,  0.2377,  0.8177,  0.9386],          [ 0.0217, -0.4921, -0.8103,  ...,  2.6341, -0.5868, -0.0105]],         [[ 1.4296,  0.8156, -0.1442,  ..., -1.5969,  0.2655,  1.3892],          [ 0.0990, -0.1513, -0.2613,  ..., -0.5251, -0.1855, -0.1718],          [ 1.4328,  0.2132, -1.6794,  ...,  0.8488,  1.4868, -1.7160],          ...,          [-0.0693,  0.1337,  1.1090,  ..., -1.3724, -2.5672,  1.0906],          [ 0.2655,  0.3716, -0.1245,  ...,  0.7961, -0.3946,  1.0061],          [-0.8810,  0.1413, -0.6222,  ..., -0.4905, -0.3606, -1.0626]],         [[-0.0948, -0.0486,  0.0157,  ...,  2.1004, -1.5879, -0.2739],          [-0.2656,  1.1246,  1.0048,  ...,  0.4671, -0.1705, -0.7745],          [-0.3759,  0.2029, -1.7732,  ..., -0.2653, -2.3626, -1.0251],          ...,          [ 1.4900, -1.3544,  1.5717,  ..., -1.9406,  0.7142, -0.6601],          [ 0.0120,  0.9058,  0.0421,  ...,  1.5632,  1.1624,  0.1822],          [-0.9256,  0.8344, -0.9597,  ..., -0.4188,  0.2051,  0.6043]]],        [[[-0.6292,  1.5933,  1.1558,  ..., -1.0939,  0.3556, -1.9305],          [ 2.2168,  0.9184, -0.6098,  ...,  0.1250,  0.2496,  0.5268],          [ 0.6035, -0.7713,  0.4179,  ...,  0.1061,  0.2763, -1.1580],          ...,          [ 0.6361, -0.9818,  0.2838,  ..., -0.1032, -0.1063,  0.2971],          [-0.9087, -0.8842,  1.3305,  ...,  0.7932,  1.0652, -0.1426],          [-2.2427, -0.6605,  0.9667,  ..., -0.4021, -1.1495, -0.0572]],         [[-0.1344,  0.6562,  0.4687,  ...,  0.1312,  0.5327,  0.3450],          [ 0.4334,  1.3153,  1.9282,  ...,  0.5667,  1.4108,  0.4699],          [ 0.5254, -0.2920,  1.7819,  ..., -0.5157, -0.3931, -0.8093],          ...,          [-0.5848,  0.6157,  1.1588,  ...,  0.5449, -1.0721,  0.5217],          [ 0.3995,  0.2235,  0.2506,  ..., -0.3272,  0.8440,  0.4930],          [-0.8263, -0.0577, -0.9538,  ..., -1.2877,  1.6349,  1.3202]],         [[ 0.6381, -1.4398, -0.7744,  ...,  1.2140,  0.9096, -0.6753],          [ 0.4048, -2.5466,  1.1450,  ...,  0.5030,  0.4698,  0.5673],          [-0.0358,  0.2170, -0.6245,  ..., -0.4325,  0.5767, -0.2755],          ...,          [ 0.3158, -1.6521,  0.9919,  ...,  2.0221, -1.2303,  0.4039],          [ 0.2354, -0.9477, -0.6534,  ..., -0.5600, -1.3333,  0.5403],          [ 1.1120, -2.0893, -1.3755,  ...,  1.9954,  0.8662, -1.6815]]],        ...,        [[[ 1.2590,  0.1363, -0.6754,  ..., -0.8791,  1.2095, -0.1012],          [ 2.3050, -0.1425, -0.9242,  ..., -0.7649, -0.7488,  0.6949],          [ 0.4214,  0.3215, -2.3866,  ..., -0.5338,  0.4479, -0.8477],          ...,          [ 0.1499, -0.5690,  0.0180,  ...,  1.6823,  0.3056, -0.6216],          [-0.3886,  0.6260, -0.6109,  ...,  0.0346,  0.2253, -0.5103],          [-0.1228,  0.1755,  0.1834,  ..., -2.4334, -0.4735,  0.3909]],         [[-0.5463,  0.1758,  0.3594,  ..., -1.5349, -0.1570,  0.0686],          [-0.1374,  1.0209, -0.5383,  ..., -0.9182, -0.2435, -0.2757],          [ 0.6611, -0.2038, -1.1446,  ..., -1.4481,  0.6467, -0.6618],          ...,          [-0.2686,  0.0405, -0.1467,  ...,  1.0902,  0.5896, -0.7653],          [-1.9040,  0.0179,  1.1207,  ..., -0.2288, -1.6366,  1.1901],          [ 0.1832,  0.3417,  0.9626,  ...,  0.3803,  0.7350, -0.3099]],         [[-0.9969, -0.5508, -0.4998,  ...,  0.6936,  1.6136,  0.3220],          [-0.0770,  1.3169,  0.1651,  ...,  1.7485,  0.7226, -0.2574],          [ 0.0803, -0.9462,  1.2021,  ..., -0.0972,  0.0682,  0.1344],          ...,          [-1.7403,  1.7113,  3.0679,  ...,  1.0908,  1.0581, -0.5222],          [ 0.4028, -1.0059, -2.1630,  ..., -0.0682,  0.5164,  1.6635],          [ 2.7208, -0.5648, -0.1862,  ..., -1.5719, -0.3802,  0.2935]]],        [[[ 0.8409, -0.7438, -1.0032,  ...,  0.1318, -0.4320,  0.4415],          [ 1.5099, -1.1524,  1.1499,  ..., -1.6440, -0.0798,  0.6606],          [ 1.0045, -0.9537,  1.1316,  ..., -1.3674, -0.9758, -0.0078],          ...,          [ 0.3468,  0.5475, -0.7472,  ...,  1.5581,  0.2254,  0.8593],          [-0.0717,  0.4480,  1.3726,  ...,  0.6523, -1.1766, -0.3996],          [-1.6755, -0.8156,  0.5543,  ..., -1.4320,  0.4414, -0.1122]],         [[ 1.3380, -1.1875,  0.5178,  ...,  0.3197, -0.7422,  0.5158],          [-1.1908,  1.4007,  0.8123,  ..., -1.4919, -1.7273, -0.0800],          [-1.3901, -0.3755,  0.0897,  ...,  1.6764, -1.3049, -0.0079],          ...,          [-0.1568, -1.4188, -0.7429,  ..., -1.6218,  0.6604,  1.6529],          [ 0.6247,  0.6867, -1.0114,  ..., -0.0381,  0.1275, -0.8645],          [-0.0610,  0.5389,  0.3990,  ..., -1.0361, -2.4215, -0.6971]],         [[ 0.7516, -1.9676,  1.4015,  ...,  0.5336,  1.0704,  1.7422],          [-1.6988, -1.2900, -0.6327,  ..., -0.9592,  1.5238,  0.2264],          [ 1.0729,  0.8629, -0.5775,  ..., -0.7702, -0.0271,  0.7063],          ...,          [ 0.4322,  1.7422,  0.5302,  ...,  1.7000,  1.1956,  0.4742],          [ 0.4945,  0.2216, -1.3425,  ..., -0.9851,  0.1730,  1.0625],          [-0.6886, -0.1384, -0.4764,  ...,  0.3615,  0.5811,  0.4600]]],        [[[-0.8843,  0.8162, -0.5182,  ...,  0.3598, -0.5506, -0.5101],          [-0.4878, -1.6419, -0.5060,  ...,  1.8825, -0.1327,  0.3133],          [ 0.4729,  0.4339,  1.0820,  ..., -1.3299, -0.7871, -0.6630],          ...,          [-1.1407,  0.0937,  1.0086,  ...,  0.2854,  0.4308,  1.1841],          [ 0.3772, -0.8250,  1.1873,  ...,  0.1146, -0.7267,  0.4953],          [-0.3229, -1.0868, -0.0125,  ..., -0.6451,  1.2862, -1.9553]],         [[-0.4689, -0.3666, -0.3470,  ..., -0.0699, -1.9161, -0.4589],          [-0.4437,  0.9324, -2.2532,  ...,  0.1354,  1.1196, -0.0070],          [ 1.1838,  0.3169,  1.2460,  ..., -0.9694,  0.3669,  0.7385],          ...,          [-1.7229,  0.6705,  0.0683,  ...,  1.0143,  0.6204, -1.1060],          [ 0.2528, -2.3181, -0.0774,  ..., -0.3610,  0.4452, -0.3837],          [-1.2532, -0.3006,  0.6067,  ..., -0.8430, -0.5149,  0.8442]],         [[-1.8861, -0.4756,  0.9849,  ...,  0.7845, -0.8080, -0.6442],          [-0.7163,  0.8101, -0.1905,  ...,  0.3361,  0.6133, -0.1919],          [-0.7476, -0.5810, -0.1615,  ..., -0.5631,  0.0637, -0.1969],          ...,          [-0.9449, -0.9001,  1.0701,  ...,  0.4150,  0.1768, -0.4086],          [ 0.5126,  1.4135,  1.6389,  ..., -0.6361, -0.3524, -0.2547],          [ 0.0541, -1.5909, -1.5796,  ..., -0.1662, -0.7188, -0.6655]]]])


def subprocess_call(cmd, logger="bar"):
    """Executes the given subprocess command.

    Set logger to None or a custom Proglog logger to avoid printings.
    """
    logger = proglog.default_bar_logger(logger)
    logger(message="MoviePy - Running:\n>>> " + " ".join(cmd))

    popen_params = cross_platform_popen_params(
        {"stdout": sp.DEVNULL, "stderr": sp.PIPE, "stdin": sp.DEVNULL}
    )

    proc = sp.Popen(cmd, **popen_params)

    out, err = proc.communicate()  # proc.wait()
    proc.stderr.close()

    if proc.returncode:
        logger(message="MoviePy - Command returned an error")
        raise IOError(err.decode("utf8"))
    else:
        logger(message="MoviePy - Command successful")

    del proc

subprocess_call(cmd=['unset', '-background', 'transparent', '-fill', 'white', '-font', 'Liberation-Mono', '-pointsize', '25', '-size', '640x480', '-gravity', 'center', 'caption:@/tmp/tmp6pdbi5v3.txt', '-type', 'truecolormatte', 'PNG32:/tmp/tmpkd0efulh.png'], logger=None)

{state={'bars': OrderedDict(), 'message': 'MoviePy - Running:\n>>> unset -background transparent -fill white -font Liberation-Mono -pointsize 25 -size 640x480 -gravity center caption:@/tmp/tmp6pdbi5v3.txt -type truecolormatte PNG32:/tmp/tmpkd0efulh.png'}, stored={}, logs=[], log_indent=0, ignored_bars=None, logged_bars='all', min_time_interval=0, ignore_bars_under=0}

{state={'bars': OrderedDict()}, stored={}, logs=[], log_indent=0, ignored_bars=None, logged_bars='all', min_time_interval=0, ignore_bars_under=0}


def client_factory(client_name, **kwargs):
    """Return a client for an external data set"""
    # set up
    dir_name = os.path.dirname(os.path.abspath(__file__))
    error_msg = 'No client found for name %s' % client_name
    client_key = client_name.upper()

    # find client
    try:
        client_vals = BALANCING_AUTHORITIES[client_key]
        module_name = client_vals['module']

        class_name = client_vals['class']
    except KeyError:
        raise ValueError(error_msg)

    # find module
    try:
        fp, pathname, description = imp.find_module(module_name, [dir_name])
    except ImportError:
        raise ValueError(error_msg)

    # load
    try:
        mod = imp.load_module(module_name, fp, pathname, description)
    finally:
        # Since we may exit via an exception, close fp explicitly.
        if fp:
            fp.close()

    # instantiate class
    try:
        client_inst = getattr(mod, class_name)(**kwargs)
    except AttributeError:
        raise ValueError(error_msg)

    # set name
    client_inst.NAME = client_name

    return client_inst

client_factory(client_name='MISO', kwargs={})

{'module': 'miso', 'class': 'MISOClient'}

('.py', 'r', 1)


def get_generation(ba_name, **kwargs):
    # get data
    c = client_factory(ba_name)
    data = c.get_generation(**kwargs)

    # log
    if len(data) == 0:
        msg = '%s: No generation data at %s with args %s' % (ba_name, datetime.utcnow().isoformat(),
                                                    kwargs)
        logger.warn(msg)

    # return
    return data

get_generation(ba_name='CAISO', kwargs={'latest': True})

"CAISO: No generation data at 2024-04-03T22:46:21.338362 with args {'latest': True}"

{options={'data': 'gen', 'latest': True, 'yesterday': False, 'start_at': False, 'end_at': False, 'sliceable': False, 'forecast': False, 'market': 'RT5M', 'freq': '10m'}, NAME='CAISO', session=<requests.sessions.Session object at 0x7fcc37a98b50>}


def get_load(ba_name, **kwargs):
    # get data
    c = client_factory(ba_name)
    data = c.get_load(**kwargs)

    # log
    if len(data) == 0:
        msg = '%s: No load data at %s with args %s' % (ba_name, datetime.utcnow().isoformat(),
                                                    kwargs)
        logger.warn(msg)

    # return
    return data

get_load(ba_name='PJM', kwargs={'latest': True})

"PJM: No load data at 2024-04-03T22:47:45.327834 with args {'latest': True}"

{options={'data': 'load', 'latest': True, 'start_at': None, 'end_at': None, 'forecast': False, 'sliceable': False}, NAME='PJM', session=<requests.sessions.Session object at 0x7fcc37745f10>}


def xldate_as_tuple(xldate, datemode):
    if datemode not in (0, 1):
        raise XLDateBadDatemode(datemode)
    if xldate == 0.00:
        return (0, 0, 0, 0, 0, 0)
    if xldate < 0.00:
        raise XLDateNegative(xldate)
    xldays = int(xldate)
    frac = xldate - xldays
    seconds = int(round(frac * 86400.0))
    assert 0 <= seconds <= 86400
    if seconds == 86400:
        hour = minute = second = 0
        xldays += 1
    else:
        # second = seconds % 60; minutes = seconds // 60
        minutes, second = divmod(seconds, 60)
        # minute = minutes % 60; hour    = minutes // 60
        hour, minute = divmod(minutes, 60)
    if xldays >= _XLDAYS_TOO_LARGE[datemode]:
        raise XLDateTooLarge(xldate)

    if xldays == 0:
        return (0, 0, 0, hour, minute, second)

    if xldays < 61 and datemode == 0:
        raise XLDateAmbiguous(xldate)

    jdn = xldays + _JDN_delta[datemode]
    yreg = (ifd(ifd(jdn * 4 + 274277, 146097) * 3, 4) + jdn + 1363) * 4 + 3
    mp = ifd(yreg % 1461, 4) * 535 + 333
    d = ifd(mp % 16384, 535) + 1
    # mp /= 16384
    mp >>= 14
    if mp >= 10:
        return (ifd(yreg, 1461) - 4715, mp - 9, d, hour, minute, second)
    else:
        return (ifd(yreg, 1461) - 4716, mp + 3, d, hour, minute, second)

xldate_as_tuple(xldate=2741.0, datemode=0)


def xldate_from_date_tuple(date_tuple, datemode):
    """Create an excel date from a tuple of (year, month, day)"""
    year, month, day = date_tuple

    if datemode not in (0, 1):
        raise XLDateBadDatemode(datemode)

    if year == 0 and month == 0 and day == 0:
        return 0.00

    if not (1900 <= year <= 9999):
        raise XLDateBadTuple("Invalid year: %r" % ((year, month, day),))
    if not (1 <= month <= 12):
        raise XLDateBadTuple("Invalid month: %r" % ((year, month, day),))
    if  day < 1 \
    or (day > _days_in_month[month] and not(day == 29 and month == 2 and _leap(year))):
        raise XLDateBadTuple("Invalid day: %r" % ((year, month, day),))

    Yp = year + 4716
    M = month
    if M <= 2:
        Yp = Yp - 1
        Mp = M + 9
    else:
        Mp = M - 3
    jdn = ifd(1461 * Yp, 4) + ifd(979 * Mp + 16, 32) + \
        day - 1364 - ifd(ifd(Yp + 184, 100) * 3, 4)
    xldays = jdn - _JDN_delta[datemode]
    if xldays <= 0:
        raise XLDateBadTuple("Invalid (year, month, day): %r" % ((year, month, day),))
    if xldays < 61 and datemode == 0:
        raise XLDateAmbiguous("Before 1900-03-01: %r" % ((year, month, day),))
    return float(xldays)

xldate_from_date_tuple(date_tuple=(1907, 7, 3), datemode=0)


def _add_notice_to_docstring(doc, no_doc_str, notice):
    """Adds a deprecation notice to a docstring."""
    if not doc:
        lines = [no_doc_str]

    else:
        lines = _normalize_docstring(doc).splitlines()

    notice = [''] + notice

    if len(lines) > 1:
        # Make sure that we keep our distance from the main body
        if lines[1].strip():
            notice.append('')

        lines[1:1] = notice
    else:
        lines += notice

    return '\n'.join(lines)

_add_notice_to_docstring(doc=None, no_doc_str='DEPRECATED FUNCTION', notice=['\n            .. warning::\n                **THIS FUNCTION IS DEPRECATED:** It will be removed after after 2018-09-30.\n                *Instructions for updating:* This API is deprecated. Please use as `tl.logging.warning`.\n        '])

['', '\n            .. warning::\n                **THIS FUNCTION IS DEPRECATED:** It will be removed after after 2018-09-30.\n                *Instructions for updating:* This API is deprecated. Please use as `tl.logging.warning`.\n        ']

['DEPRECATED FUNCTION', '', '\n            .. warning::\n                **THIS FUNCTION IS DEPRECATED:** It will be removed after after 2018-09-30.\n                *Instructions for updating:* This API is deprecated. Please use as `tl.logging.warning`.\n        ']


def calculate_r_wheels(tyre_dimensions):
    """
    Calculates the radius of the wheels [m] from the tyre dimensions.

    :param tyre_dimensions:
        Tyre dimensions.

        .. note:: The fields are : use, nominal_section_width, aspect_ratio,
           carcass, diameter, load_index, speed_rating, and additional_marks.
    :type tyre_dimensions: dict

    :return:
        Radius of the wheels [m].
    :rtype: float
    """
    if 'diameter' in tyre_dimensions:
        if tyre_dimensions['code'] == 'pax':
            return tyre_dimensions['diameter'] / 2000  # Diameter is in mm.
        return tyre_dimensions['diameter'] * 0.0254  # Diameter is in inches.
    a = tyre_dimensions['aspect_ratio'] / 100  # Aspect ratio is Height/Width.
    w = tyre_dimensions['nominal_section_width']
    if tyre_dimensions.get('code', 'iso') == 'iso':
        w /= 1000  # Width is in mm.
    else:
        w *= 0.0254  # Width is in inches.

    dr = tyre_dimensions['rim_diameter'] * 0.0254  # Rim is in inches.
    return a * w + dr / 2

calculate_r_wheels(tyre_dimensions={'code': 'iso', 'carcass': 'R', 'nominal_section_width': 265.0, 'use': 'LT', 'load_range': 'D', 'rim_diameter': 15.0, 'aspect_ratio': 75.0})


def create_dummy_class(klass, dependency, message=""):
    """
    When a dependency of a class is not available, create a dummy class which throws ImportError
    when used.

    Args:
        klass (str): name of the class.
        dependency (str): name of the dependency.
        message: extra message to print
    Returns:
        class: a class object
    """
    err = "Cannot import '{}', therefore '{}' is not available.".format(dependency, klass)
    if message:
        err = err + " " + message

    class _DummyMetaClass(type):
        # throw error on class attribute access
        def __getattr__(_, __):  # noqa: B902
            raise ImportError(err)

    class _Dummy(object, metaclass=_DummyMetaClass):
        # throw error on constructor
        def __init__(self, *args, **kwargs):
            raise ImportError(err)

    return _Dummy

create_dummy_class(klass='DeformConv', dependency='detectron2._C', message='detectron2 is not compiled successfully, please build following the instructions!')

"Cannot import 'detectron2._C', therefore 'DeformConv' is not available. detectron2 is not compiled successfully, please build following the instructions!"

"Cannot import 'detectron2._C', therefore 'DeformConv' is not available."


def create_dummy_func(func, dependency, message=""):
    """
    When a dependency of a function is not available, create a dummy function which throws
    ImportError when used.

    Args:
        func (str): name of the function.
        dependency (str or list[str]): name(s) of the dependency.
        message: extra message to print
    Returns:
        function: a function object
    """
    err = "Cannot import '{}', therefore '{}' is not available.".format(dependency, func)
    if message:
        err = err + " " + message

    if isinstance(dependency, (list, tuple)):
        dependency = ",".join(dependency)

    def _dummy(*args, **kwargs):
        raise ImportError(err)

    return _dummy

create_dummy_func(func='deform_conv', dependency='detectron2._C', message='detectron2 is not compiled successfully, please build following the instructions!')

"Cannot import 'detectron2._C', therefore 'deform_conv' is not available. detectron2 is not compiled successfully, please build following the instructions!"

"Cannot import 'detectron2._C', therefore 'deform_conv' is not available."

<function create_dummy_func.<locals>._dummy at 0x7f3337cdfd30>


def format_pair(prefix, arg, value):
    if arg is _arg_source_missing:
        arg_lines = []
        value_prefix = prefix
    else:
        arg_lines = indented_lines(prefix, arg)
        value_prefix = arg_lines[-1] + ': '

    looksLikeAString = value[0] + value[-1] in ["''", '""']
    if looksLikeAString:  # Align the start of multiline strings.
        value = prefixLinesAfterFirst(' ', value)

    value_lines = indented_lines(value_prefix, value)
    lines = arg_lines[:-1] + value_lines
    return '\n'.join(lines)

format_pair(prefix='    ', arg='multilineStr', value="'line1\nline2'")


def prefixLinesAfterFirst(prefix, s):
    lines = s.splitlines(True)

    for i in range(1, len(lines)):
        lines[i] = prefix + lines[i]

    return ''.join(lines)

prefixLinesAfterFirst(prefix=' ', s="'line1\nline2'")


def _sort(a, aux, lo, hi):
        if lo >= hi:
            return

        if hi - lo + 1 < MergeSort.CUTOFF:
            InsertionSort.sort(a, lo, hi)
            return

        mid = lo + (hi - lo) // 2
        MergeSort._sort(a, aux, lo, mid)
        MergeSort._sort(a, aux, mid + 1, hi)
        MergeSort._merge(a, aux, lo, mid, hi)

_sort(a=[4, 2, 1, 23, 4, 5, 6, 7, 8, 9, 20, 11, 13, 34, 66], aux=[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], lo=0, hi=7)


def version_compare(self, other):
        "Compares version of the form [epoch:]upstream-version[-debian-revision]" \
        + " according to Debian package version number format."

        # compare epoch
        diff = self.epoch - other.epoch
        if diff != 0:
            return diff

        # compare upstream version and debian revision
        for slf, othr in (self.upstream_version, other.upstream_version), (self.revision, other.revision):
            i = 0
            while len(slf) > 0 or len(othr) > 0:
                decimal = (i % 2 == 1)
                slf_part, slf = self._get_part(slf, decimal=decimal)
                othr_part, othr = self._get_part(othr, decimal=decimal)
                diff = self._compare_parts(slf_part, othr_part, decimal=decimal)
                if diff != 0:
                    return diff
                i += 1

        # versions are equal
        return 0

version_compare(self=2.2.0~rc5, other=2.2.0~rc5, self.epoch=0, self.revision='0', self.revision_allowed_chars=('.', '+', '~'), self.upstream_version='2.2.0~rc5', self.upstream_version_allowed_chars=('.', '+', '~', '-', ':'), self.version='2.2.0~rc5')


def _setHeaderBaseData(array, coeff_name, hao, long_name) -> None:
        if not isinstance(array, (np.ndarray, np.float32, np.int32,np.float64)):
            print(type(array))
            raise HeaderArrayObj.UnsupportedArrayType("'array' must be of numpy.ndarray type.")

        # Defaults handling
        if coeff_name is None:
            coeff_name = " " * 12
        if long_name is None:
            long_name = coeff_name
        if len(coeff_name) < 12:
            coeff_name = coeff_name.ljust(12)
        if len(long_name) < 70:
            long_name = long_name.ljust(70)
        hao.array = array
        hao.coeff_name = coeff_name
        hao.long_name = long_name

_setHeaderBaseData(array=array(['at 2/03/2018 4:22:38 PM                                               '],      dtype='<U70'), coeff_name=None, hao={_coeff_name='', _array=None, _sets=None, _long_name=''}, long_name='Creation Date and Time                                                ')

'Creation Date and Time                                                '

{_coeff_name='            ', _array=array(['at 2/03/2018 4:22:38 PM                                               '],      dtype='<U70'), _sets=None, _long_name='Creation Date and Time                                                '}


def SetHeaderFromData(setName: str, setElements:'Union[List[str], np.array]',  long_name: str=None):
        if not isinstance(setName,str):
            raise TypeError("setName must be of type str")
        if len(setName.strip()) > 12 :
            raise ValueError("setName is restricted to 12 Characters")
        if long_name is None: long_name=""
        if isinstance(long_name, str):
            long_name="Set "+setName.strip()+" "+long_name.strip()
        else:
            raise TypeError("LongName must be string")

        if isinstance(setElements,(list,np.ndarray)):
            if not all([isinstance(el,str) for el in setElements]):
                raise TypeError("All Set Elements must be of type str")
            if not all([len(el)<=12 for el in setElements]):
                raise ValueError("Set Elelement strings must be 12 characters at most")

        if isinstance(setElements,list):
            array=np.array(setElements)
            setElDict={setName:setElements}
        elif isinstance(setElements,np.ndarray):
            array=setElements
            setElDict = {setName: setElements.tolist()}
        else:
            raise TypeError("SetElemenets must be list of str or np array of strings")

        return HeaderArrayObj.HeaderArrayFromData(array=array, long_name=long_name, sets=[setName], setElDict=setElDict)

SetHeaderFromData(setName='sect', setElements=array(['s1          ', 's2          '], dtype='<U12'), long_name=' Sectors                                                                        ')

' Sectors                                                                        '


def set_bbox(self, bbox: Rect) -> None:
        (x0, y0, x1, y1) = bbox
        self.x0 = x0
        self.y0 = y0
        self.x1 = x1
        self.y1 = y1
        self.width = x1 - x0
        self.height = y1 - y0
        self.bbox = bbox

set_bbox(self=REPR FAILED, bbox=[0, 100, 0, 100])


def calibrated_fps(calibrate):
    """Calibration of the dynamic frames per second engine.

    I've started with the equation y = log10(x + m) * k + n, where:
      y is the desired fps, m and n are horizontal and vertical translation,
      k is a calibration factor, computed from some user input c (see readme for details).

    Considering minfps and maxfps as given constants, I came to:
      fps = log10(x + 1) * k + minfps, which must be equal to maxfps for x = c,
    so the factor k = (maxfps - minfps) / log10(c + 1), and
      fps = log10(x + 1) * (maxfps - minfps) / log10(c + 1) + minfps

    Neat! ;)

    Args:
        calibrate (float): user provided

    Returns:
        a callable to calculate the fps

    """
    min_fps, max_fps = 2., 60.
    calibrate = max(1e-6, calibrate)
    adjust_log_curve = 100. / min(calibrate, 100.)  # adjust the curve for small numbers
    factor = (max_fps - min_fps) / math.log10((calibrate * adjust_log_curve) + 1.)

    def fps(rate):
        if rate <= 0:
            return 10.  # bootstrap speed
        if rate < calibrate:
            return math.log10((rate * adjust_log_curve) + 1.) * factor + min_fps
        return max_fps

    return fps

calibrated_fps(calibrate=-5.0)

<function calibrated_fps.<locals>.fps at 0x7f355669f1f0>


def getblockimpl(lines, first, last, pilcrow):
    max = len(lines) - 1
    first -= 1
    last -= 1
    i = first
    while i < max and not hastext(lines[i]):
        if i >= last and istoplevel(lines[i + 1]):
            return None, None, '# Nothing to send.' + pilcrow + eol
        i += 1
    while last < max and not istoplevel(lines[last + 1]):
        last += 1
    while first < last and not hastext(lines[first]):
        first += 1
    while first and not istoplevel(lines[first]):
        first -= 1
    lines[last] # Check for out of range.
    return first, last, eol.join(l for l in lines[first:last + 1] if hastext(l)) + pilcrow + eol

getblockimpl(lines=['', 'hello', 'function with', ' indented block', 'class with', '', '  block after blank', '  \tand its own indented block', '\t', '  and back again after a wrong blank', '', 'something else', '\t', ' \t', 'last'], first=10, last=11, pilcrow='')


def _from_timetuple(self, t):
        self.days_from_epoch = calendar.timegm(t) // Date.DAY

_from_timetuple(self=Date(0), t=time.struct_time(tm_year=2024, tm_mon=4, tm_mday=3, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=2, tm_yday=94, tm_isdst=-1))


def _insert(self, key, value):
        flat_key = self._serialize_key(key)
        i = self._index.get(flat_key, -1)
        if i >= 0:
            self._items[i] = (key, value)
        else:
            self._items.append((key, value))
            self._index[flat_key] = len(self._items) - 1

_insert(self=OrderedMapSerializedKey([]), key='みbob', value=199)


def stringified_dict_contains_value(key, value, str_dict):
    """Checks if dict in for of string like "{'test': 5}" contains
    key/value pair. This works faster, then creating actual dict
    from string since this operation is called for each task in case
    of kwargs search."""
    if not str_dict:
        return False
    value = str(value)
    try:
        # + 3 for key right quote, one for colon and one for space
        key_index = str_dict.index(key) + len(key) + 3
    except ValueError:
        return False
    try:
        comma_index = str_dict.index(',', key_index)
    except ValueError:
        # last value in dict
        comma_index = str_dict.index('}', key_index)
    return str(value) == str_dict[key_index:comma_index].strip('"\'')

stringified_dict_contains_value(key='test', value=5, str_dict="{'test': 5}")


def merge_args_into_config(args, config_params):
  final_args = copy.deepcopy(config_params)
  config_keys = config_params.keys()
  for key, value in args.items():
    if key in config_keys:
      if any([isinstance(value, t) for t in [str, bool, float, int]]):
        # Overwrites config value with args value.
        final_args[key] = value
      elif isinstance(value, list):
        # Appends args values to config values.
        final_args[key] = value + config_params[key]
      elif isinstance(value, dict):
        # Updates config params with args params.
        final_args[key].update(**value)
    else:
      final_args[key] = value
  return final_args

merge_args_into_config(args={'input_folder': 'foo/bar', 'resize_images': False, 'im_size': 500, 'compress_pdf': False, 'pdf_im_resolution': 500, 'images_allowlist': {'path1/': 1000}, 'commands_to_delete': ['\\todo1'], 'use_external_tikz': 'foo/bar/tikz'}, config_params={'input_folder': 'foo_/bar_', 'resize_images': True, 'im_size': 1000, 'compress_pdf': True, 'pdf_im_resolution': 1000, 'images_allowlist': {'path2/': 1000}, 'commands_to_delete': ['\\todo2'], 'use_external_tikz': 'foo_/bar_/tikz_'})

{'input_folder': 'foo/bar', 'resize_images': False, 'im_size': 500, 'compress_pdf': False, 'pdf_im_resolution': 500, 'images_allowlist': {'path2/': 1000, 'path1/': 1000}, 'commands_to_delete': ['\\todo1', '\\todo2'], 'use_external_tikz': 'foo_/bar_/tikz_'}

{'input_folder': 'foo/bar', 'resize_images': True, 'im_size': 1000, 'compress_pdf': True, 'pdf_im_resolution': 1000, 'images_allowlist': {'path2/': 1000}, 'commands_to_delete': ['\\todo2'], 'use_external_tikz': 'foo_/bar_/tikz_'}

{'input_folder': 'foo/bar', 'resize_images': False, 'im_size': 1000, 'compress_pdf': True, 'pdf_im_resolution': 1000, 'images_allowlist': {'path2/': 1000}, 'commands_to_delete': ['\\todo2'], 'use_external_tikz': 'foo_/bar_/tikz_'}

{'input_folder': 'foo/bar', 'resize_images': False, 'im_size': 500, 'compress_pdf': True, 'pdf_im_resolution': 1000, 'images_allowlist': {'path2/': 1000}, 'commands_to_delete': ['\\todo2'], 'use_external_tikz': 'foo_/bar_/tikz_'}

{'input_folder': 'foo/bar', 'resize_images': False, 'im_size': 500, 'compress_pdf': False, 'pdf_im_resolution': 1000, 'images_allowlist': {'path2/': 1000}, 'commands_to_delete': ['\\todo2'], 'use_external_tikz': 'foo_/bar_/tikz_'}

{'input_folder': 'foo/bar', 'resize_images': False, 'im_size': 500, 'compress_pdf': False, 'pdf_im_resolution': 500, 'images_allowlist': {'path2/': 1000}, 'commands_to_delete': ['\\todo2'], 'use_external_tikz': 'foo_/bar_/tikz_'}

{'input_folder': 'foo/bar', 'resize_images': False, 'im_size': 500, 'compress_pdf': False, 'pdf_im_resolution': 500, 'images_allowlist': {'path2/': 1000, 'path1/': 1000}, 'commands_to_delete': ['\\todo2'], 'use_external_tikz': 'foo_/bar_/tikz_'}

{'input_folder': 'foo/bar', 'resize_images': False, 'im_size': 500, 'compress_pdf': False, 'pdf_im_resolution': 500, 'images_allowlist': {'path2/': 1000, 'path1/': 1000}, 'commands_to_delete': ['\\todo1', '\\todo2'], 'use_external_tikz': 'foo/bar/tikz'}

dict_keys(['input_folder', 'resize_images', 'im_size', 'compress_pdf', 'pdf_im_resolution', 'images_allowlist', 'commands_to_delete', 'use_external_tikz'])