

import argparse
import random

import joblib
import numpy as np
import torch
from igf.igf import (
    SecondaryLearner,
    collect_objective_set,
    compute_perplexity,
    generate_datasets,
    load_gpta,
    recopy_gpta,
    set_seed,
    train_secondary_learner,
)
from torch.utils.data import DataLoader, RandomSampler

from transformers import GPTaLMHeadModel


def        __lowerCAmelCase    (       _UpperCamelCase		:  Optional[int]=32		,							_UpperCamelCase		:  Optional[Any]=10		,							_UpperCamelCase		:  Tuple=1_00		,							_UpperCamelCase		:  Optional[Any]=10_26		,							_UpperCamelCase		:  Optional[Any]=True		,							_UpperCamelCase		:  Optional[int]="data/tokenized_stories_train_wikitext103.jbl"		,							_UpperCamelCase		:  Optional[Any]="igf_context_pairs.jbl"		,							)		->							List[str]:
 '''simple docstring'''


 set_seed(3	)
 # generate train_data and objective_set
 SCREAMING_SNAKE_CASE						,	SCREAMING_SNAKE_CASE								=			generate_datasets(
     _A		,							_A		,							number=_A		,							min_len=10_26		,							trim=_A	)
 # keeps model same across runs
 set_seed(4	)
 # model, lm_optimizer, lm_scheduler = recopy_gpt2(model, device, max_steps) # store original model weights
 # can we train on GPU?
 SCREAMING_SNAKE_CASE								=			torch.device('cuda:0' if torch.cuda.is_available() else 'cpu'	)

 # load pretrained model
 SCREAMING_SNAKE_CASE								=			load_gpta('gpt2'	).to(_A	)
 print('computing perplexity on objective set'	)
 SCREAMING_SNAKE_CASE								=			compute_perplexity(_A		,							_A		,							_A	).item()
 print('perplexity on objective set:'		,							_A	)

 # collect igf pairs and save to file demo.jbl
 collect_objective_set(_A		,							_A		,							_A		,							_A		,							_A		,							_A		,							_A		,							_A	)

 # clean up, delete model and data we don't need anymore
 del model, train_data, objective_set
 torch.cuda.empty_cache()


def        __lowerCAmelCase    (       _UpperCamelCase		:  Dict		,							_UpperCamelCase		:  str=15		,							_UpperCamelCase		:  List[str]=1_28		,							_UpperCamelCase		:  int=1_00		,							_UpperCamelCase		:  Dict="igf_model.pt"		,							)		->							Any:
 '''simple docstring'''


 set_seed(42	)

 # Load pre-trained model
 SCREAMING_SNAKE_CASE								=			GPTaLMHeadModel.from_pretrained('gpt2'	)

 # Initialize secondary learner to use embedding weights of model
 SCREAMING_SNAKE_CASE								=			SecondaryLearner(_A	)

 # Train secondary learner
 SCREAMING_SNAKE_CASE								=			train_secondary_learner(
     _A		,							_A		,							max_epochs=_A		,							batch_size=_A		,							eval_freq=1_00		,							igf_model_path=_A		,							)

 del model, secondary_learner_train_data
 torch.cuda.empty_cache()

 return secondary_learner


def        __lowerCAmelCase    (       _UpperCamelCase		:  Tuple		,							_UpperCamelCase		:  Tuple		,							_UpperCamelCase		:  Optional[int]		,							_UpperCamelCase		:  Tuple=32		,							_UpperCamelCase		:  Optional[Any]=10_00		,							_UpperCamelCase		:  List[str]=16		,							_UpperCamelCase		:  Dict=1.0		,							_UpperCamelCase		:  int=recopy_gpta		,							_UpperCamelCase		:  List[Any]=None		,							_UpperCamelCase		:  Dict=10		,							_UpperCamelCase		:  List[Any]="gpt2_finetuned.pt"		,							)		->							List[Any]:
 '''simple docstring'''


 SCREAMING_SNAKE_CASE								=			torch.device('cuda:0' if torch.cuda.is_available() else 'cpu'	)
 SCREAMING_SNAKE_CASE								=			RandomSampler(_A	)
 SCREAMING_SNAKE_CASE								=			DataLoader(_A		,							sampler=_A	)

 SCREAMING_SNAKE_CASE								=			max_steps // (len(_A	)) + 1
 SCREAMING_SNAKE_CASE								=			0
 SCREAMING_SNAKE_CASE								=			torch.zeros((1, context_len)		,							dtype=torch.long		,							device=_A	)
 SCREAMING_SNAKE_CASE						,	SCREAMING_SNAKE_CASE						,	SCREAMING_SNAKE_CASE								=			recopy_model(_A		,							_A		,							_A	)

 model.train()
 if secondary_learner is not None:
  secondary_learner.to(_A	)
  secondary_learner.eval()
 SCREAMING_SNAKE_CASE								=			[]
 SCREAMING_SNAKE_CASE								=			0

 SCREAMING_SNAKE_CASE								=			[]
 SCREAMING_SNAKE_CASE								=			[]

 # Compute the performance of the transformer model at the beginning
 SCREAMING_SNAKE_CASE								=			compute_perplexity(_A		,							_A		,							_A	)
 test_perps.append(_A	)
 print('Test perplexity, step'		,							_A		,							':'		,							_A	)
 for epoch in range(int(_A	)	):
  for step, example in enumerate(_A	):
   torch.cuda.empty_cache()
   SCREAMING_SNAKE_CASE								=			random.randint(0		,							example.size(2	) - context_len - 1	)
   SCREAMING_SNAKE_CASE								=			example[0, 0, start : start + context_len]
   lm_optimizer.zero_grad()
   SCREAMING_SNAKE_CASE								=			model(_A		,							labels=_A	)
   SCREAMING_SNAKE_CASE								=			True

   if secondary_learner is not None:
    SCREAMING_SNAKE_CASE								=			secondary_learner.forward(
        torch.tensor(_A		,							dtype=torch.long		,							device=_A	).unsqueeze(0	)	)[0].item()
    observed_qs.append(float(_A	)	)

    # Here we implement the simple non-constant threshold for the predicted IG(X) value
    # We will decay the selectivity of our secondary learner filter from
    # 1 standard deviation above average to 1 below average after 10 batches.

    if global_step == 10:
     SCREAMING_SNAKE_CASE								=			-1
    if predicted_q < threshold:
     SCREAMING_SNAKE_CASE								=			False

            # If we passed the filter, add the context to the batch!
   if do_backprop:
    contexts.append(np.array(context.cpu()	)	)
    SCREAMING_SNAKE_CASE								=			outputs[0]
    lm_loss.backward()
    examples += 1

   del outputs

   # Once the batch is filled with enough contexts, backprop on the batch.
   if examples == batch_size:
    torch.cuda.empty_cache()
    SCREAMING_SNAKE_CASE								=			0
    # Do LM backprop
    torch.nn.utils.clip_grad_norm_(model.parameters()		,							3.0	)
    lm_optimizer.step()
    lm_scheduler.step()  # Update learning rate schedule
    global_step += 1
    # Compute the performance of the transformer model at this batch
    if global_step % eval_interval == 0:
     SCREAMING_SNAKE_CASE								=			compute_perplexity(_A		,							_A		,							_A	)
     test_perps.append(_A	)

     print('Test perplexity, step'		,							_A		,							':'		,							_A	)
            # Break out of the loop after 60 batches
   if max_steps > 0 and global_step > 60:
    break
  if max_steps > 0 and global_step > 60:
   break

    # save finetuned transformer model
 torch.save(model.state_dict()		,							_A	)
 torch.cuda.empty_cache()
 # Do some cleaning up so we can reinitialize for the next run of this function
 del lm_optimizer
 del lm_scheduler
 return model


def        __lowerCAmelCase    (       )		->							Optional[int]:
 '''simple docstring'''


 SCREAMING_SNAKE_CASE								=			argparse.ArgumentParser(description='Fine-tune a transformer model with IGF on a language modeling task'	)

 # Required parameters
 parser.add_argument(
     '--data_dir'		,							default=_A		,							type=_A		,							required=_A		,							help='The input data dir. Should contain data files for WikiText.'		,							)
 parser.add_argument(
     '--model_name_or_path'		,							default=_A		,							type=_A		,							required=_A		,							help='Path to pretrained model or model identifier from huggingface.co/models'		,							)
 parser.add_argument(
     '--data_file'		,							type=_A		,							default=_A		,							help=(
         'A jbl file containing tokenized data which can be split as objective dataset, '
         'train_dataset and test_dataset.'
     )		,							)

 parser.add_argument(
     '--igf_data_file'		,							type=_A		,							default=_A		,							help='A jbl file containing the context and information gain pairs to train secondary learner.'		,							)

 parser.add_argument(
     '--output_dir'		,							default=_A		,							type=_A		,							required=_A		,							help='The output directory where the final fine-tuned model is stored.'		,							)

 parser.add_argument(
     '--tokenizer_name'		,							default=_A		,							type=_A		,							help='Pretrained tokenizer name or path if not the same as model_name'		,							)
 parser.add_argument('--seed'		,							type=_A		,							default=_A		,							help='A seed for reproducible training.'	)

 parser.add_argument(
     '--context_len'		,							default=32		,							type=_A		,							help=(
         'The maximum total input sequence length after tokenization. Sequences longer '
         'than this will be truncated, sequences shorter will be padded.'
     )		,							)

 parser.add_argument(
     '--size_objective_set'		,							default=1_00		,							type=_A		,							help='number of articles that are long enough to be used as our objective set'		,							)
 parser.add_argument(
     '--eval_freq'		,							default=1_00		,							type=_A		,							help='secondary model evaluation is triggered at eval_freq'	)

 parser.add_argument('--max_steps'		,							default=10_00		,							type=_A		,							help='To calculate training epochs'	)

 parser.add_argument(
     '--secondary_learner_batch_size'		,							default=1_28		,							type=_A		,							help='batch size of training data for secondary learner'		,							)

 parser.add_argument(
     '--batch_size'		,							default=16		,							type=_A		,							help='batch size of training data of language model(gpt2) '	)

 parser.add_argument(
     '--eval_interval'		,							default=10		,							type=_A		,							help=(
         'decay the selectivity of our secondary learner filter from'
         '1 standard deviation above average to 1 below average after 10 batches'
     )		,							)

 parser.add_argument(
     '--number'		,							default=1_00		,							type=_A		,							help='The number of examples split to be used as objective_set/test_data'	)

 parser.add_argument(
     '--min_len'		,							default=10_26		,							type=_A		,							help='The minimum length of the article to be used as objective set'	)

 parser.add_argument(
     '--secondary_learner_max_epochs'		,							default=15		,							type=_A		,							help='number of epochs to train secondary learner'	)

 parser.add_argument('--trim'		,							default=_A		,							type=_A		,							help='truncate the example if it exceeds context length'	)

 parser.add_argument(
     '--threshold'		,							default=1.0		,							type=_A		,							help=(
         'The threshold value used by secondary learner to filter the train_data and allow only'
         ' informative data as input to the model'
     )		,							)

 parser.add_argument('--finetuned_model_name'		,							default='gpt2_finetuned.pt'		,							type=_A		,							help='finetuned_model_name'	)

 parser.add_argument(
     '--recopy_model'		,							default=_A		,							type=_A		,							help='Reset the model to the original pretrained GPT-2 weights after each iteration'		,							)

 # function calls
 # Collecting *n* pairs of context and information gain(X, IG(X)) for training the secondary learner
 generate_n_pairs(
     context_len=32		,							max_steps=10		,							size_objective_set=1_00		,							min_len=10_26		,							trim=_A		,							data_file='data/tokenized_stories_train_wikitext103.jbl'		,							igf_data_file='igf_context_pairs.jbl'		,							)

 # Load train data for secondary learner
 SCREAMING_SNAKE_CASE								=			joblib.load('data/IGF_values.jbl'	)

 # Train secondary learner
 SCREAMING_SNAKE_CASE								=			training_secondary_learner(
     _A		,							secondary_learner_max_epochs=15		,							secondary_learner_batch_size=1_28		,							eval_freq=1_00		,							igf_model_path='igf_model.pt'		,							)

 # load pretrained gpt2 model
 SCREAMING_SNAKE_CASE								=			GPTaLMHeadModel.from_pretrained('gpt2'	)
 set_seed(42	)

 # Generate train and test data to train and evaluate gpt2 model
 SCREAMING_SNAKE_CASE						,	SCREAMING_SNAKE_CASE								=			generate_datasets(
     context_len=32		,							file='data/tokenized_stories_train_wikitext103.jbl'		,							number=1_00		,							min_len=10_26		,							trim=_A	)

 # fine-tuning of the gpt2 model using igf (Information Gain Filtration)
 finetune(
     _A		,							_A		,							_A		,							context_len=32		,							max_steps=10_00		,							batch_size=16		,							threshold=1.0		,							recopy_model=_A		,							secondary_learner=_A		,							eval_interval=10		,							finetuned_model_name='gpt2_finetuned.pt'		,							)


if __name__ == "__main__":
   main()




import heapq
import sys

import numpy as np

a_    :						Optional[int]    		=      tuple[int, int]




class      UpperCamelCase :

    def __init__(			self :      Dict    ):

     """simple docstring"""






     SCREAMING_SNAKE_CASE								=			[]
     SCREAMING_SNAKE_CASE								=			set()

    def UpperCamelCase			(			self :      List[Any]    ):

     """simple docstring"""






     if not self.empty():
      return self.elements[0][0]
     else:
      return float('inf'    )

    def UpperCamelCase			(			self :      List[str]    ):

     """simple docstring"""






     return len(self.elements    ) == 0

    def UpperCamelCase			(			self :      Union[str, Any]							,    snake_case__ :      Optional[Any]							,    snake_case__ :      List[Any]    ):

     """simple docstring"""






     if item not in self.set:
      heapq.heappush(self.elements							,    (priority, item)    )
      self.set.add(snake_case__    )
     else:
      # update
      # print("update", item)
      SCREAMING_SNAKE_CASE								=			[]
      ((SCREAMING_SNAKE_CASE)						,	(SCREAMING_SNAKE_CASE))								=			heapq.heappop(self.elements    )
      while x != item:
       temp.append((pri, x)    )
       ((SCREAMING_SNAKE_CASE)						,	(SCREAMING_SNAKE_CASE))								=			heapq.heappop(self.elements    )
      temp.append((priority, item)    )
      for pro, xxx in temp:
       heapq.heappush(self.elements							,    (pro, xxx)    )

    def UpperCamelCase			(			self :      Dict							,    snake_case__ :      Dict    ):

     """simple docstring"""






     if item in self.set:
      self.set.remove(snake_case__    )
      SCREAMING_SNAKE_CASE								=			[]
      ((SCREAMING_SNAKE_CASE)						,	(SCREAMING_SNAKE_CASE))								=			heapq.heappop(self.elements    )
      while x != item:
       temp.append((pro, x)    )
       ((SCREAMING_SNAKE_CASE)						,	(SCREAMING_SNAKE_CASE))								=			heapq.heappop(self.elements    )
      for prito, yyy in temp:
       heapq.heappush(self.elements							,    (prito, yyy)    )

    def UpperCamelCase			(			self :      str    ):

     """simple docstring"""






     return self.elements[0][1]




    def UpperCamelCase			(			self :      Tuple    ):

     """simple docstring"""






     ((SCREAMING_SNAKE_CASE)						,	(SCREAMING_SNAKE_CASE))								=			heapq.heappop(self.elements    )
     self.set.remove(snake_case__    )
     return (priority, item)


def        __lowerCAmelCase    (       _UpperCamelCase		:  TPos		,							_UpperCamelCase		:  TPos	)		->							Optional[Any]:
 '''simple docstring'''


 SCREAMING_SNAKE_CASE								=			np.array(_UpperCamelCase	)
 SCREAMING_SNAKE_CASE								=			np.array(_UpperCamelCase	)
 return np.linalg.norm(a - b	)


def        __lowerCAmelCase    (       _UpperCamelCase		:  TPos		,							_UpperCamelCase		:  TPos	)		->							Dict:
 '''simple docstring'''


 return consistent_heuristic(_UpperCamelCase		,							_UpperCamelCase	) // t


def        __lowerCAmelCase    (       _UpperCamelCase		:  TPos		,							_UpperCamelCase		:  TPos	)		->							Optional[int]:
 '''simple docstring'''


 return abs(p[0] - goal[0]	) + abs(p[1] - goal[1]	)


def        __lowerCAmelCase    (       _UpperCamelCase		:  TPos		,							_UpperCamelCase		:  int		,							_UpperCamelCase		:  TPos		,							_UpperCamelCase		:  dict[TPos, float]	)		->							List[str]:
 '''simple docstring'''


 SCREAMING_SNAKE_CASE								=			g_function[start] + Wa * heuristics[i](_UpperCamelCase		,							_UpperCamelCase	)
 return ans


def        __lowerCAmelCase    (       _UpperCamelCase		:  List[str]		,							_UpperCamelCase		:  int		,							_UpperCamelCase		:  Tuple	)		->							int:
 '''simple docstring'''


 SCREAMING_SNAKE_CASE								=			np.chararray((n, n)	)
 for i in range(_UpperCamelCase	):
  for j in range(_UpperCamelCase	):
   SCREAMING_SNAKE_CASE								=			'*'

 for i in range(_UpperCamelCase	):
  for j in range(_UpperCamelCase	):
   if (j, (n - 1) - i) in blocks:
    SCREAMING_SNAKE_CASE								=			'#'

 SCREAMING_SNAKE_CASE								=			'-'
 SCREAMING_SNAKE_CASE								=			back_pointer[goal]
 while x != start:
  ((SCREAMING_SNAKE_CASE)						,	(SCREAMING_SNAKE_CASE))								=			x
  # print(x)
  SCREAMING_SNAKE_CASE								=			'-'
  SCREAMING_SNAKE_CASE								=			back_pointer[x]
 SCREAMING_SNAKE_CASE								=			'-'

 for i in range(_UpperCamelCase	):
  for j in range(_UpperCamelCase	):
   if (i, j) == (0, n - 1):
    print(grid[i][j]		,							end=' '	)
    print('<-- End position'		,							end=' '	)
   else:
    print(grid[i][j]		,							end=' '	)
  print()
 print('^'	)
 print('Start position'	)
 print()
 print('# is an obstacle'	)
 print('- is the path taken by algorithm'	)
 print('PATH TAKEN BY THE ALGORITHM IS:-'	)
 SCREAMING_SNAKE_CASE								=			back_pointer[goal]
 while x != start:
  print(_UpperCamelCase		,							end=' '	)
  SCREAMING_SNAKE_CASE								=			back_pointer[x]
 print(_UpperCamelCase	)
 sys.exit()


def        __lowerCAmelCase    (       _UpperCamelCase		:  TPos	)		->							Any:
 '''simple docstring'''


 if p[0] < 0 or p[0] > n - 1:
  return False
 if p[1] < 0 or p[1] > n - 1:
  return False
 return True


def        __lowerCAmelCase    (       _UpperCamelCase		:  List[Any]		,							_UpperCamelCase		:  Tuple		,							_UpperCamelCase		:  Any		,							_UpperCamelCase		:  Union[str, Any]		,							_UpperCamelCase		:  Union[str, Any]		,							_UpperCamelCase		:  Tuple		,							_UpperCamelCase		:  List[Any]		,							_UpperCamelCase		:  Optional[Any]		,							)		->							List[Any]:
 '''simple docstring'''


 for itera in range(_UpperCamelCase	):
  open_list[itera].remove_element(_UpperCamelCase	)
 # print("s", s)
 # print("j", j)
 ((SCREAMING_SNAKE_CASE)						,	(SCREAMING_SNAKE_CASE))								=			s
 SCREAMING_SNAKE_CASE								=			(x - 1, y)
 SCREAMING_SNAKE_CASE								=			(x + 1, y)
 SCREAMING_SNAKE_CASE								=			(x, y + 1)
 SCREAMING_SNAKE_CASE								=			(x, y - 1)

 for neighbours in [left, right, up, down]:
  if neighbours not in blocks:
   if valid(_UpperCamelCase	) and neighbours not in visited:
    # print("neighbour", neighbours)
    visited.add(_UpperCamelCase	)
    SCREAMING_SNAKE_CASE								=			-1
    SCREAMING_SNAKE_CASE								=			float('inf'	)

   if valid(_UpperCamelCase	) and g_function[neighbours] > g_function[s] + 1:
    SCREAMING_SNAKE_CASE								=			g_function[s] + 1
    SCREAMING_SNAKE_CASE								=			s
    if neighbours not in close_list_anchor:
     open_list[0].put(_UpperCamelCase		,							key(_UpperCamelCase		,							0		,							_UpperCamelCase		,							_UpperCamelCase	)	)
     if neighbours not in close_list_inad:
      for var in range(1		,							_UpperCamelCase	):
       if key(_UpperCamelCase		,							_UpperCamelCase		,							_UpperCamelCase		,							_UpperCamelCase	) <= Wa * key(
           _UpperCamelCase		,							0		,							_UpperCamelCase		,							_UpperCamelCase	):
        open_list[j].put(
            _UpperCamelCase		,							key(_UpperCamelCase		,							_UpperCamelCase		,							_UpperCamelCase		,							_UpperCamelCase	)	)


def        __lowerCAmelCase    (       )		->							Tuple:
 '''simple docstring'''


 SCREAMING_SNAKE_CASE								=			[]
 for x in range(1		,							5	):
  for y in range(1		,							6	):
   some_list.append((x, y)	)

 for x in range(15		,							20	):
  some_list.append((x, 17)	)

 for x in range(10		,							19	):
  for y in range(1		,							15	):
   some_list.append((x, y)	)

    # L block
 for x in range(1		,							4	):
  for y in range(12		,							19	):
   some_list.append((x, y)	)
 for x in range(3		,							13	):
  for y in range(16		,							19	):
   some_list.append((x, y)	)
 return some_list


a_    :						str    		=      {0: consistent_heuristic, 1: heuristic_a, 2: heuristic_a}

a_    :						List[str]    		=      [
    (0, 1),
    (1, 1),
    (2, 1),
    (3, 1),
    (4, 1),
    (5, 1),
    (6, 1),
    (7, 1),
    (8, 1),
    (9, 1),
    (10, 1),
    (11, 1),
    (12, 1),
    (13, 1),
    (14, 1),
    (15, 1),
    (16, 1),
    (17, 1),
    (18, 1),
    (19, 1),
]
a_    :						Union[str, Any]    		=      make_common_ground()


a_    :						Tuple    		=      blocks_blk
# hyper parameters
a_    :						Any    		=      1
a_    :						List[str]    		=      1
a_    :						Union[str, Any]    		=      20
a_    :						Optional[Any]    		=      3  # one consistent and two other inconsistent

# start and end destination
a_    :						int    		=      (0, 0)
a_    :						Optional[int]    		=      (n - 1, n - 1)

a_    :						Union[str, Any]    		=      1


def        __lowerCAmelCase    (       _UpperCamelCase		:  TPos		,							_UpperCamelCase		:  TPos		,							_UpperCamelCase		:  int	)		->							List[Any]:
 '''simple docstring'''


 SCREAMING_SNAKE_CASE								=			{start: 0, goal: float('inf'	)}
 SCREAMING_SNAKE_CASE								=			{start: -1, goal: -1}
 SCREAMING_SNAKE_CASE								=			[]
 SCREAMING_SNAKE_CASE								=			set()

 for i in range(_UpperCamelCase	):
  open_list.append(PriorityQueue()	)
  open_list[i].put(_UpperCamelCase		,							key(_UpperCamelCase		,							_UpperCamelCase		,							_UpperCamelCase		,							_UpperCamelCase	)	)

 SCREAMING_SNAKE_CASE								=			[]
 SCREAMING_SNAKE_CASE								=			[]
 while open_list[0].minkey() < float('inf'	):
  for i in range(1		,							_UpperCamelCase	):
   # print(open_list[0].minkey(), open_list[i].minkey())
   if open_list[i].minkey() <= Wa * open_list[0].minkey():
    global t
    t += 1
    if g_function[goal] <= open_list[i].minkey():
     if g_function[goal] < float('inf'	):
      do_something(_UpperCamelCase		,							_UpperCamelCase		,							_UpperCamelCase	)
    else:
     SCREAMING_SNAKE_CASE						,	SCREAMING_SNAKE_CASE								=			open_list[i].top_show()
     visited.add(_UpperCamelCase	)
     expand_state(
         _UpperCamelCase		,							_UpperCamelCase		,							_UpperCamelCase		,							_UpperCamelCase		,							_UpperCamelCase		,							_UpperCamelCase		,							_UpperCamelCase		,							_UpperCamelCase		,							)
     close_list_inad.append(_UpperCamelCase	)
   else:
    if g_function[goal] <= open_list[0].minkey():
     if g_function[goal] < float('inf'	):
      do_something(_UpperCamelCase		,							_UpperCamelCase		,							_UpperCamelCase	)
    else:
     SCREAMING_SNAKE_CASE								=			open_list[0].top_show()
     visited.add(_UpperCamelCase	)
     expand_state(
         _UpperCamelCase		,							0		,							_UpperCamelCase		,							_UpperCamelCase		,							_UpperCamelCase		,							_UpperCamelCase		,							_UpperCamelCase		,							_UpperCamelCase		,							)
     close_list_anchor.append(_UpperCamelCase	)
 print('No path found to goal'	)
 print()
 for i in range(n - 1		,							-1		,							-1	):
  for j in range(_UpperCamelCase	):
   if (j, i) in blocks:
    print('#'		,							end=' '	)
   elif (j, i) in back_pointer:
    if (j, i) == (n - 1, n - 1):
     print('*'		,							end=' '	)
    else:
     print('-'		,							end=' '	)
   else:
    print('*'		,							end=' '	)
   if (j, i) == (n - 1, n - 1):
    print('<-- End position'		,							end=' '	)
  print()
 print('^'	)
 print('Start position'	)
 print()
 print('# is an obstacle'	)
 print('- is the path taken by algorithm'	)


if __name__ == "__main__":
      multi_a_star(start, goal, n_heuristic)

