


"""simple docstring"""







import importlib
import json
import os
import sys
import tempfile
import unittest
from pathlib import Path

import transformers
import transformers.models.auto
from transformers.models.auto.configuration_auto import CONFIG_MAPPING, AutoConfig
from transformers.models.bert.configuration_bert import BertConfig
from transformers.models.roberta.configuration_roberta import RobertaConfig
from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER, get_tests_dir


sys.path.append(str(Path(__file__).parent.parent.parent.parent / '''utils'''))

from test_module.custom_configuration import CustomConfig  # noqa E402


a__    :							int            =					get_tests_dir('''fixtures/dummy-config.json''')




class 			UpperCamelCase_     (			unittest.TestCase):

	"""simple docstring"""





	def   UpperCAmelCase_				(			self      :    str       )	->     int:
						__SCREAMING_SNAKE_CASE						       =    0




	def   UpperCAmelCase_				(			self      :    int       )	->     List[Any]:
						self.assertIsNotNone(transformers.models.auto.__spec__       )
						self.assertIsNotNone(importlib.util.find_spec("transformers.models.auto"       )       )




	def   UpperCAmelCase_				(			self      :    Optional[int]       )	->     List[Any]:
						__SCREAMING_SNAKE_CASE						       =    AutoConfig.from_pretrained("bert-base-uncased"       )
						self.assertIsInstance(UpperCAmelCase__      ,      UpperCAmelCase__       )




	def   UpperCAmelCase_				(			self      :    Dict       )	->     str:
						__SCREAMING_SNAKE_CASE						       =    AutoConfig.from_pretrained(UpperCAmelCase__       )
						self.assertIsInstance(UpperCAmelCase__      ,      UpperCAmelCase__       )




	def   UpperCAmelCase_				(			self      :    int       )	->     Tuple:
						__SCREAMING_SNAKE_CASE						       =    AutoConfig.from_pretrained(UpperCAmelCase__       )
						self.assertIsInstance(UpperCAmelCase__      ,      UpperCAmelCase__       )




	def   UpperCAmelCase_				(			self      :    str       )	->     int:
						__SCREAMING_SNAKE_CASE						       =    AutoConfig.for_model("roberta"       )
						self.assertIsInstance(UpperCAmelCase__      ,      UpperCAmelCase__       )




	def   UpperCAmelCase_				(			self      :    str       )	->     List[Any]:
						with tempfile.TemporaryDirectory() as tmp_dir:
											# This model name contains bert and roberta, but roberta ends up being picked.
											__SCREAMING_SNAKE_CASE						       =    os.path.join(UpperCAmelCase__      ,      "fake-roberta"       )
											os.makedirs(UpperCAmelCase__      ,      exist_ok=UpperCAmelCase__       )
											with open(os.path.join(UpperCAmelCase__      ,      "config.json"       )      ,      "w"       ) as f:
																f.write(json.dumps({}       )       )
											__SCREAMING_SNAKE_CASE						       =    AutoConfig.from_pretrained(UpperCAmelCase__       )
											self.assertEqual(type(UpperCAmelCase__       )      ,      UpperCAmelCase__       )




	def   UpperCAmelCase_				(			self      :    Optional[int]       )	->     Any:
						try:
											AutoConfig.register("custom"      ,      UpperCAmelCase__       )
											# Wrong model type will raise an error
											with self.assertRaises(UpperCAmelCase__       ):
																AutoConfig.register("model"      ,      UpperCAmelCase__       )
											# Trying to register something existing in the Transformers library will raise an error
											with self.assertRaises(UpperCAmelCase__       ):
																AutoConfig.register("bert"      ,      UpperCAmelCase__       )

											# Now that the config is registered, it can be used as any other config with the auto-API
											__SCREAMING_SNAKE_CASE						       =    CustomConfig()
											with tempfile.TemporaryDirectory() as tmp_dir:
																config.save_pretrained(UpperCAmelCase__       )
																__SCREAMING_SNAKE_CASE						       =    AutoConfig.from_pretrained(UpperCAmelCase__       )
																self.assertIsInstance(UpperCAmelCase__      ,      UpperCAmelCase__       )

						finally:
											if "custom" in CONFIG_MAPPING._extra_content:
																del CONFIG_MAPPING._extra_content["custom"]




	def   UpperCAmelCase_				(			self      :    List[str]       )	->     Any:
						with self.assertRaisesRegex(
						    UpperCAmelCase__      ,      "bert-base is not a local folder and is not a valid model identifier"       ):
											__SCREAMING_SNAKE_CASE						       =    AutoConfig.from_pretrained("bert-base"       )




	def   UpperCAmelCase_				(			self      :    Dict       )	->     List[Any]:
						with self.assertRaisesRegex(
						    UpperCAmelCase__      ,      R"aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)"       ):
											__SCREAMING_SNAKE_CASE						       =    AutoConfig.from_pretrained(UpperCAmelCase__      ,      revision="aaaaaa"       )




	def   UpperCAmelCase_				(			self      :    List[Any]       )	->     str:
						with self.assertRaisesRegex(
						    UpperCAmelCase__      ,      "hf-internal-testing/no-config-test-repo does not appear to have a file named config.json."      ,      ):
											__SCREAMING_SNAKE_CASE						       =    AutoConfig.from_pretrained("hf-internal-testing/no-config-test-repo"       )




	def   UpperCAmelCase_				(			self      :    List[str]       )	->     str:
						# If remote code is not set, we will time out when asking whether to load the model.
						with self.assertRaises(UpperCAmelCase__       ):
											__SCREAMING_SNAKE_CASE						       =    AutoConfig.from_pretrained("hf-internal-testing/test_dynamic_model"       )
						# If remote code is disabled, we can't load this config.
						with self.assertRaises(UpperCAmelCase__       ):
											__SCREAMING_SNAKE_CASE						       =    AutoConfig.from_pretrained("hf-internal-testing/test_dynamic_model"      ,      trust_remote_code=UpperCAmelCase__       )

						__SCREAMING_SNAKE_CASE						       =    AutoConfig.from_pretrained("hf-internal-testing/test_dynamic_model"      ,      trust_remote_code=UpperCAmelCase__       )
						self.assertEqual(config.__class__.__name__      ,      "NewModelConfig"       )

						# Test config can be reloaded.
						with tempfile.TemporaryDirectory() as tmp_dir:
											config.save_pretrained(UpperCAmelCase__       )
											__SCREAMING_SNAKE_CASE						       =    AutoConfig.from_pretrained(UpperCAmelCase__      ,      trust_remote_code=UpperCAmelCase__       )
						self.assertEqual(reloaded_config.__class__.__name__      ,      "NewModelConfig"       )




	def   UpperCAmelCase_				(			self      :    List[Any]       )	->     Tuple:




						class 			UpperCamelCase_     (			UpperCamelCase):

							"""simple docstring"""





							snake_case__    :  int    =      "new-model"

						try:
											AutoConfig.register("new-model"      ,      UpperCAmelCase__       )
											# If remote code is not set, the default is to use local
											__SCREAMING_SNAKE_CASE						       =    AutoConfig.from_pretrained("hf-internal-testing/test_dynamic_model"       )
											self.assertEqual(config.__class__.__name__      ,      "NewModelConfigLocal"       )

											# If remote code is disabled, we load the local one.
											__SCREAMING_SNAKE_CASE						       =    AutoConfig.from_pretrained("hf-internal-testing/test_dynamic_model"      ,      trust_remote_code=UpperCAmelCase__       )
											self.assertEqual(config.__class__.__name__      ,      "NewModelConfigLocal"       )

											# If remote is enabled, we load from the Hub
											__SCREAMING_SNAKE_CASE						       =    AutoConfig.from_pretrained("hf-internal-testing/test_dynamic_model"      ,      trust_remote_code=UpperCAmelCase__       )
											self.assertEqual(config.__class__.__name__      ,      "NewModelConfig"       )

						finally:
											if "new-model" in CONFIG_MAPPING._extra_content:
																del CONFIG_MAPPING._extra_content["new-model"]




"""simple docstring"""







from __future__ import annotations




def        UpperCAmelCase__	(lowerCAmelCase_  ,						lowerCAmelCase_       ):




					'''simple docstring'''


					print(f"""Vertex\tShortest Distance from vertex {src}"""       )
					for i, d in enumerate(lowerCAmelCase_       ):
										print(f"""{i}\t\t{d}"""       )




def        UpperCAmelCase__	(lowerCAmelCase_  ,						lowerCAmelCase_  ,						lowerCAmelCase_       ):




					'''simple docstring'''


					for j in range(lowerCAmelCase_       ):
										__SCREAMING_SNAKE_CASE       ,  __SCREAMING_SNAKE_CASE       ,  __SCREAMING_SNAKE_CASE						       =    (graph[j][k] for k in ["src", "dst", "weight"])
										if distance[u] != float("inf"       ) and distance[u] + w < distance[v]:
															return True
					return False




def        UpperCAmelCase__	(lowerCAmelCase_  ,						lowerCAmelCase_  ,						lowerCAmelCase_  ,						lowerCAmelCase_       ):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE						       =    [float("inf"       )] * vertex_count
					__SCREAMING_SNAKE_CASE						       =    0.0

					for _ in range(vertex_count - 1       ):
										for j in range(lowerCAmelCase_       ):
															__SCREAMING_SNAKE_CASE       ,  __SCREAMING_SNAKE_CASE       ,  __SCREAMING_SNAKE_CASE						       =    (graph[j][k] for k in ["src", "dst", "weight"])

															if distance[u] != float("inf"       ) and distance[u] + w < distance[v]:
																				__SCREAMING_SNAKE_CASE						       =    distance[u] + w

					__SCREAMING_SNAKE_CASE						       =    check_negative_cycle(lowerCAmelCase_  ,						lowerCAmelCase_  ,						lowerCAmelCase_       )
					if negative_cycle_exists:
										raise Exception("Negative cycle found"       )

					return distance


if __name__ == "__main__":
		import doctest

		doctest.testmod()

		a__    :							Union[str, Any]            =					int(input('''Enter number of vertices: ''').strip())
		a__    :							Any            =					int(input('''Enter number of edges: ''').strip())

		a__    :							list[dict[str, int]]            =					[{} for _ in range(E)]

		for i in range(E):
				print('''Edge ''', i + 1)
				a__      ,					a__      ,					a__    :							str            =					(
				    int(x)
				    for x in input('''Enter source, destination, weight: ''').strip().split(''' ''')
				)
				a__    :							str            =					{'''src''': src, '''dst''': dest, '''weight''': weight}

		a__    :							str            =					int(input('''\nEnter shortest path source:''').strip())
		a__    :							List[Any]            =					bellman_ford(graph, V, E, source)
		print_distance(shortest_distance, 0)
