



'''simple docstring'''



from __future__ import annotations

import unittest

from transformers import is_tf_available, is_torch_available
from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER, SMALL_MODEL_IDENTIFIER, is_pt_tf_cross_test, slow


if is_tf_available():
		from transformers import (
		    AutoConfig,
		    BertConfig,
		    GPTaConfig,
		    TaConfig,
		    TFAutoModel,
		    TFAutoModelForCausalLM,
		    TFAutoModelForMaskedLM,
		    TFAutoModelForPreTraining,
		    TFAutoModelForQuestionAnswering,
		    TFAutoModelForSeqaSeqLM,
		    TFAutoModelForSequenceClassification,
		    TFAutoModelWithLMHead,
		    TFBertForMaskedLM,
		    TFBertForPreTraining,
		    TFBertForQuestionAnswering,
		    TFBertForSequenceClassification,
		    TFBertModel,
		    TFGPTaLMHeadModel,
		    TFRobertaForMaskedLM,
		    TFTaForConditionalGeneration,
		)
		from transformers.models.bert.modeling_tf_bert import TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST
		from transformers.models.gpta.modeling_tf_gpta import TF_GPT2_PRETRAINED_MODEL_ARCHIVE_LIST
		from transformers.models.ta.modeling_tf_ta import TF_T5_PRETRAINED_MODEL_ARCHIVE_LIST

if is_torch_available():
		from transformers import (
		    AutoModel,
		    AutoModelForCausalLM,
		    AutoModelForMaskedLM,
		    AutoModelForPreTraining,
		    AutoModelForQuestionAnswering,
		    AutoModelForSeqaSeqLM,
		    AutoModelForSequenceClassification,
		    AutoModelWithLMHead,
		    BertForMaskedLM,
		    BertForPreTraining,
		    BertForQuestionAnswering,
		    BertForSequenceClassification,
		    BertModel,
		    GPTaLMHeadModel,
		    RobertaForMaskedLM,
		    TaForConditionalGeneration,
		)





@is_pt_tf_cross_test
class _UpperCamelCase		(  unittest.TestCase		):





				'''simple docstring'''





				@slow
				def 					__lowerCamelCase  (				self	:	int):







											'''simple docstring'''

											for model_name in ["bert-base-uncased"]:
																		__lowercase													=AutoConfig.from_pretrained(lowerCAmelCase__)
																		self.assertIsNotNone(lowerCAmelCase__)
																		self.assertIsInstance(lowerCAmelCase__	,							lowerCAmelCase__)

																		__lowercase													=TFAutoModel.from_pretrained(lowerCAmelCase__	,							from_pt=lowerCAmelCase__)
																		self.assertIsNotNone(lowerCAmelCase__)
																		self.assertIsInstance(lowerCAmelCase__	,							lowerCAmelCase__)

																		__lowercase													=AutoModel.from_pretrained(lowerCAmelCase__	,							from_tf=lowerCAmelCase__)
																		self.assertIsNotNone(lowerCAmelCase__)
																		self.assertIsInstance(lowerCAmelCase__	,							lowerCAmelCase__)

				@slow
				def 					__lowerCamelCase  (				self	:	List[str]):







											'''simple docstring'''

											for model_name in ["bert-base-uncased"]:
																		__lowercase													=AutoConfig.from_pretrained(lowerCAmelCase__)
																		self.assertIsNotNone(lowerCAmelCase__)
																		self.assertIsInstance(lowerCAmelCase__	,							lowerCAmelCase__)

																		__lowercase													=TFAutoModelForPreTraining.from_pretrained(lowerCAmelCase__	,							from_pt=lowerCAmelCase__)
																		self.assertIsNotNone(lowerCAmelCase__)
																		self.assertIsInstance(lowerCAmelCase__	,							lowerCAmelCase__)

																		__lowercase													=AutoModelForPreTraining.from_pretrained(lowerCAmelCase__	,							from_tf=lowerCAmelCase__)
																		self.assertIsNotNone(lowerCAmelCase__)
																		self.assertIsInstance(lowerCAmelCase__	,							lowerCAmelCase__)

				@slow
				def 					__lowerCamelCase  (				self	:	List[str]):







											'''simple docstring'''

											for model_name in TF_GPT2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																		__lowercase													=AutoConfig.from_pretrained(lowerCAmelCase__)
																		self.assertIsNotNone(lowerCAmelCase__)
																		self.assertIsInstance(lowerCAmelCase__	,							lowerCAmelCase__)

																		__lowercase													=TFAutoModelForCausalLM.from_pretrained(lowerCAmelCase__	,							from_pt=lowerCAmelCase__)
																		__lowercase													=TFAutoModelForCausalLM.from_pretrained(
																		    lowerCAmelCase__	,							output_loading_info=lowerCAmelCase__	,							from_pt=lowerCAmelCase__)
																		self.assertIsNotNone(lowerCAmelCase__)
																		self.assertIsInstance(lowerCAmelCase__	,							lowerCAmelCase__)

																		__lowercase													=AutoModelForCausalLM.from_pretrained(lowerCAmelCase__	,							from_tf=lowerCAmelCase__)
																		__lowercase													=AutoModelForCausalLM.from_pretrained(
																		    lowerCAmelCase__	,							output_loading_info=lowerCAmelCase__	,							from_tf=lowerCAmelCase__)
																		self.assertIsNotNone(lowerCAmelCase__)
																		self.assertIsInstance(lowerCAmelCase__	,							lowerCAmelCase__)

				@slow
				def 					__lowerCamelCase  (				self	:	Dict):







											'''simple docstring'''

											for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																		__lowercase													=AutoConfig.from_pretrained(lowerCAmelCase__)
																		self.assertIsNotNone(lowerCAmelCase__)
																		self.assertIsInstance(lowerCAmelCase__	,							lowerCAmelCase__)

																		__lowercase													=TFAutoModelWithLMHead.from_pretrained(lowerCAmelCase__	,							from_pt=lowerCAmelCase__)
																		self.assertIsNotNone(lowerCAmelCase__)
																		self.assertIsInstance(lowerCAmelCase__	,							lowerCAmelCase__)

																		__lowercase													=AutoModelWithLMHead.from_pretrained(lowerCAmelCase__	,							from_tf=lowerCAmelCase__)
																		self.assertIsNotNone(lowerCAmelCase__)
																		self.assertIsInstance(lowerCAmelCase__	,							lowerCAmelCase__)

				@slow
				def 					__lowerCamelCase  (				self	:	Dict):







											'''simple docstring'''

											for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																		__lowercase													=AutoConfig.from_pretrained(lowerCAmelCase__)
																		self.assertIsNotNone(lowerCAmelCase__)
																		self.assertIsInstance(lowerCAmelCase__	,							lowerCAmelCase__)

																		__lowercase													=TFAutoModelForMaskedLM.from_pretrained(lowerCAmelCase__	,							from_pt=lowerCAmelCase__)
																		__lowercase													=TFAutoModelForMaskedLM.from_pretrained(
																		    lowerCAmelCase__	,							output_loading_info=lowerCAmelCase__	,							from_pt=lowerCAmelCase__)
																		self.assertIsNotNone(lowerCAmelCase__)
																		self.assertIsInstance(lowerCAmelCase__	,							lowerCAmelCase__)

																		__lowercase													=AutoModelForMaskedLM.from_pretrained(lowerCAmelCase__	,							from_tf=lowerCAmelCase__)
																		__lowercase													=AutoModelForMaskedLM.from_pretrained(
																		    lowerCAmelCase__	,							output_loading_info=lowerCAmelCase__	,							from_tf=lowerCAmelCase__)
																		self.assertIsNotNone(lowerCAmelCase__)
																		self.assertIsInstance(lowerCAmelCase__	,							lowerCAmelCase__)

				@slow
				def 					__lowerCamelCase  (				self	:	Optional[Any]):







											'''simple docstring'''

											for model_name in TF_T5_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																		__lowercase													=AutoConfig.from_pretrained(lowerCAmelCase__)
																		self.assertIsNotNone(lowerCAmelCase__)
																		self.assertIsInstance(lowerCAmelCase__	,							lowerCAmelCase__)

																		__lowercase													=TFAutoModelForSeqaSeqLM.from_pretrained(lowerCAmelCase__	,							from_pt=lowerCAmelCase__)
																		__lowercase													=TFAutoModelForSeqaSeqLM.from_pretrained(
																		    lowerCAmelCase__	,							output_loading_info=lowerCAmelCase__	,							from_pt=lowerCAmelCase__)
																		self.assertIsNotNone(lowerCAmelCase__)
																		self.assertIsInstance(lowerCAmelCase__	,							lowerCAmelCase__)

																		__lowercase													=AutoModelForSeqaSeqLM.from_pretrained(lowerCAmelCase__	,							from_tf=lowerCAmelCase__)
																		__lowercase													=AutoModelForSeqaSeqLM.from_pretrained(
																		    lowerCAmelCase__	,							output_loading_info=lowerCAmelCase__	,							from_tf=lowerCAmelCase__)
																		self.assertIsNotNone(lowerCAmelCase__)
																		self.assertIsInstance(lowerCAmelCase__	,							lowerCAmelCase__)

				@slow
				def 					__lowerCamelCase  (				self	:	Tuple):







											'''simple docstring'''

											for model_name in ["bert-base-uncased"]:
																		__lowercase													=AutoConfig.from_pretrained(lowerCAmelCase__)
																		self.assertIsNotNone(lowerCAmelCase__)
																		self.assertIsInstance(lowerCAmelCase__	,							lowerCAmelCase__)

																		__lowercase													=TFAutoModelForSequenceClassification.from_pretrained(lowerCAmelCase__	,							from_pt=lowerCAmelCase__)
																		self.assertIsNotNone(lowerCAmelCase__)
																		self.assertIsInstance(lowerCAmelCase__	,							lowerCAmelCase__)

																		__lowercase													=AutoModelForSequenceClassification.from_pretrained(lowerCAmelCase__	,							from_tf=lowerCAmelCase__)
																		self.assertIsNotNone(lowerCAmelCase__)
																		self.assertIsInstance(lowerCAmelCase__	,							lowerCAmelCase__)

				@slow
				def 					__lowerCamelCase  (				self	:	List[str]):







											'''simple docstring'''

											for model_name in ["bert-base-uncased"]:
																		__lowercase													=AutoConfig.from_pretrained(lowerCAmelCase__)
																		self.assertIsNotNone(lowerCAmelCase__)
																		self.assertIsInstance(lowerCAmelCase__	,							lowerCAmelCase__)

																		__lowercase													=TFAutoModelForQuestionAnswering.from_pretrained(lowerCAmelCase__	,							from_pt=lowerCAmelCase__)
																		self.assertIsNotNone(lowerCAmelCase__)
																		self.assertIsInstance(lowerCAmelCase__	,							lowerCAmelCase__)

																		__lowercase													=AutoModelForQuestionAnswering.from_pretrained(lowerCAmelCase__	,							from_tf=lowerCAmelCase__)
																		self.assertIsNotNone(lowerCAmelCase__)
																		self.assertIsInstance(lowerCAmelCase__	,							lowerCAmelCase__)

				def 					__lowerCamelCase  (				self	:	Any):







											'''simple docstring'''

											__lowercase													=TFAutoModelWithLMHead.from_pretrained(lowerCAmelCase__	,							from_pt=lowerCAmelCase__)
											self.assertIsInstance(lowerCAmelCase__	,							lowerCAmelCase__)
											self.assertEqual(model.num_parameters()	,							1_4_4_1_0)
											self.assertEqual(model.num_parameters(only_trainable=lowerCAmelCase__)	,							1_4_4_1_0)

											__lowercase													=AutoModelWithLMHead.from_pretrained(lowerCAmelCase__	,							from_tf=lowerCAmelCase__)
											self.assertIsInstance(lowerCAmelCase__	,							lowerCAmelCase__)
											self.assertEqual(model.num_parameters()	,							1_4_4_1_0)
											self.assertEqual(model.num_parameters(only_trainable=lowerCAmelCase__)	,							1_4_4_1_0)

				def 					__lowerCamelCase  (				self	:	Optional[int]):







											'''simple docstring'''

											__lowercase													=TFAutoModelWithLMHead.from_pretrained(lowerCAmelCase__	,							from_pt=lowerCAmelCase__)
											self.assertIsInstance(lowerCAmelCase__	,							lowerCAmelCase__)
											self.assertEqual(model.num_parameters()	,							1_4_4_1_0)
											self.assertEqual(model.num_parameters(only_trainable=lowerCAmelCase__)	,							1_4_4_1_0)

											__lowercase													=AutoModelWithLMHead.from_pretrained(lowerCAmelCase__	,							from_tf=lowerCAmelCase__)
											self.assertIsInstance(lowerCAmelCase__	,							lowerCAmelCase__)
											self.assertEqual(model.num_parameters()	,							1_4_4_1_0)
											self.assertEqual(model.num_parameters(only_trainable=lowerCAmelCase__)	,							1_4_4_1_0)










"""simple docstring"""




from __future__ import annotations

from statistics import mean






def  _SCREAMING_SNAKE_CASE						(      _lowercase		:       list[int]       ,			_lowercase		:       list[int]       ,			_lowercase		:       int   )					->list[int]:






	'''simple docstring'''






	a :						Union[str, Any]      =							[0] * no_of_processes
	a :						int      =							[0] * no_of_processes

	# Initialize remaining_time to waiting_time.

	for i in range(_lowercase   ):
		a :						List[Any]      =							burst_time[i]
	a :						list[int]      =							[]

	a :						List[Any]      =							0
	a :						Any      =							0

	# When processes are not completed,
	# A process whose arrival time has passed \
	# and has remaining execution time is put into the ready_process.
	# The shortest process in the ready_process, target_process is executed.

	while completed != no_of_processes:
		a :						str      =							[]
		a :						Tuple      =							-1

		for i in range(_lowercase   ):
			if (arrival_time[i] <= total_time) and (remaining_time[i] > 0):
				ready_process.append(_lowercase   )

		if len(_lowercase   ) > 0:
			a :						List[Any]      =							ready_process[0]
			for i in ready_process:
				if remaining_time[i] < remaining_time[target_process]:
					a :						Optional[Any]      =							i
			total_time += burst_time[target_process]
			completed += 1
			a :						str      =							0
			a :						Union[str, Any]      =							(
			    total_time - arrival_time[target_process] - burst_time[target_process]
			)
		else:
			total_time += 1

	return waiting_time






def  _SCREAMING_SNAKE_CASE						(      _lowercase		:       list[int]       ,			_lowercase		:       int       ,			_lowercase		:       list[int]   )					->list[int]:






	'''simple docstring'''






	a :						List[str]      =							[0] * no_of_processes
	for i in range(_lowercase   ):
		a :						Optional[int]      =							burst_time[i] + waiting_time[i]
	return turn_around_time


if __name__ == "__main__":
		print('''[TEST CASE 01]''')

		a		:					Dict	      =     4
		a		:					Tuple	      =     [2, 5, 3, 7]
		a		:					List[Any]	      =     [0, 0, 0, 0]
		a		:					int	      =     calculate_waitingtime(arrival_time, burst_time, no_of_processes)
		a		:					List[Any]	      =     calculate_turnaroundtime(
		    burst_time, no_of_processes, waiting_time
		)

		# Printing the Result
		print('''PID\tBurst Time\tArrival Time\tWaiting Time\tTurnaround Time''')
		for i, process_id in enumerate(list(range(1, 5))):
				print(
				    F'''{process_id}\t{burst_time[i]}\t\t\t{arrival_time[i]}\t\t\t\t'''
				    F'''{waiting_time[i]}\t\t\t\t{turn_around_time[i]}'''
				)
		print(F'''\nAverage waiting time = {mean(waiting_time):.5f}''')
		print(F'''Average turnaround time = {mean(turn_around_time):.5f}''')


