


'''simple docstring'''





from collections import OrderedDict
from typing import Any, List, Mapping, Optional

from ... import PreTrainedTokenizer, TensorType, is_torch_available
from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfigWithPast, PatchingSpec
from ...utils import logging


__lowerCamelCase       				=	logging.get_logger(__name__)

__lowerCamelCase       				=	{
    '''gpt2''': '''https://huggingface.co/gpt2/resolve/main/config.json''',
    '''gpt2-medium''': '''https://huggingface.co/gpt2-medium/resolve/main/config.json''',
    '''gpt2-large''': '''https://huggingface.co/gpt2-large/resolve/main/config.json''',
    '''gpt2-xl''': '''https://huggingface.co/gpt2-xl/resolve/main/config.json''',
    '''distilgpt2''': '''https://huggingface.co/distilgpt2/resolve/main/config.json''',
}




class 							UpperCAmelCase ( _snake_case	):
 UpperCAmelCase				=				"gpt2"
 UpperCAmelCase				=				["past_key_values"]
 UpperCAmelCase				=				{
     "hidden_size": "n_embd",
     "max_position_embeddings": "n_positions",
     "num_attention_heads": "n_head",
     "num_hidden_layers": "n_layer",
 }


 def __init__(			self       :  str ,					__lowerCamelCase       :  str=5_0_2_5_7 ,					__lowerCamelCase       :  List[Any]=1_0_2_4 ,					__lowerCamelCase       :  Union[str, Any]=7_6_8 ,					__lowerCamelCase       :  str=1_2 ,					__lowerCamelCase       :  str=1_2 ,					__lowerCamelCase       :  Any=None ,					__lowerCamelCase       :  Union[str, Any]="gelu_new" ,					__lowerCamelCase       :  List[str]=0.1 ,					__lowerCamelCase       :  Tuple=0.1 ,					__lowerCamelCase       :  List[str]=0.1 ,					__lowerCamelCase       :  Optional[int]=1e-5 ,					__lowerCamelCase       :  Optional[int]=0.02 ,					__lowerCamelCase       :  List[str]="cls_index" ,					__lowerCamelCase       :  Optional[Any]=True ,					__lowerCamelCase       :  List[str]=None ,					__lowerCamelCase       :  str=True ,					__lowerCamelCase       :  Any=0.1 ,					__lowerCamelCase       :  Union[str, Any]=True ,					__lowerCamelCase       :  Optional[Any]=True ,					__lowerCamelCase       :  List[Any]=5_0_2_5_6 ,					__lowerCamelCase       :  int=5_0_2_5_6 ,					__lowerCamelCase       :  Tuple=False ,					__lowerCamelCase       :  List[str]=False ,					**__lowerCamelCase       :  int ,					):
    UpperCAmelCase__  :Optional[int]            =			vocab_size
    UpperCAmelCase__  :Any            =			n_positions
    UpperCAmelCase__  :Optional[Any]            =			n_embd
    UpperCAmelCase__  :Tuple            =			n_layer
    UpperCAmelCase__  :Optional[Any]            =			n_head
    UpperCAmelCase__  :Optional[int]            =			n_inner
    UpperCAmelCase__  :List[str]            =			activation_function
    UpperCAmelCase__  :Union[str, Any]            =			resid_pdrop
    UpperCAmelCase__  :Optional[int]            =			embd_pdrop
    UpperCAmelCase__  :str            =			attn_pdrop
    UpperCAmelCase__  :Optional[int]            =			layer_norm_epsilon
    UpperCAmelCase__  :str            =			initializer_range
    UpperCAmelCase__  :Dict            =			summary_type
    UpperCAmelCase__  :str            =			summary_use_proj
    UpperCAmelCase__  :Optional[int]            =			summary_activation
    UpperCAmelCase__  :Optional[int]            =			summary_first_dropout
    UpperCAmelCase__  :str            =			summary_proj_to_labels
    UpperCAmelCase__  :Union[str, Any]            =			scale_attn_weights
    UpperCAmelCase__  :str            =			use_cache
    UpperCAmelCase__  :Any            =			scale_attn_by_inverse_layer_idx
    UpperCAmelCase__  :int            =			reorder_and_upcast_attn

    UpperCAmelCase__  :Union[str, Any]            =			bos_token_id
    UpperCAmelCase__  :Optional[int]            =			eos_token_id

    super().__init__(bos_token_id=__lowerCamelCase ,					eos_token_id=__lowerCamelCase ,					**__lowerCamelCase   )




class 							UpperCAmelCase ( _snake_case	):


 def __init__(			self       :  Any ,					__lowerCamelCase       :  PretrainedConfig ,					__lowerCamelCase       :  str = "default" ,					__lowerCamelCase       :  List[PatchingSpec] = None ,					__lowerCamelCase       :  bool = False ,					):
    super().__init__(__lowerCamelCase ,					task=__lowerCamelCase ,					patching_specs=__lowerCamelCase ,					use_past=__lowerCamelCase   )
    if not getattr(self._config ,					'''pad_token_id''' ,					__lowerCamelCase   ):
       # TODO: how to do that better?
       UpperCAmelCase__  :Optional[int]            =			0


 @property
 def 					__SCREAMING_SNAKE_CASE				(			self       :  List[str]   ):
    UpperCAmelCase__  :Dict            =			OrderedDict({'''input_ids''': {0: '''batch''', 1: '''sequence'''}}   )
    if self.use_past:
       self.fill_with_past_key_values_(__lowerCamelCase ,					direction='''inputs'''   )
       UpperCAmelCase__  :int            =			{0: '''batch''', 1: '''past_sequence + sequence'''}
    else:
       UpperCAmelCase__  :Optional[Any]            =			{0: '''batch''', 1: '''sequence'''}

    return common_inputs


 @property
 def 					__SCREAMING_SNAKE_CASE				(			self       :  Optional[Any]   ):
    return self._config.n_layer


 @property
 def 					__SCREAMING_SNAKE_CASE				(			self       :  int   ):
    return self._config.n_head


 def 					__SCREAMING_SNAKE_CASE				(			self       :  str ,					__lowerCamelCase       :  PreTrainedTokenizer ,					__lowerCamelCase       :  int = -1 ,					__lowerCamelCase       :  int = -1 ,					__lowerCamelCase       :  bool = False ,					__lowerCamelCase       :  Optional[TensorType] = None ,					):
    UpperCAmelCase__  :List[Any]            =			super(__lowerCamelCase ,					self   ).generate_dummy_inputs(
        __lowerCamelCase ,					batch_size=__lowerCamelCase ,					seq_length=__lowerCamelCase ,					is_pair=__lowerCamelCase ,					framework=__lowerCamelCase   )

    # We need to order the input in the way they appears in the forward()
    UpperCAmelCase__  :int            =			OrderedDict({'''input_ids''': common_inputs['''input_ids''']}   )

    # Need to add the past_keys
    if self.use_past:
       if not is_torch_available():
          raise ValueError('''Cannot generate dummy past_keys inputs without PyTorch installed.'''   )
       else:
          import torch

          UpperCAmelCase__      ,	UpperCAmelCase__  :Dict            =			common_inputs['''input_ids'''].shape
          # Not using the same length for past_key_values
          UpperCAmelCase__  :Union[str, Any]            =			seqlen + 2
          UpperCAmelCase__  :Optional[Any]            =			(
              batch,
              self.num_attention_heads,
              past_key_values_length,
              self._config.hidden_size // self.num_attention_heads,
          )
          UpperCAmelCase__  :Union[str, Any]            =			[
              (torch.zeros(__lowerCamelCase   ), torch.zeros(__lowerCamelCase   )) for _ in range(self.num_layers   )
          ]

    UpperCAmelCase__  :str            =			common_inputs['''attention_mask''']
    if self.use_past:
       UpperCAmelCase__  :Optional[Any]            =			ordered_inputs['''attention_mask'''].dtype
       UpperCAmelCase__  :Any            =			torch.cat(
           [ordered_inputs['''attention_mask'''], torch.ones(__lowerCamelCase ,					__lowerCamelCase ,					dtype=__lowerCamelCase   )] ,					dim=1   )

    return ordered_inputs





 @property
 def 					__SCREAMING_SNAKE_CASE				(			self       :  Tuple   ):
    return 1_3







'''simple docstring'''





__lowerCamelCase       				=	[
    ['''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 					a__    (				UpperCamelCase_	:			List[str]	):
   UpperCAmelCase__  :str            =			set()
   for row in edge_array:
      for item in row:
         distinct_edge.add(item[0]	)
   return list(UpperCamelCase_	)


def 					a__    (				UpperCamelCase_	:			Tuple,      UpperCamelCase_	:			List[Any]	):
   UpperCAmelCase__  :int            =			['''0'''] * len(UpperCamelCase_	)
   for i, row in enumerate(UpperCamelCase_	):
      for item in row:
         if distinct_edge in item[0]:
            UpperCAmelCase__  :List[Any]            =			'''1'''
            break
   return "".join(UpperCamelCase_	)


def 					a__    (				UpperCamelCase_	:			Optional[int]	):
   UpperCAmelCase__  :Any            =			get_distinct_edge(UpperCamelCase_	)
   UpperCAmelCase__  :Dict            =			{}

   for item in distinct_edge:
      UpperCAmelCase__  :List[str]            =			get_bitcode(UpperCamelCase_,      UpperCamelCase_	)
      # print('bit',bit)
      # bt=''.join(bit)
      UpperCAmelCase__  :int            =			bit.count('''1'''	)
      UpperCAmelCase__  :Tuple            =			[s, bit]
   # Store [Distinct edge, WT(Bitcode), Bitcode] in descending order
   UpperCAmelCase__  :str            =			[
       [k, v[0], v[1]]
       for k, v in sorted(frequency_table.items(),      key=lambda UpperCamelCase_	: v[1][0],      reverse=UpperCamelCase_	)
   ]
   return sorted_frequency_table


def 					a__    (				UpperCamelCase_	:			Optional[int]	):
   UpperCAmelCase__  :int            =			{}
   for _, item in enumerate(UpperCamelCase_	):
      nodes.setdefault(item[2],      []	).append(item[0]	)
   return nodes


def 					a__    (				UpperCamelCase_	:			Any	):
   UpperCAmelCase__  :Any            =			{}
   for key, value in nodes.items():
      UpperCAmelCase__  :Optional[int]            =			value
   return cluster


def 					a__    (				UpperCamelCase_	:			Tuple	):
   return [i * 100 / len(UpperCamelCase_	) for i in cluster]


def 					a__    (				):
   print('''\nNodes\n'''	)
   for key, value in nodes.items():
      print(UpperCamelCase_,      UpperCamelCase_	)
   print('''\nSupport\n'''	)
   print(UpperCamelCase_	)
   print('''\n Cluster \n'''	)
   for key, value in sorted(cluster.items(),      reverse=UpperCamelCase_	):
      print(UpperCamelCase_,      UpperCamelCase_	)
   print('''\n Graph\n'''	)
   for key, value in graph.items():
      print(UpperCamelCase_,      UpperCamelCase_	)
   print('''\n Edge List of Frequent subgraphs \n'''	)
   for edge_list in freq_subgraph_edge_list:
      print(UpperCamelCase_	)


def 					a__    (				UpperCamelCase_	:			Optional[int],      UpperCamelCase_	:			Any,      UpperCamelCase_	:			int,      UpperCamelCase_	:			Dict	):
   for i in cluster[ca]:
      UpperCAmelCase__  :int            =			0
      UpperCAmelCase__  :int            =			ca + 1
      while ca < max(cluster.keys()	):
         for j in cluster[ca]:
            if int(UpperCamelCase_,      2	) & int(UpperCamelCase_,      2	) == int(UpperCamelCase_,      2	):
               if tuple(nodes[i]	) in graph:
                  graph[tuple(nodes[i]	)].append(nodes[j]	)
               else:
                  UpperCAmelCase__  :int            =			[nodes[j]]
               count += 1
         if count == 0:
            UpperCAmelCase__  :List[Any]            =			ca + 1
         else:
            break


def 					a__    (				UpperCamelCase_	:			Optional[int],      UpperCamelCase_	:			List[str]	):
   UpperCAmelCase__  :List[Any]            =			cluster[max(cluster.keys()	)]
   UpperCAmelCase__  :Union[str, Any]            =			'''Header'''
   UpperCAmelCase__  :Optional[int]            =			{}
   for i in x:
      if (["Header"],) in graph:
         graph[(["Header"],)].append(x[i]	)
      else:
         UpperCAmelCase__  :Tuple            =			[x[i]]
   for i in x:
      UpperCAmelCase__  :Dict            =			[['''Header''']]
   UpperCAmelCase__  :Any            =			1
   while i < max(UpperCamelCase_	) - 1:
      create_edge(UpperCamelCase_,      UpperCamelCase_,      UpperCamelCase_,      UpperCamelCase_	)
      UpperCAmelCase__  :Union[str, Any]            =			i + 1
   return graph


def 					a__    (				UpperCamelCase_	:			Optional[Any],      UpperCamelCase_	:			int,      UpperCamelCase_	:			Any,      UpperCamelCase_	:			Dict=None	):
   UpperCAmelCase__  :Tuple            =			(path or []) + [start]
   if start == end:
      paths.append(UpperCamelCase_	)
   for node in graph[start]:
      if tuple(UpperCamelCase_	) not in path:
         my_dfs(UpperCamelCase_,      tuple(UpperCamelCase_	),      UpperCamelCase_,      UpperCamelCase_	)


def 					a__    (				UpperCamelCase_	:			Dict,      UpperCamelCase_	:			int,      UpperCamelCase_	:			List[Any]	):
   UpperCAmelCase__  :List[str]            =			int(s / 100 * (len(UpperCamelCase_	) - 1)	)
   for i in cluster[k]:
      my_dfs(UpperCamelCase_,      tuple(cluster[k][i]	),      (['''Header'''],)	)


def 					a__    (				UpperCamelCase_	:			List[Any]	):
   UpperCAmelCase__  :int            =			[]
   for edges in paths:
      UpperCAmelCase__  :List[Any]            =			[]
      for j in range(len(UpperCamelCase_	) - 1	):
         UpperCAmelCase__  :Any            =			list(edges[j]	)
         for e in temp:
            UpperCAmelCase__  :str            =			(e[0], e[1])
            el.append(UpperCamelCase_	)
      freq_sub_el.append(UpperCamelCase_	)
   return freq_sub_el


def 					a__    (				UpperCamelCase_	:			Dict	):
   for i in range(len(UpperCamelCase_	)	):
      for j in range(len(edge_array[i]	)	):
         UpperCAmelCase__  :Dict            =			edge_array[i][j].split('''-'''	)
         UpperCAmelCase__  :Optional[Any]            =			t


if __name__ == "__main__":
    preprocess(edge_array)
    __lowerCamelCase       				=	get_frequency_table(edge_array)
    __lowerCamelCase       				=	get_nodes(frequency_table)
    __lowerCamelCase       				=	get_cluster(nodes)
    __lowerCamelCase       				=	get_support(cluster)
    __lowerCamelCase       				=	construct_graph(cluster, nodes)
    find_freq_subgraph_given_support(60, cluster, graph)
    __lowerCamelCase       				=	[]
    __lowerCamelCase       				=	freq_subgraphs_edge_list(paths)
    print_all()



