


"""simple docstring"""







from __future__ import annotations

import unittest

import numpy as np

from transformers import OPTConfig, is_tf_available
from transformers.testing_utils import require_sentencepiece, require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
		import tensorflow as tf

		from transformers import GPTaTokenizer, TFOPTForCausalLM, TFOPTModel




def    UpperCAmelCase__       (lowerCAmelCase_  ,						lowerCAmelCase_  ,						lowerCAmelCase_=None  ,						lowerCAmelCase_=None   ):




					'''simple docstring'''


					if attention_mask is None:
										__SCREAMING_SNAKE_CASE						   =				tf.cast(tf.math.not_equal(lowerCAmelCase_  ,						config.pad_token_id   )  ,						tf.inta   )
					return {"input_ids": input_ids, "attention_mask": attention_mask}




@require_tf
class  UpperCamelCase_	:

	"""simple docstring"""





	snake_case__				:  Dict    					=			OPTConfig
	snake_case__				:  List[Any]    					=			{}
	snake_case__				:  List[str]    					=			"gelu"




	def __init__( self			:				Union[str, Any]			,			UpperCAmelCase__			:				int			,			UpperCAmelCase__			:				List[str]=1_3			,			UpperCAmelCase__			:				Optional[int]=7			,			UpperCAmelCase__			:				Tuple=True			,			UpperCAmelCase__			:				Optional[Any]=False			,			UpperCAmelCase__			:				str=9_9			,			UpperCAmelCase__			:				Dict=1_6			,			UpperCAmelCase__			:				Tuple=2			,			UpperCAmelCase__			:				int=4			,			UpperCAmelCase__			:				Tuple=4			,			UpperCAmelCase__			:				str="gelu"			,			UpperCAmelCase__			:				Optional[int]=0.1			,			UpperCAmelCase__			:				Any=0.1			,			UpperCAmelCase__			:				List[str]=2_0			,			UpperCAmelCase__			:				Any=2			,			UpperCAmelCase__			:				str=1			,			UpperCAmelCase__			:				Optional[Any]=0			,			UpperCAmelCase__			:				Optional[Any]=1_6			,			UpperCAmelCase__			:				List[str]=1_6			,			)       ->	List[str]:
						__SCREAMING_SNAKE_CASE						   =				parent
						__SCREAMING_SNAKE_CASE						   =				batch_size
						__SCREAMING_SNAKE_CASE						   =				seq_length
						__SCREAMING_SNAKE_CASE						   =				is_training
						__SCREAMING_SNAKE_CASE						   =				use_labels
						__SCREAMING_SNAKE_CASE						   =				vocab_size
						__SCREAMING_SNAKE_CASE						   =				hidden_size
						__SCREAMING_SNAKE_CASE						   =				num_hidden_layers
						__SCREAMING_SNAKE_CASE						   =				num_attention_heads
						__SCREAMING_SNAKE_CASE						   =				intermediate_size
						__SCREAMING_SNAKE_CASE						   =				hidden_act
						__SCREAMING_SNAKE_CASE						   =				hidden_dropout_prob
						__SCREAMING_SNAKE_CASE						   =				attention_probs_dropout_prob
						__SCREAMING_SNAKE_CASE						   =				max_position_embeddings
						__SCREAMING_SNAKE_CASE						   =				eos_token_id
						__SCREAMING_SNAKE_CASE						   =				pad_token_id
						__SCREAMING_SNAKE_CASE						   =				bos_token_id
						__SCREAMING_SNAKE_CASE						   =				embed_dim
						__SCREAMING_SNAKE_CASE						   =				word_embed_proj_dim
						__SCREAMING_SNAKE_CASE						   =				False




	def   UpperCAmelCase_      ( self			:				Optional[Any]   )       ->	Dict:
						__SCREAMING_SNAKE_CASE						   =				ids_tensor([self.batch_size, self.seq_length - 1]			,			self.vocab_size   )
						__SCREAMING_SNAKE_CASE						   =				tf.expand_dims(tf.constant([self.eos_token_id] * self.batch_size   )			,			1   )
						__SCREAMING_SNAKE_CASE						   =				tf.concat([input_ids, eos_tensor]			,			axis=1   )

						__SCREAMING_SNAKE_CASE						   =				self.config_cls(
						    vocab_size=self.vocab_size			,			hidden_size=self.hidden_size			,			num_hidden_layers=self.num_hidden_layers			,			num_attention_heads=self.num_attention_heads			,			ffn_dim=self.intermediate_size			,			dropout=self.hidden_dropout_prob			,			attention_dropout=self.attention_probs_dropout_prob			,			max_position_embeddings=self.max_position_embeddings			,			eos_token_id=self.eos_token_id			,			bos_token_id=self.bos_token_id			,			pad_token_id=self.pad_token_id			,			embed_dim=self.embed_dim			,			word_embed_proj_dim=self.word_embed_proj_dim			,			is_encoder_decoder=UpperCAmelCase__			,			**self.config_updates			,			)
						__SCREAMING_SNAKE_CASE						   =				prepare_opt_inputs_dict(UpperCAmelCase__			,			UpperCAmelCase__   )
						return config, inputs_dict




	def   UpperCAmelCase_      ( self			:				Optional[Any]			,			UpperCAmelCase__			:				Union[str, Any]			,			UpperCAmelCase__			:				List[Any]   )       ->	str:
						__SCREAMING_SNAKE_CASE						   =				TFOPTModel(config=UpperCAmelCase__   )
						__SCREAMING_SNAKE_CASE						   =				inputs_dict["input_ids"]

						__SCREAMING_SNAKE_CASE						   =				input_ids[:1, :]
						__SCREAMING_SNAKE_CASE						   =				inputs_dict["attention_mask"][:1, :]
						__SCREAMING_SNAKE_CASE						   =				1

						# first forward pass
						__SCREAMING_SNAKE_CASE						   =				model(UpperCAmelCase__			,			attention_mask=UpperCAmelCase__			,			use_cache=UpperCAmelCase__   )

						__SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE						   =				outputs.to_tuple()

						# create hypothetical next token and extent to next_input_ids
						__SCREAMING_SNAKE_CASE						   =				ids_tensor((self.batch_size, 3)			,			config.vocab_size   )
						__SCREAMING_SNAKE_CASE						   =				tf.cast(ids_tensor((self.batch_size, 3)			,			2   )			,			tf.inta   )

						# append to next input_ids and
						__SCREAMING_SNAKE_CASE						   =				tf.concat([input_ids, next_tokens]			,			axis=-1   )
						__SCREAMING_SNAKE_CASE						   =				tf.concat([attention_mask, next_attn_mask]			,			axis=-1   )

						__SCREAMING_SNAKE_CASE						   =				model(UpperCAmelCase__			,			attention_mask=UpperCAmelCase__   )[0]
						__SCREAMING_SNAKE_CASE						   =				model(UpperCAmelCase__			,			attention_mask=UpperCAmelCase__			,			past_key_values=UpperCAmelCase__   )[0]

						self.parent.assertEqual(next_tokens.shape[1]			,			output_from_past.shape[1]   )

						# select random slice
						__SCREAMING_SNAKE_CASE						   =				int(ids_tensor((1,)			,			output_from_past.shape[-1]   )   )
						__SCREAMING_SNAKE_CASE						   =				output_from_no_past[:, -3:, random_slice_idx]
						__SCREAMING_SNAKE_CASE						   =				output_from_past[:, :, random_slice_idx]

						# test that outputs are equal for slice
						tf.debugging.assert_near(UpperCAmelCase__			,			UpperCAmelCase__			,			rtol=1E-3   )




@require_tf
class  UpperCamelCase_	( UpperCamelCase			,  UpperCamelCase			,  unittest.TestCase):

	"""simple docstring"""





	snake_case__				:  str    					=			(TFOPTModel, TFOPTForCausalLM) if is_tf_available() else ()
	snake_case__				:  Optional[Any]    					=			(TFOPTForCausalLM,) if is_tf_available() else ()
	snake_case__				:  Tuple    					=			(
	    {"feature-extraction": TFOPTModel, "text-generation": TFOPTForCausalLM} if is_tf_available() else {}
	)
	snake_case__				:  Any    					=			False
	snake_case__				:  Union[str, Any]    					=			False
	snake_case__				:  List[str]    					=			False
	snake_case__				:  Tuple    					=			10




	def   UpperCAmelCase_      ( self			:				Union[str, Any]   )       ->	Dict:
						__SCREAMING_SNAKE_CASE						   =				TFOPTModelTester(self   )
						__SCREAMING_SNAKE_CASE						   =				ConfigTester(self			,			config_class=UpperCAmelCase__   )




	def   UpperCAmelCase_      ( self			:				List[str]   )       ->	List[Any]:
						self.config_tester.run_common_tests()




	def   UpperCAmelCase_      ( self			:				Optional[int]   )       ->	Union[str, Any]:
						__SCREAMING_SNAKE_CASE						   =				self.model_tester.prepare_config_and_inputs_for_common()
						self.model_tester.check_decoder_model_past_large_inputs(*UpperCAmelCase__   )




	def   UpperCAmelCase_      ( self			:				Dict   )       ->	str:
						__SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE						   =				self.model_tester.prepare_config_and_inputs_for_common()

						def _get_word_embedding_weight(UpperCAmelCase__			:				Dict			,			UpperCAmelCase__			:				str   ):
											if hasattr(UpperCAmelCase__			,			"weight"   ):
																return embedding_layer.weight
											else:
																# Here we build the word embeddings weights if not exists.
																# And then we retry to get the attribute once built.
																model.build()
																if hasattr(UpperCAmelCase__			,			"weight"   ):
																					return embedding_layer.weight
																else:
																					return None

						for model_class in self.all_model_classes:
											for size in [config.vocab_size - 1_0, config.vocab_size + 1_0]:
																# build the embeddings
																__SCREAMING_SNAKE_CASE						   =				model_class(config=UpperCAmelCase__   )
																__SCREAMING_SNAKE_CASE						   =				_get_word_embedding_weight(UpperCAmelCase__			,			model.get_input_embeddings()   )
																__SCREAMING_SNAKE_CASE						   =				_get_word_embedding_weight(UpperCAmelCase__			,			model.get_output_embeddings()   )

																# reshape the embeddings
																model.resize_token_embeddings(UpperCAmelCase__   )
																__SCREAMING_SNAKE_CASE						   =				_get_word_embedding_weight(UpperCAmelCase__			,			model.get_input_embeddings()   )
																__SCREAMING_SNAKE_CASE						   =				_get_word_embedding_weight(UpperCAmelCase__			,			model.get_output_embeddings()   )

																# check that the resized embeddings size matches the desired size.
																__SCREAMING_SNAKE_CASE						   =				size if size is not None else config.vocab_size

																self.assertEqual(new_input_embeddings.shape[0]			,			UpperCAmelCase__   )

																# check that weights remain the same after resizing
																__SCREAMING_SNAKE_CASE						   =				True
																for pa, pa in zip(old_input_embeddings.value()			,			new_input_embeddings.value()   ):
																					if tf.math.reduce_sum(tf.math.abs(pa - pa   )   ) > 0:
																										__SCREAMING_SNAKE_CASE						   =				False
																self.assertTrue(UpperCAmelCase__   )

																if old_output_embeddings is not None and new_output_embeddings is not None:
																					self.assertEqual(new_output_embeddings.shape[0]			,			UpperCAmelCase__   )

																					__SCREAMING_SNAKE_CASE						   =				True
																					for pa, pa in zip(old_output_embeddings.value()			,			new_output_embeddings.value()   ):
																										if tf.math.reduce_sum(tf.math.abs(pa - pa   )   ) > 0:
																															__SCREAMING_SNAKE_CASE						   =				False
																					self.assertTrue(UpperCAmelCase__   )




def    UpperCAmelCase__       (lowerCAmelCase_   ):




					'''simple docstring'''


					return tf.constant(lowerCAmelCase_  ,						dtype=tf.intaa   )




@require_tf
class  UpperCamelCase_	( unittest.TestCase):

	"""simple docstring"""





	snake_case__				:  int    					=			99




	def   UpperCAmelCase_      ( self			:				Optional[Any]   )       ->	Optional[int]:
						__SCREAMING_SNAKE_CASE						   =				tf.ones((4, 1)			,			dtype=tf.intaa   ) * 2
						__SCREAMING_SNAKE_CASE						   =				tf.concat([ids_tensor((4, 6)			,			self.vocab_size - 3   ) + 3, eos_column_vector]			,			axis=1   )
						__SCREAMING_SNAKE_CASE						   =				input_ids.shape[0]
						__SCREAMING_SNAKE_CASE						   =				OPTConfig(
						    vocab_size=self.vocab_size			,			hidden_size=2_4			,			num_hidden_layers=2			,			num_attention_heads=2			,			ffn_dim=3_2			,			max_position_embeddings=4_8			,			eos_token_id=2			,			pad_token_id=1			,			bos_token_id=0			,			)
						return config, input_ids, batch_size




@require_sentencepiece
@require_tf
class  UpperCamelCase_	( unittest.TestCase):

	"""simple docstring"""





	@slow
	def   UpperCAmelCase_      ( self			:				List[Any]   )       ->	List[Any]:
						__SCREAMING_SNAKE_CASE						   =				TFOPTModel.from_pretrained("facebook/opt-350m"   )
						__SCREAMING_SNAKE_CASE						   =				_long_tensor([[0, 3_1_4_1_4, 2_3_2, 3_2_8, 7_4_0, 1_1_4_0, 1_2_6_9_5, 6_9, 4_6_0_7_8, 1_5_8_8, 2]]   )
						__SCREAMING_SNAKE_CASE						   =				tf.not_equal(UpperCAmelCase__			,			model.config.pad_token_id   )
						with tf.GradientTape():
											__SCREAMING_SNAKE_CASE						   =				model(input_ids=UpperCAmelCase__			,			attention_mask=UpperCAmelCase__   ).last_hidden_state
						__SCREAMING_SNAKE_CASE						   =				(1, 1_1, 5_1_2)
						self.assertEqual(output.shape			,			UpperCAmelCase__   )
						__SCREAMING_SNAKE_CASE						   =				tf.constant(
						    [[-0.2_873, -1.9_218, -0.3_033], [-1.2_710, -0.1_338, -0.1_902], [0.4_095, 0.1_214, -1.3_121]]   )
						self.assertTrue(np.allclose(output[:, :3, :3]			,			UpperCAmelCase__			,			atol=4E-3   )   )

						__SCREAMING_SNAKE_CASE						   =				tf.function(UpperCAmelCase__			,			jit_compile=UpperCAmelCase__   )
						__SCREAMING_SNAKE_CASE						   =				xla_generate(UpperCAmelCase__			,			UpperCAmelCase__   )[0]
						self.assertTrue(np.allclose(output[:, :3, :3]			,			UpperCAmelCase__			,			atol=4E-2   )   )




@require_tf
@slow
class  UpperCamelCase_	( unittest.TestCase):

	"""simple docstring"""





	def   UpperCAmelCase_      ( self			:				Optional[Any]   )       ->	Optional[Any]:
						super().setUp()
						__SCREAMING_SNAKE_CASE						   =				"facebook/opt-350m"




	def   UpperCAmelCase_      ( self			:				Tuple   )       ->	Union[str, Any]:
						__SCREAMING_SNAKE_CASE						   =				TFOPTForCausalLM.from_pretrained(self.path_model   )
						__SCREAMING_SNAKE_CASE						   =				GPTaTokenizer.from_pretrained(self.path_model   )

						__SCREAMING_SNAKE_CASE						   =				[
						    "Today is a beautiful day and I want to",
						    "In the city of",
						    "Paris is the capital of France and",
						    "Computers and mobile phones have taken",
						]
						# verify that prompt without BOS token is identical to Metaseq -> add_special_tokens=False
						__SCREAMING_SNAKE_CASE						   =				tokenizer(UpperCAmelCase__			,			return_tensors="tf"			,			padding=UpperCAmelCase__			,			add_special_tokens=UpperCAmelCase__   )
						__SCREAMING_SNAKE_CASE						   =				tf.math.reduce_mean(model(inputs.input_ids			,			attention_mask=inputs.attention_mask   )[0]			,			axis=-1   )
						__SCREAMING_SNAKE_CASE						   =				tf.constant(
						    [
						        [1.3_851, -13.8_923, -10.5_229, -10.7_533, -0.2_309, -10.2_384, -0.5_365, -9.0_947, -5.1_670],
						        [-4.7_073, -10.6_276, -3.9_415, -21.5_242, -0.2_822, -0.2_822, -0.2_822, -0.2_822, -0.2_822],
						        [0.6_247, -3.4_229, -8.9_179, -1.4_297, -14.1_650, 1.4_146, -9.0_218, -0.2_703, -0.2_703],
						        [6.4_783, -1.9_913, -10.7_926, -2.3_336, 1.5_092, -0.9_974, -6.8_213, 1.3_477, 1.3_477],
						    ]   )
						self.assertTrue(np.allclose(UpperCAmelCase__			,			UpperCAmelCase__			,			atol=1E-4   )   )

						__SCREAMING_SNAKE_CASE						   =				tf.function(UpperCAmelCase__			,			jit_compile=UpperCAmelCase__   )
						__SCREAMING_SNAKE_CASE						   =				tf.math.reduce_mean(xla_generate(inputs.input_ids			,			attention_mask=inputs.attention_mask   )[0]			,			axis=-1   )
						self.assertTrue(np.allclose(UpperCAmelCase__			,			UpperCAmelCase__			,			atol=1E-4   )   )




@require_tf
@slow
class  UpperCamelCase_	( unittest.TestCase):

	"""simple docstring"""





	@property
	def   UpperCAmelCase_      ( self			:				Dict   )       ->	str:
						return [
						    "Today is a beautiful day and I want",
						    "In the city of",
						    "Paris is the capital of France and",
						    "Computers and mobile phones have taken",
						]




	def   UpperCAmelCase_      ( self			:				Union[str, Any]   )       ->	Any:
						__SCREAMING_SNAKE_CASE						   =				"facebook/opt-125m"

						__SCREAMING_SNAKE_CASE						   =				[
						    "Today is a beautiful day and I want to",
						    "In the city of New York, the city",
						    "Paris is the capital of France and the capital",
						    "Computers and mobile phones have taken over the",
						]

						__SCREAMING_SNAKE_CASE						   =				[]
						__SCREAMING_SNAKE_CASE						   =				GPTaTokenizer.from_pretrained(UpperCAmelCase__   )
						__SCREAMING_SNAKE_CASE						   =				TFOPTForCausalLM.from_pretrained(UpperCAmelCase__   )

						for prompt in self.prompts:
											__SCREAMING_SNAKE_CASE						   =				tokenizer(UpperCAmelCase__			,			return_tensors="tf"   ).input_ids

											__SCREAMING_SNAKE_CASE						   =				model.generate(UpperCAmelCase__			,			max_length=1_0   )

											__SCREAMING_SNAKE_CASE						   =				tokenizer.batch_decode(UpperCAmelCase__			,			skip_special_tokens=UpperCAmelCase__   )
											predicted_outputs += generated_string

						self.assertListEqual(UpperCAmelCase__			,			UpperCAmelCase__   )




	def   UpperCAmelCase_      ( self			:				int   )       ->	int:
						__SCREAMING_SNAKE_CASE						   =				"facebook/opt-350m"

						__SCREAMING_SNAKE_CASE						   =				GPTaTokenizer.from_pretrained(UpperCAmelCase__   )
						__SCREAMING_SNAKE_CASE						   =				TFOPTForCausalLM.from_pretrained(UpperCAmelCase__   )

						__SCREAMING_SNAKE_CASE						   =				"left"

						# use different length sentences to test batching
						__SCREAMING_SNAKE_CASE						   =				[
						    "Hello, my dog is a little",
						    "Today, I",
						]

						__SCREAMING_SNAKE_CASE						   =				tokenizer(UpperCAmelCase__			,			return_tensors="tf"			,			padding=UpperCAmelCase__   )
						__SCREAMING_SNAKE_CASE						   =				inputs["input_ids"]

						__SCREAMING_SNAKE_CASE						   =				model.generate(input_ids=UpperCAmelCase__			,			attention_mask=inputs["attention_mask"]   )

						__SCREAMING_SNAKE_CASE						   =				tokenizer(sentences[0]			,			return_tensors="tf"   ).input_ids
						__SCREAMING_SNAKE_CASE						   =				model.generate(input_ids=UpperCAmelCase__   )

						__SCREAMING_SNAKE_CASE						   =				inputs_non_padded.shape[-1] - tf.math.reduce_sum(
						    tf.cast(inputs["attention_mask"][-1]			,			tf.intaa   )   )
						__SCREAMING_SNAKE_CASE						   =				tokenizer(sentences[1]			,			return_tensors="tf"   ).input_ids
						__SCREAMING_SNAKE_CASE						   =				model.generate(input_ids=UpperCAmelCase__			,			max_length=model.config.max_length - num_paddings   )

						__SCREAMING_SNAKE_CASE						   =				tokenizer.batch_decode(UpperCAmelCase__			,			skip_special_tokens=UpperCAmelCase__   )
						__SCREAMING_SNAKE_CASE						   =				tokenizer.decode(output_non_padded[0]			,			skip_special_tokens=UpperCAmelCase__   )
						__SCREAMING_SNAKE_CASE						   =				tokenizer.decode(output_padded[0]			,			skip_special_tokens=UpperCAmelCase__   )

						__SCREAMING_SNAKE_CASE						   =				[
						    "Hello, my dog is a little bit of a dork.\nI'm a little bit",
						    "Today, I was in the middle of a conversation with a friend about the",
						]
						self.assertListEqual(UpperCAmelCase__			,			UpperCAmelCase__   )
						self.assertListEqual(UpperCAmelCase__			,			[non_padded_sentence, padded_sentence]   )




	def   UpperCAmelCase_      ( self			:				Any   )       ->	Any:
						__SCREAMING_SNAKE_CASE						   =				"facebook/opt-350m"

						__SCREAMING_SNAKE_CASE						   =				[
						    "Today is a beautiful day and I want to",
						    "In the city of San Francisco, the city",
						    "Paris is the capital of France and the capital",
						    "Computers and mobile phones have taken over the",
						]

						__SCREAMING_SNAKE_CASE						   =				[]
						__SCREAMING_SNAKE_CASE						   =				GPTaTokenizer.from_pretrained(UpperCAmelCase__   )
						__SCREAMING_SNAKE_CASE						   =				TFOPTForCausalLM.from_pretrained(UpperCAmelCase__   )

						for prompt in self.prompts:
											__SCREAMING_SNAKE_CASE						   =				tokenizer(UpperCAmelCase__			,			return_tensors="tf"   ).input_ids

											__SCREAMING_SNAKE_CASE						   =				model.generate(UpperCAmelCase__			,			max_length=1_0   )

											__SCREAMING_SNAKE_CASE						   =				tokenizer.batch_decode(UpperCAmelCase__			,			skip_special_tokens=UpperCAmelCase__   )
											predicted_outputs += generated_string

						self.assertListEqual(UpperCAmelCase__			,			UpperCAmelCase__   )




"""simple docstring"""







from __future__ import annotations

import pandas as pd




def    UpperCAmelCase__       (lowerCAmelCase_  ,						lowerCAmelCase_  ,						lowerCAmelCase_   ):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE						   =				[0] * no_of_processes
					__SCREAMING_SNAKE_CASE						   =				[0] * no_of_processes
					# Copy the burst time into remaining_time[]
					for i in range(lowerCAmelCase_   ):
										__SCREAMING_SNAKE_CASE						   =				burst_time[i]

					__SCREAMING_SNAKE_CASE						   =				0
					__SCREAMING_SNAKE_CASE						   =				0
					__SCREAMING_SNAKE_CASE						   =				9_9999_9999
					__SCREAMING_SNAKE_CASE						   =				0
					__SCREAMING_SNAKE_CASE						   =				False

					# Process until all processes are completed
					while complete != no_of_processes:
										for j in range(lowerCAmelCase_   ):
															if arrival_time[j] <= increment_time and remaining_time[j] > 0:
																				if remaining_time[j] < minm:
																									__SCREAMING_SNAKE_CASE						   =				remaining_time[j]
																									__SCREAMING_SNAKE_CASE						   =				j
																									__SCREAMING_SNAKE_CASE						   =				True

										if not check:
															increment_time += 1
															continue
										remaining_time[short] -= 1

										__SCREAMING_SNAKE_CASE						   =				remaining_time[short]
										if minm == 0:
															__SCREAMING_SNAKE_CASE						   =				9_9999_9999

										if remaining_time[short] == 0:
															complete += 1
															__SCREAMING_SNAKE_CASE						   =				False

															# Find finish time of current process
															__SCREAMING_SNAKE_CASE						   =				increment_time + 1

															# Calculate waiting time
															__SCREAMING_SNAKE_CASE						   =				finish_time - arrival_time[short]
															__SCREAMING_SNAKE_CASE						   =				finar - burst_time[short]

															if waiting_time[short] < 0:
																				__SCREAMING_SNAKE_CASE						   =				0

        # Increment time
										increment_time += 1
					return waiting_time




def    UpperCAmelCase__       (lowerCAmelCase_  ,						lowerCAmelCase_  ,						lowerCAmelCase_   ):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE						   =				[0] * no_of_processes
					for i in range(lowerCAmelCase_   ):
										__SCREAMING_SNAKE_CASE						   =				burst_time[i] + waiting_time[i]
					return turn_around_time




def    UpperCAmelCase__       (lowerCAmelCase_  ,						lowerCAmelCase_  ,						lowerCAmelCase_   ):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE						   =				0
					__SCREAMING_SNAKE_CASE						   =				0
					for i in range(lowerCAmelCase_   ):
										__SCREAMING_SNAKE_CASE						   =				total_waiting_time + waiting_time[i]
										__SCREAMING_SNAKE_CASE						   =				total_turn_around_time + turn_around_time[i]
					print(f"""Average waiting time = {total_waiting_time / no_of_processes:.5f}"""   )
					print("Average turn around time ="  ,						total_turn_around_time / no_of_processes   )


if __name__ == "__main__":
		print('''Enter how many process you want to analyze''')
		a__				:							Optional[Any]						=     int(input())
		a__				:							Optional[int]						=     [0] * no_of_processes
		a__				:							int						=     [0] * no_of_processes
		a__				:							List[Any]						=     list(range(1, no_of_processes + 1))

		for i in range(no_of_processes):
				print('''Enter the arrival time and burst time for process:--''' + str(i + 1))
				a__			,     a__				:							Tuple						=     map(int, input().split())

		a__				:							int						=     calculate_waitingtime(arrival_time, burst_time, no_of_processes)

		a__				:							Dict						=     burst_time
		a__				:							Any						=     no_of_processes
		a__				:							Optional[int]						=     waiting_time
		a__				:							Union[str, Any]						=     calculate_turnaroundtime(bt, n, wt)

		calculate_average_times(waiting_time, turn_around_time, no_of_processes)

		a__				:							str						=     pd.DataFrame(
		    list(zip(processes, burst_time, arrival_time, waiting_time, turn_around_time)),
		    columns=[
		        '''Process''',
		        '''BurstTime''',
		        '''ArrivalTime''',
		        '''WaitingTime''',
		        '''TurnAroundTime''',
		    ],
		)

		# Printing the dataFrame
		pd.set_option('''display.max_rows''', fcfs.shape[0] + 1)
		print(fcfs)
