






"""simple docstring"""







import os
import shutil
import unittest
from unittest.mock import patch

from transformers.testing_utils import CaptureStd, is_pt_tf_cross_test, require_torch







class 					lowerCamelCase__					(       unittest.TestCase ):






    @patch("""sys.argv"""	,["""fakeprogrampath""", """env"""]					)
    def 				_UpperCamelCase							( self					):
          # test transformers-cli env
          import transformers.commands.transformers_cli

          with CaptureStd() as cs:
                transformers.commands.transformers_cli.main()
          self.assertIn("""Python version"""	,cs.out					)
          self.assertIn("""Platform"""	,cs.out					)
          self.assertIn("""Using distributed or parallel set-up in script?"""	,cs.out					)






    @is_pt_tf_cross_test
    @patch(
        """sys.argv"""	,["""fakeprogrampath""", """pt-to-tf""", """--model-name""", """hf-internal-testing/tiny-random-gptj""", """--no-pr"""]					)
    def 				_UpperCamelCase							( self					):
          import transformers.commands.transformers_cli

          shutil.rmtree("""/tmp/hf-internal-testing/tiny-random-gptj"""	,ignore_errors=A__					)  # cleans potential past runs
          transformers.commands.transformers_cli.main()

          # The original repo has no TF weights -- if they exist, they were created by the CLI
          self.assertTrue(os.path.exists("""/tmp/hf-internal-testing/tiny-random-gptj/tf_model.h5"""					)					)






    @require_torch
    @patch("""sys.argv"""	,["""fakeprogrampath""", """download""", """hf-internal-testing/tiny-random-gptj""", """--cache-dir""", """/tmp"""]					)
    def 				_UpperCamelCase							( self					):
          import transformers.commands.transformers_cli

          # # remove any previously downloaded model to start clean
          shutil.rmtree("""/tmp/models--hf-internal-testing--tiny-random-gptj"""	,ignore_errors=A__					)

          # run the command
          transformers.commands.transformers_cli.main()

          # check if the model files are downloaded correctly on /tmp/models--hf-internal-testing--tiny-random-gptj
          self.assertTrue(os.path.exists("""/tmp/models--hf-internal-testing--tiny-random-gptj/blobs"""					)					)
          self.assertTrue(os.path.exists("""/tmp/models--hf-internal-testing--tiny-random-gptj/refs"""					)					)
          self.assertTrue(os.path.exists("""/tmp/models--hf-internal-testing--tiny-random-gptj/snapshots"""					)					)






    @require_torch
    @patch(
        """sys.argv"""	,[
            """fakeprogrampath""",
            """download""",
            """hf-internal-testing/test_dynamic_model_with_tokenizer""",
            """--trust-remote-code""",
            """--cache-dir""",
            """/tmp""",
        ]	,)
    def 				_UpperCamelCase							( self					):
          import transformers.commands.transformers_cli

          # # remove any previously downloaded model to start clean
          shutil.rmtree("""/tmp/models--hf-internal-testing--test_dynamic_model_with_tokenizer"""	,ignore_errors=A__					)

          # run the command
          transformers.commands.transformers_cli.main()

          # check if the model files are downloaded correctly on /tmp/models--hf-internal-testing--test_dynamic_model_with_tokenizer
          self.assertTrue(os.path.exists("""/tmp/models--hf-internal-testing--test_dynamic_model_with_tokenizer/blobs"""					)					)
          self.assertTrue(os.path.exists("""/tmp/models--hf-internal-testing--test_dynamic_model_with_tokenizer/refs"""					)					)
          self.assertTrue(
              os.path.exists("""/tmp/models--hf-internal-testing--test_dynamic_model_with_tokenizer/snapshots"""					)					)





'''simple docstring'''



UpperCamelCase__					:						Tuple											=     [
    ["ab-e1", "ac-e3", "ad-e5", "bc-e4", "bd-e2", "be-e6", "bh-e12", "cd-e2", "ce-e4",
     "de-e1", "df-e8", "dg-e5", "dh-e10", "ef-e3", "eg-e2", "fg-e6", "gh-e6", "hi-e3"],
    ["ab-e1", "ac-e3", "ad-e5", "bc-e4", "bd-e2", "be-e6", "cd-e2", "de-e1", "df-e8",
     "ef-e3", "eg-e2", "fg-e6"],
    ["ab-e1", "ac-e3", "bc-e4", "bd-e2", "de-e1", "df-e8", "dg-e5", "ef-e3", "eg-e2",
     "eh-e12", "fg-e6", "fh-e10", "gh-e6"],
    ["ab-e1", "ac-e3", "bc-e4", "bd-e2", "bh-e12", "cd-e2", "df-e8", "dh-e10"],
    ["ab-e1", "ac-e3", "ad-e5", "bc-e4", "bd-e2", "cd-e2", "ce-e4", "de-e1", "df-e8",
     "dg-e5", "ef-e3", "eg-e2", "fg-e6"]
]
def       lowerCAmelCase_		( SCREAMING_SNAKE_CASE_  )   ->   List[str]:




   """simple docstring"""
   _SCREAMING_SNAKE_CASE          = set()
   for row in edge_array:
      for item in row:
         distinct_edge.add(item[0]  )
   return list(SCREAMING_SNAKE_CASE_  )
def       lowerCAmelCase_		( SCREAMING_SNAKE_CASE_			,					SCREAMING_SNAKE_CASE_  )   ->   List[str]:




   """simple docstring"""
   _SCREAMING_SNAKE_CASE          = ["""0"""] * len(SCREAMING_SNAKE_CASE_  )
   for i, row in enumerate(SCREAMING_SNAKE_CASE_  ):
      for item in row:
         if distinct_edge in item[0]:
            _SCREAMING_SNAKE_CASE          = """1"""
            break
   return "".join(SCREAMING_SNAKE_CASE_  )
def       lowerCAmelCase_		( SCREAMING_SNAKE_CASE_  )   ->   Union[str, Any]:




   """simple docstring"""
   _SCREAMING_SNAKE_CASE          = get_distinct_edge(SCREAMING_SNAKE_CASE_  )
   _SCREAMING_SNAKE_CASE          = {}

   for item in distinct_edge:
      _SCREAMING_SNAKE_CASE          = get_bitcode(SCREAMING_SNAKE_CASE_			,					SCREAMING_SNAKE_CASE_  )
      # print('bit',bit)
      # bt=''.join(bit)
      _SCREAMING_SNAKE_CASE          = bit.count("""1"""  )
      _SCREAMING_SNAKE_CASE          = [s, bit]
   # Store [Distinct edge, WT(Bitcode), Bitcode] in descending order
   _SCREAMING_SNAKE_CASE          = [
       [k, v[0], v[1]]
       for k, v in sorted(frequency_table.items()			,					key=lambda SCREAMING_SNAKE_CASE_  : v[1][0]			,					reverse=SCREAMING_SNAKE_CASE_  )
   ]
   return sorted_frequency_table
def       lowerCAmelCase_		( SCREAMING_SNAKE_CASE_  )   ->   List[str]:




   """simple docstring"""
   _SCREAMING_SNAKE_CASE          = {}
   for _, item in enumerate(SCREAMING_SNAKE_CASE_  ):
      nodes.setdefault(item[2]			,					[]  ).append(item[0]  )
   return nodes
def       lowerCAmelCase_		( SCREAMING_SNAKE_CASE_  )   ->   int:




   """simple docstring"""
   _SCREAMING_SNAKE_CASE          = {}
   for key, value in nodes.items():
      _SCREAMING_SNAKE_CASE          = value
   return cluster
def       lowerCAmelCase_		( SCREAMING_SNAKE_CASE_  )   ->   str:




   """simple docstring"""
   return [i * 1_00 / len(SCREAMING_SNAKE_CASE_  ) for i in cluster]
def       lowerCAmelCase_		( )   ->   None:




   """simple docstring"""
   print("""\nNodes\n"""  )
   for key, value in nodes.items():
      print(SCREAMING_SNAKE_CASE_			,					SCREAMING_SNAKE_CASE_  )
   print("""\nSupport\n"""  )
   print(SCREAMING_SNAKE_CASE_  )
   print("""\n Cluster \n"""  )
   for key, value in sorted(cluster.items()			,					reverse=SCREAMING_SNAKE_CASE_  ):
      print(SCREAMING_SNAKE_CASE_			,					SCREAMING_SNAKE_CASE_  )
   print("""\n Graph\n"""  )
   for key, value in graph.items():
      print(SCREAMING_SNAKE_CASE_			,					SCREAMING_SNAKE_CASE_  )
   print("""\n Edge List of Frequent subgraphs \n"""  )
   for edge_list in freq_subgraph_edge_list:
      print(SCREAMING_SNAKE_CASE_  )
def       lowerCAmelCase_		( SCREAMING_SNAKE_CASE_			,					SCREAMING_SNAKE_CASE_			,					SCREAMING_SNAKE_CASE_			,					SCREAMING_SNAKE_CASE_  )   ->   Optional[int]:




   """simple docstring"""
   for i in cluster[ca]:
      _SCREAMING_SNAKE_CASE          = 0
      _SCREAMING_SNAKE_CASE          = ca + 1
      while ca < max(cluster.keys()  ):
         for j in cluster[ca]:
            if int(SCREAMING_SNAKE_CASE_			,					2  ) & int(SCREAMING_SNAKE_CASE_			,					2  ) == int(SCREAMING_SNAKE_CASE_			,					2  ):
               if tuple(nodes[i]  ) in graph:
                  graph[tuple(nodes[i]  )].append(nodes[j]  )
               else:
                  _SCREAMING_SNAKE_CASE          = [nodes[j]]
               count += 1
         if count == 0:
            _SCREAMING_SNAKE_CASE          = ca + 1
         else:
            break
def       lowerCAmelCase_		( SCREAMING_SNAKE_CASE_			,					SCREAMING_SNAKE_CASE_  )   ->   Optional[int]:




   """simple docstring"""
   _SCREAMING_SNAKE_CASE          = cluster[max(cluster.keys()  )]
   _SCREAMING_SNAKE_CASE          = """Header"""
   _SCREAMING_SNAKE_CASE          = {}
   for i in x:
      if (["Header"],) in graph:
         graph[(["Header"],)].append(x[i]  )
      else:
         _SCREAMING_SNAKE_CASE          = [x[i]]
   for i in x:
      _SCREAMING_SNAKE_CASE          = [["""Header"""]]
   _SCREAMING_SNAKE_CASE          = 1
   while i < max(SCREAMING_SNAKE_CASE_  ) - 1:
      create_edge(SCREAMING_SNAKE_CASE_			,					SCREAMING_SNAKE_CASE_			,					SCREAMING_SNAKE_CASE_			,					SCREAMING_SNAKE_CASE_  )
      _SCREAMING_SNAKE_CASE          = i + 1
   return graph
def       lowerCAmelCase_		( SCREAMING_SNAKE_CASE_			,					SCREAMING_SNAKE_CASE_			,					SCREAMING_SNAKE_CASE_			,					SCREAMING_SNAKE_CASE_=None  )   ->   List[Any]:




   """simple docstring"""
   _SCREAMING_SNAKE_CASE          = (path or []) + [start]
   if start == end:
      paths.append(SCREAMING_SNAKE_CASE_  )
   for node in graph[start]:
      if tuple(SCREAMING_SNAKE_CASE_  ) not in path:
         my_dfs(SCREAMING_SNAKE_CASE_			,					tuple(SCREAMING_SNAKE_CASE_  )			,					SCREAMING_SNAKE_CASE_			,					SCREAMING_SNAKE_CASE_  )
def       lowerCAmelCase_		( SCREAMING_SNAKE_CASE_			,					SCREAMING_SNAKE_CASE_			,					SCREAMING_SNAKE_CASE_  )   ->   int:




   """simple docstring"""
   _SCREAMING_SNAKE_CASE          = int(s / 1_00 * (len(SCREAMING_SNAKE_CASE_  ) - 1)  )
   for i in cluster[k]:
      my_dfs(SCREAMING_SNAKE_CASE_			,					tuple(cluster[k][i]  )			,					(["""Header"""],)  )
def       lowerCAmelCase_		( SCREAMING_SNAKE_CASE_  )   ->   Optional[Any]:




   """simple docstring"""
   _SCREAMING_SNAKE_CASE          = []
   for edges in paths:
      _SCREAMING_SNAKE_CASE          = []
      for j in range(len(SCREAMING_SNAKE_CASE_  ) - 1  ):
         _SCREAMING_SNAKE_CASE          = list(edges[j]  )
         for e in temp:
            _SCREAMING_SNAKE_CASE          = (e[0], e[1])
            el.append(SCREAMING_SNAKE_CASE_  )
      freq_sub_el.append(SCREAMING_SNAKE_CASE_  )
   return freq_sub_el
def       lowerCAmelCase_		( SCREAMING_SNAKE_CASE_  )   ->   Any:




   """simple docstring"""
   for i in range(len(SCREAMING_SNAKE_CASE_  )  ):
      for j in range(len(edge_array[i]  )  ):
         _SCREAMING_SNAKE_CASE          = edge_array[i][j].split("""-"""  )
         _SCREAMING_SNAKE_CASE          = t


if __name__ == "__main__":
     preprocess(edge_array)
     UpperCamelCase__					:						List[Any]											=     get_frequency_table(edge_array)
     UpperCamelCase__					:						List[Any]											=     get_nodes(frequency_table)
     UpperCamelCase__					:						List[str]											=     get_cluster(nodes)
     UpperCamelCase__					:						List[Any]											=     get_support(cluster)
     UpperCamelCase__					:						Union[str, Any]											=     construct_graph(cluster, nodes)
     find_freq_subgraph_given_support(60, cluster, graph)
     UpperCamelCase__					:						list											=     []
     UpperCamelCase__					:						int											=     freq_subgraphs_edge_list(paths)
     print_all()






