



import warnings
from dataclasses import dataclass, field
from typing import Optional, Tuple

from .training_args import TrainingArguments
from .utils import cached_property, is_tf_available, logging, requires_backends


__A       					=		logging.get_logger(__name__)

if is_tf_available():
						import tensorflow as tf






@dataclass
class 	lowercase		(				lowerCAmelCase_):






	"""simple docstring"""


	a__   :      List[Any]	     =							'tf'
	a__   :      Optional[str]	     =							field(
	    default=lowerCAmelCase_				,					metadata={"help": "Name of TPU"}				,					)

	a__   :      Optional[str]	     =							field(
	    default=lowerCAmelCase_				,					metadata={"help": "Zone of TPU"}				,					)

	a__   :      Optional[str]	     =							field(
	    default=lowerCAmelCase_				,					metadata={"help": "Name of Cloud TPU-enabled project"}				,					)

	a__   :      float	     =							field(
	    default=1.0				,					metadata={"help": "Power for the Polynomial decay LR scheduler."}				,					)

	a__   :      bool	     =							field(default=lowerCAmelCase_				,					metadata={"help": "Whether to activate the XLA compilation or not"})




	@cached_property
	def 						_SCREAMING_SNAKE_CASE	(			self			:		List[str]  )    ->				List[Any]:
							requires_backends(self		,						["""tf"""]  )
							logger.info("""Tensorflow: setting up strategy"""  )

							UpperCAmelCase_=     tf.config.list_physical_devices("""GPU"""  )

							# Set to float16 at first
							if self.fpaa:
													tf.keras.mixed_precision.set_global_policy("""mixed_float16"""  )

							if self.no_cuda:
													UpperCAmelCase_=     tf.distribute.OneDeviceStrategy(device="""/cpu:0"""  )
							else:
													try:
																			if self.tpu_name:
																									UpperCAmelCase_=     tf.distribute.cluster_resolver.TPUClusterResolver(
																									    self.tpu_name		,						zone=self.tpu_zone		,						project=self.gcp_project  )
																			else:
																									UpperCAmelCase_=     tf.distribute.cluster_resolver.TPUClusterResolver()
													except ValueError:
																			if self.tpu_name:
																									raise RuntimeError(F"""Couldn\'t connect to TPU {self.tpu_name}!"""  )
																			else:
																									UpperCAmelCase_=     None

													if tpu:
																			# Set to bfloat16 in case of TPU
																			if self.fpaa:
																									tf.keras.mixed_precision.set_global_policy("""mixed_bfloat16"""  )

																			tf.config.experimental_connect_to_cluster(lowerCamelCase_  )
																			tf.tpu.experimental.initialize_tpu_system(lowerCamelCase_  )

																			UpperCAmelCase_=     tf.distribute.TPUStrategy(lowerCamelCase_  )

													elif len(lowerCamelCase_  ) == 0:
																			UpperCAmelCase_=     tf.distribute.OneDeviceStrategy(device="""/cpu:0"""  )
													elif len(lowerCamelCase_  ) == 1:
																			UpperCAmelCase_=     tf.distribute.OneDeviceStrategy(device="""/gpu:0"""  )
													elif len(lowerCamelCase_  ) > 1:
																			# If you only want to use a specific subset of GPUs use `CUDA_VISIBLE_DEVICES=0`
																			UpperCAmelCase_=     tf.distribute.MirroredStrategy()
													else:
																			raise ValueError("""Cannot find the proper strategy, please check your environment properties."""  )

							return strategy




	@property
	def 						_SCREAMING_SNAKE_CASE	(			self			:		int  )    ->				str:
							requires_backends(self		,						["""tf"""]  )
							return self._setup_strategy




	@property
	def 						_SCREAMING_SNAKE_CASE	(			self			:		List[Any]  )    ->				Optional[Any]:
							requires_backends(self		,						["""tf"""]  )
							return self._setup_strategy.num_replicas_in_sync




	@property
	def 						_SCREAMING_SNAKE_CASE	(			self			:		Dict  )    ->				Any:
							return False  # TF Logging is handled by Keras not the Trainer




	@property
	def 						_SCREAMING_SNAKE_CASE	(			self			:		int  )    ->				str:

							if self.per_gpu_train_batch_size:
													logger.warning(
													    """Using deprecated `--per_gpu_train_batch_size` argument which will be removed in a future """
													    """version. Using `--per_device_train_batch_size` is preferred."""  )
							UpperCAmelCase_=     self.per_gpu_train_batch_size or self.per_device_train_batch_size
							return per_device_batch_size * self.n_replicas




	@property
	def 						_SCREAMING_SNAKE_CASE	(			self			:		Tuple  )    ->				Tuple:

							if self.per_gpu_eval_batch_size:
													logger.warning(
													    """Using deprecated `--per_gpu_eval_batch_size` argument which will be removed in a future """
													    """version. Using `--per_device_eval_batch_size` is preferred."""  )
							UpperCAmelCase_=     self.per_gpu_eval_batch_size or self.per_device_eval_batch_size
							return per_device_batch_size * self.n_replicas




	@property
	def 						_SCREAMING_SNAKE_CASE	(			self			:		str  )    ->				int:
							requires_backends(self		,						["""tf"""]  )
							warnings.warn(
							    """The n_gpu argument is deprecated and will be removed in a future version, use n_replicas instead."""		,						lowerCamelCase_		,						)
							return self._setup_strategy.num_replicas_in_sync









from math import radians as angle_to_radians
from math import sin

# Acceleration Constant on Earth (unit m/s^2)
__A       					=		9.8_0_6_6_5



def  __a  (					lowerCAmelCase_     :      float    ,lowerCAmelCase_     :      float       )   ->				None:






						'''simple docstring'''



						if not isinstance(lowerCAmelCase_    ,(int, float)       ):
												raise TypeError("""Invalid velocity. Should be a positive number."""       )

						if not isinstance(lowerCAmelCase_    ,(int, float)       ):
												raise TypeError("""Invalid angle. Range is 1-90 degrees."""       )

						# Ensure valid angle
						if angle > 90 or angle < 1:
												raise ValueError("""Invalid angle. Range is 1-90 degrees."""       )

						# Ensure valid velocity
						if init_velocity < 0:
												raise ValueError("""Invalid velocity. Should be a positive number."""       )



def  __a  (					lowerCAmelCase_     :      float    ,lowerCAmelCase_     :      float       )   ->				float:






						'''simple docstring'''



						check_args(lowerCAmelCase_    ,lowerCAmelCase_       )
						UpperCAmelCase_=     angle_to_radians(2 * angle       )
						return round(init_velocity**2 * sin(lowerCAmelCase_       ) / g    ,2       )



def  __a  (					lowerCAmelCase_     :      float    ,lowerCAmelCase_     :      float       )   ->				float:






						'''simple docstring'''



						check_args(lowerCAmelCase_    ,lowerCAmelCase_       )
						UpperCAmelCase_=     angle_to_radians(lowerCAmelCase_       )
						return round(init_velocity**2 * sin(lowerCAmelCase_       ) ** 2 / (2 * g)    ,2       )



def  __a  (					lowerCAmelCase_     :      float    ,lowerCAmelCase_     :      float       )   ->				float:






						'''simple docstring'''



						check_args(lowerCAmelCase_    ,lowerCAmelCase_       )
						UpperCAmelCase_=     angle_to_radians(lowerCAmelCase_       )
						return round(2 * init_velocity * sin(lowerCAmelCase_       ) / g    ,2       )



def  __a  (					)   ->				None:






						'''simple docstring'''



						UpperCAmelCase_,     UpperCAmelCase_=     25, 20
						assert horizontal_distance(lowerCAmelCase_    ,lowerCAmelCase_       ) == 40.97
						assert max_height(lowerCAmelCase_    ,lowerCAmelCase_       ) == 3.73
						assert total_time(lowerCAmelCase_    ,lowerCAmelCase_       ) == 1.74


if __name__ == "__main__":
	from doctest import testmod

	testmod()

	# Get input from user
	__A       					=		float(input('''Initial Velocity: ''').strip())

	# Get input from user
	__A       					=		float(input('''angle: ''').strip())

	# Print results
	print()
	print('''Results: ''')
	print(f'Horizontal Distance: {horizontal_distance(init_vel, angle)!s} [m]')
	print(f'Maximum Height: {max_height(init_vel, angle)!s} [m]')
	print(f'Total Time: {total_time(init_vel, angle)!s} [s]')




