



from __future__ import annotations

import time

__lowerCamelCase         =			list[tuple[int, int]]

__lowerCamelCase         =			[
    [0, 0, 0, 0, 0, 0, 0],
    [0, 1, 0, 0, 0, 0, 0],  # 0 are free path whereas 1's are obstacles
    [0, 0, 0, 0, 0, 0, 0],
    [0, 0, 1, 0, 0, 0, 0],
    [1, 0, 1, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 1, 0, 0],
]

__lowerCamelCase         =			[[-1, 0], [0, -1], [1, 0], [0, 1]]  # up, left, down, right


class   snake_case_ :




       """simple docstring"""






       def __init__(     self     ,lowercase     ,lowercase     ,lowercase     ,lowercase     ,lowercase):

             """simple docstring"""





             UpperCAmelCase_  :	Union[str, Any]				      =		pos_x
             UpperCAmelCase_  :	str				      =		pos_y
             UpperCAmelCase_  :	str				      =		(pos_y, pos_x)
             UpperCAmelCase_  :	Union[str, Any]				      =		goal_x
             UpperCAmelCase_  :	int				      =		goal_y
             UpperCAmelCase_  :	Union[str, Any]				      =		parent


class   snake_case_ :




       """simple docstring"""






       def __init__(     self     ,lowercase     ,lowercase):

             """simple docstring"""





             UpperCAmelCase_  :	str				      =		Node(start[1]     ,start[0]     ,goal[1]     ,goal[0]     ,lowercase)
             UpperCAmelCase_  :	List[str]				      =		Node(goal[1]     ,goal[0]     ,goal[1]     ,goal[0]     ,lowercase)

             UpperCAmelCase_  :	Optional[Any]				      =		[self.start]
             UpperCAmelCase_  :	Tuple				      =		False



       def  A_   (     self):

             """simple docstring"""





             while self.node_queue:
                   UpperCAmelCase_  :	str				      =		self.node_queue.pop(0)

                   if current_node.pos == self.target.pos:
                         UpperCAmelCase_  :	Optional[Any]				      =		True
                         return self.retrace_path(lowercase)

                   UpperCAmelCase_  :	Optional[int]				      =		self.get_successors(lowercase)

                   for node in successors:
                         self.node_queue.append(lowercase)

             if not self.reached:
                   return [self.start.pos]
             return None



       def  A_   (     self     ,lowercase):

             """simple docstring"""





             UpperCAmelCase_  :	List[Any]				      =		[]
             for action in delta:
                   UpperCAmelCase_  :	List[Any]				      =		parent.pos_x + action[1]
                   UpperCAmelCase_  :	Optional[int]				      =		parent.pos_y + action[0]
                   if not (0 <= pos_x <= len(grid[0]) - 1 and 0 <= pos_y <= len(lowercase) - 1):
                         continue

                   if grid[pos_y][pos_x] != 0:
                         continue

                   successors.append(
                       Node(lowercase     ,lowercase     ,self.target.pos_y     ,self.target.pos_x     ,lowercase))
             return successors



       def  A_   (     self     ,lowercase):

             """simple docstring"""





             UpperCAmelCase_  :	Optional[Any]				      =		node
             UpperCAmelCase_  :	Tuple				      =		[]
             while current_node is not None:
                   path.append((current_node.pos_y, current_node.pos_x))
                   UpperCAmelCase_  :	Optional[Any]				      =		current_node.parent
             path.reverse()
             return path


class   snake_case_ :




       """simple docstring"""






       def __init__(     self     ,lowercase     ,lowercase):

             """simple docstring"""





             UpperCAmelCase_  :	List[str]				      =		BreadthFirstSearch(lowercase     ,lowercase)
             UpperCAmelCase_  :	Any				      =		BreadthFirstSearch(lowercase     ,lowercase)
             UpperCAmelCase_  :	List[Any]				      =		False



       def  A_   (     self):

             """simple docstring"""





             while self.fwd_bfs.node_queue or self.bwd_bfs.node_queue:
                   UpperCAmelCase_  :	str				      =		self.fwd_bfs.node_queue.pop(0)
                   UpperCAmelCase_  :	Optional[int]				      =		self.bwd_bfs.node_queue.pop(0)

                   if current_bwd_node.pos == current_fwd_node.pos:
                         UpperCAmelCase_  :	Any				      =		True
                         return self.retrace_bidirectional_path(
                             lowercase     ,lowercase)

                   UpperCAmelCase_  :	str				      =		current_bwd_node
                   UpperCAmelCase_  :	Any				      =		current_fwd_node

                   UpperCAmelCase_  :	Tuple				      =		{
                       self.fwd_bfs: self.fwd_bfs.get_successors(lowercase),
                       self.bwd_bfs: self.bwd_bfs.get_successors(lowercase),
                   }

                   for bfs in [self.fwd_bfs, self.bwd_bfs]:
                         for node in successors[bfs]:
                               bfs.node_queue.append(lowercase)

             if not self.reached:
                   return [self.fwd_bfs.start.pos]
             return None



       def  A_   (     self     ,lowercase     ,lowercase):

             """simple docstring"""





             UpperCAmelCase_  :	List[str]				      =		self.fwd_bfs.retrace_path(lowercase)
             UpperCAmelCase_  :	Optional[int]				      =		self.bwd_bfs.retrace_path(lowercase)
             bwd_path.pop()
             bwd_path.reverse()
             UpperCAmelCase_  :	Union[str, Any]				      =		fwd_path + bwd_path
             return path


if __name__ == "__main__":
   # all coordinates are given in format [y,x]
   import doctest

   doctest.testmod()
   __lowerCamelCase         =			(0, 0)
   __lowerCamelCase         =			(len(grid) - 1, len(grid[0]) - 1)
   for elem in grid:
      print(elem)

   __lowerCamelCase         =			time.time()
   __lowerCamelCase         =			BreadthFirstSearch(init, goal)
   __lowerCamelCase         =			bfs.search()
   __lowerCamelCase         =			time.time() - start_bfs_time

   print('''Unidirectional BFS computation time : ''', bfs_time)

   __lowerCamelCase         =			time.time()
   __lowerCamelCase         =			BidirectionalBreadthFirstSearch(init, goal)
   __lowerCamelCase         =			bd_bfs.search()
   __lowerCamelCase         =			time.time() - start_bd_bfs_time

   print('''Bidirectional BFS computation time : ''', bd_bfs_time)





import argparse

import torch

from transformers import FunnelBaseModel, FunnelConfig, FunnelModel, load_tf_weights_in_funnel
from transformers.utils import logging


logging.set_verbosity_info()







def    _snake_case (       __snake_case					,  __snake_case					,  __snake_case					,  __snake_case    )     ->     Optional[Any]:






      '''simple docstring'''







      UpperCAmelCase_  :	List[str]				      =		FunnelConfig.from_json_file(__snake_case    )
      print(F"""Building PyTorch model from configuration: {config}"""    )
      UpperCAmelCase_  :	str				      =		FunnelBaseModel(__snake_case    ) if base_model else FunnelModel(__snake_case    )

      # Load weights from tf checkpoint
      load_tf_weights_in_funnel(__snake_case					,  __snake_case					,  __snake_case    )

      # Save pytorch-model
      print(F"""Save PyTorch model to {pytorch_dump_path}"""    )
      torch.save(model.state_dict()					,  __snake_case    )


if __name__ == "__main__":
   __lowerCamelCase         =			argparse.ArgumentParser()
   # Required parameters
   parser.add_argument(
       '''--tf_checkpoint_path''', default=None, type=str, required=True, help='''Path to the TensorFlow checkpoint path.'''
   )
   parser.add_argument(
       '''--config_file''',
       default=None,
       type=str,
       required=True,
       help='''The config json file corresponding to the pre-trained model. \nThis specifies the model architecture.''',
   )
   parser.add_argument(
       '''--pytorch_dump_path''', default=None, type=str, required=True, help='''Path to the output PyTorch model.'''
   )
   parser.add_argument(
       '''--base_model''', action='''store_true''', help='''Whether you want just the base model (no decoder) or not.'''
   )
   __lowerCamelCase         =			parser.parse_args()
   convert_tf_checkpoint_to_pytorch(
       args.tf_checkpoint_path, args.config_file, args.pytorch_dump_path, args.base_model
   )
