"""simple docstring"""







from typing import Dict, Optional, Tuple

import torch




def 						_lowercase				(  _SCREAMING_SNAKE_CASE				:				torch.Tensor						)    ->     torch.Tensor:







     '''simple docstring'''


     __A					:					List[str]								=		boundaries[1] - boundaries[0]
     __A					:					int								=		boundaries + step / 2
     __A					:					Union[str, Any]								=		torch.cat([bin_centers, (bin_centers[-1] + step).unsqueeze(-1						)]  ,       dim=0						)
     return bin_centers




def 						_lowercase				(  _SCREAMING_SNAKE_CASE				:				torch.Tensor  ,       _SCREAMING_SNAKE_CASE				:				torch.Tensor  ,       )    ->     Tuple[torch.Tensor, torch.Tensor]:







     '''simple docstring'''


     __A					:					str								=		_calculate_bin_centers(_SCREAMING_SNAKE_CASE						)
     return (
         torch.sum(aligned_distance_error_probs * bin_centers  ,       dim=-1						),
         bin_centers[-1],
     )




def 						_lowercase				(  _SCREAMING_SNAKE_CASE				:				torch.Tensor  ,       _SCREAMING_SNAKE_CASE				:				int = 31  ,       _SCREAMING_SNAKE_CASE				:				int = 64  ,       **_SCREAMING_SNAKE_CASE				:				Optional[Any]  ,       )    ->     Dict[str, torch.Tensor]:







     '''simple docstring'''


     __A					:					int								=		torch.linspace(0  ,       _SCREAMING_SNAKE_CASE  ,       steps=(no_bins - 1)  ,       device=logits.device						)

     __A					:					Any								=		torch.nn.functional.softmax(_SCREAMING_SNAKE_CASE  ,       dim=-1						)
     __A						,		__A					:					Tuple								=		_calculate_expected_aligned_error(
         alignment_confidence_breaks=_SCREAMING_SNAKE_CASE  ,       aligned_distance_error_probs=_SCREAMING_SNAKE_CASE  ,       )

     return {
         "aligned_confidence_probs": aligned_confidence_probs,
         "predicted_aligned_error": predicted_aligned_error,
         "max_predicted_aligned_error": max_predicted_aligned_error,
     }




def 						_lowercase				(  _SCREAMING_SNAKE_CASE				:				torch.Tensor  ,       _SCREAMING_SNAKE_CASE				:				Optional[torch.Tensor] = None  ,       _SCREAMING_SNAKE_CASE				:				int = 31  ,       _SCREAMING_SNAKE_CASE				:				int = 64  ,       _SCREAMING_SNAKE_CASE				:				float = 1E-8  ,       **_SCREAMING_SNAKE_CASE				:				Union[str, Any]  ,       )    ->     torch.Tensor:







     '''simple docstring'''


     if residue_weights is None:
          __A					:					Optional[int]								=		logits.new_ones(logits.shape[-2]						)

     __A					:					List[str]								=		torch.linspace(0  ,       _SCREAMING_SNAKE_CASE  ,       steps=(no_bins - 1)  ,       device=logits.device						)

     __A					:					Tuple								=		_calculate_bin_centers(_SCREAMING_SNAKE_CASE						)
     torch.sum(_SCREAMING_SNAKE_CASE						)
     __A					:					int								=		logits.shape[-2]
     __A					:					str								=		max(_SCREAMING_SNAKE_CASE  ,       19						)

     __A					:					Tuple								=		1.24 * (clipped_n - 15) ** (1.0 / 3) - 1.8

     __A					:					Tuple								=		torch.nn.functional.softmax(_SCREAMING_SNAKE_CASE  ,       dim=-1						)

     __A					:					List[str]								=		1.0 / (1 + (bin_centers**2) / (da**2))
     __A					:					int								=		torch.sum(probs * tm_per_bin  ,       dim=-1						)

     __A					:					Any								=		residue_weights / (eps + residue_weights.sum())
     __A					:					List[Any]								=		torch.sum(predicted_tm_term * normed_residue_mask  ,       dim=-1						)

     __A					:					int								=		per_alignment * residue_weights

     __A					:					Optional[int]								=		(weighted == torch.max(_SCREAMING_SNAKE_CASE						)).nonzero()[0]
     return per_alignment[tuple(_SCREAMING_SNAKE_CASE						)]




"""simple docstring"""







import importlib
import sys
from argparse import REMAINDER, ArgumentParser
from pathlib import Path

import torch_xla.distributed.xla_multiprocessing as xmp




def 						_lowercase				(  )    ->     List[str]:







     '''simple docstring'''


     __A					:					int								=		ArgumentParser(
         description=(
             'PyTorch TPU distributed training launch helper utility that will spawn up multiple distributed processes'
         )						)

     # Optional arguments for the launch helper
     parser.add_argument('--num_cores'  ,       type=_SCREAMING_SNAKE_CASE  ,       default=1  ,       help='Number of TPU cores to use (1 or 8).'						)

     # positional
     parser.add_argument(
         'training_script'  ,       type=_SCREAMING_SNAKE_CASE  ,       help=(
             'The full path to the single TPU training '
             'program/script to be launched in parallel, '
             'followed by all the arguments for the '
             'training script'
         )  ,       )

     # rest from the training program
     parser.add_argument('training_script_args'  ,       nargs=_SCREAMING_SNAKE_CASE						)

     return parser.parse_args()




def 						_lowercase				(  )    ->     List[str]:







     '''simple docstring'''


     __A					:					List[str]								=		parse_args()

     # Import training_script as a module.
     __A					:					Dict								=		Path(args.training_script						)
     sys.path.append(str(script_fpath.parent.resolve()						)						)
     __A					:					List[Any]								=		script_fpath.stem
     __A					:					Optional[Any]								=		importlib.import_module(_SCREAMING_SNAKE_CASE						)

     # Patch sys.argv
     __A					:					Union[str, Any]								=		[args.training_script] + args.training_script_args + ['--tpu_num_cores', str(args.num_cores						)]

     xmp.spawn(mod._mp_fn  ,       args=()  ,       nprocs=args.num_cores						)


if __name__ == "__main__":
       main()



