


'''simple docstring'''
from typing import Callable, Dict, Optional, Tuple

import torch
from torch import nn
from torch.distributions import (
    AffineTransform,
    Distribution,
    Independent,
    NegativeBinomial,
    Normal,
    StudentT,
    TransformedDistribution,
)




class      lowerCamelCase_  (      __a ):






      def __init__(   self							:       Tuple		,		_A							:       Distribution		,		_A							:       int=None		,		_A							:       Tuple=None		,		_A							:       Any=0					):


          '''simple docstring'''


          UpperCAmelCase__     :						List[str]						=							1.0 if scale is None else scale
          UpperCAmelCase__     :						List[str]						=							0.0 if loc is None else loc

          super().__init__(_A		,		[AffineTransform(loc=self.loc		,		scale=self.scale		,		event_dim=_A					)]					)






      @property
      def lowercase_				(   self							:       Tuple					):


          '''simple docstring'''


          return self.base_dist.mean * self.scale + self.loc






      @property
      def lowercase_				(   self							:       Optional[int]					):


          '''simple docstring'''


          return self.base_dist.variance * self.scale**2






      @property
      def lowercase_				(   self							:       int					):


          '''simple docstring'''


          return self.variance.sqrt()




class      lowerCamelCase_  (      nn.Module ):






      def __init__(   self							:       Tuple		,		_A							:       int		,		_A							:       Dict[str, int]		,		_A							:       Callable[..., Tuple[torch.Tensor]]		,		**_A							:       Tuple					):


          '''simple docstring'''


          super().__init__(**_A					)
          UpperCAmelCase__     :						Optional[Any]						=							args_dim
          UpperCAmelCase__     :						Optional[int]						=							nn.ModuleList([nn.Linear(_A		,		_A					) for dim in args_dim.values()]					)
          UpperCAmelCase__     :						str						=							domain_map






      def lowercase_				(   self							:       Union[str, Any]		,		_A							:       torch.Tensor					):


          '''simple docstring'''


          UpperCAmelCase__     :						Union[str, Any]						=							[proj(_A					) for proj in self.proj]

          return self.domain_map(*_A					)




class      lowerCamelCase_  (      nn.Module ):






      def __init__(   self							:       Optional[Any]		,		_A							:       Union[str, Any]					):


          '''simple docstring'''


          super().__init__()
          UpperCAmelCase__     :						Optional[int]						=							function






      def lowercase_				(   self							:       Tuple		,		_A							:       Optional[Any]		,		*_A							:       List[str]					):


          '''simple docstring'''


          return self.function(_A		,		*_A					)




class      lowerCamelCase_  :
      lowerCAmelCase__							=	42
      lowerCAmelCase__							=	42
      lowerCAmelCase__							=	42






      def __init__(   self							:       List[str]		,		_A							:       int = 1					):


          '''simple docstring'''


          UpperCAmelCase__     :						Optional[Any]						=							dim
          UpperCAmelCase__     :						Tuple						=							{k: dim * self.args_dim[k] for k in self.args_dim}






      def lowercase_				(   self							:       Union[str, Any]		,		_A							:       str					):


          '''simple docstring'''


          if self.dim == 1:
              return self.distribution_class(*_A					)
          else:
              return Independent(self.distribution_class(*_A					)		,		1					)






      def lowercase_				(   self							:       Dict		,		_A							:       str		,		_A							:       Optional[torch.Tensor] = None		,		_A							:       Optional[torch.Tensor] = None		,		):


          '''simple docstring'''


          UpperCAmelCase__     :						List[Any]						=							self._base_distribution(_A					)
          if loc is None and scale is None:
              return distr
          else:
              return AffineTransformed(_A		,		loc=_A		,		scale=_A		,		event_dim=self.event_dim					)






      @property
      def lowercase_				(   self							:       List[str]					):


          '''simple docstring'''


          return () if self.dim == 1 else (self.dim,)






      @property
      def lowercase_				(   self							:       Optional[Any]					):


          '''simple docstring'''


          return len(self.event_shape					)






      @property
      def lowercase_				(   self							:       int					):


          '''simple docstring'''


          return 0.0






      def lowercase_				(   self							:       Union[str, Any]		,		_A							:       int					):


          '''simple docstring'''


          return ParameterProjection(
              in_features=_A		,		args_dim=self.args_dim		,		domain_map=LambdaLayer(self.domain_map					)		,		)






      def lowercase_				(   self							:       str		,		*_A							:       torch.Tensor					):


          '''simple docstring'''


          raise NotImplementedError()






      @staticmethod
      def lowercase_				(   _A							:       torch.Tensor					):


          '''simple docstring'''


          return (x + torch.sqrt(torch.square(_A					) + 4.0					)) / 2.0




class      lowerCamelCase_  (      __a ):
      lowerCAmelCase__							=	{"df": 1, "loc": 1, "scale": 1}
      lowerCAmelCase__							=	StudentT






      @classmethod
      def lowercase_				(   cls							:       Union[str, Any]		,		_A							:       torch.Tensor		,		_A							:       torch.Tensor		,		_A							:       torch.Tensor					):


          '''simple docstring'''


          UpperCAmelCase__     :						int						=							cls.squareplus(_A					).clamp_min(torch.finfo(scale.dtype					).eps					)
          UpperCAmelCase__     :						Dict						=							2.0 + cls.squareplus(_A					)
          return df.squeeze(-1					), loc.squeeze(-1					), scale.squeeze(-1					)




class      lowerCamelCase_  (      __a ):
      lowerCAmelCase__							=	{"loc": 1, "scale": 1}
      lowerCAmelCase__							=	Normal






      @classmethod
      def lowercase_				(   cls							:       List[str]		,		_A							:       torch.Tensor		,		_A							:       torch.Tensor					):


          '''simple docstring'''


          UpperCAmelCase__     :						List[Any]						=							cls.squareplus(_A					).clamp_min(torch.finfo(scale.dtype					).eps					)
          return loc.squeeze(-1					), scale.squeeze(-1					)




class      lowerCamelCase_  (      __a ):
      lowerCAmelCase__							=	{"total_count": 1, "logits": 1}
      lowerCAmelCase__							=	NegativeBinomial






      @classmethod
      def lowercase_				(   cls							:       List[Any]		,		_A							:       torch.Tensor		,		_A							:       torch.Tensor					):


          '''simple docstring'''


          UpperCAmelCase__     :						Optional[Any]						=							cls.squareplus(_A					)
          return total_count.squeeze(-1					), logits.squeeze(-1					)






      def lowercase_				(   self							:       Optional[int]		,		_A							:       Optional[int]					):


          '''simple docstring'''


          UpperCAmelCase__     :						List[Any]						=							distr_args
          if self.dim == 1:
              return self.distribution_class(total_count=_A		,		logits=_A					)
          else:
              return Independent(self.distribution_class(total_count=_A		,		logits=_A					)		,		1					)






      def lowercase_				(   self							:       Union[str, Any]		,		_A							:       Optional[Any]		,		_A							:       Optional[torch.Tensor] = None		,		_A							:       Optional[torch.Tensor] = None					):


          '''simple docstring'''


          UpperCAmelCase__     :						Any						=							distr_args

          if scale is not None:
              # See scaling property of Gamma.
              logits += scale.log()

          return self._base_distribution((total_count, logits)					)




import qiskit


def     lowercase	(    a     , a ):



		'''simple docstring'''




		SCREAMING_SNAKE_CASE_				:int				     =						qiskit.Aer.get_backend("aer_simulator" )

		# Create a Quantum Circuit acting on the q register
		SCREAMING_SNAKE_CASE_				:Union[str, Any]				     =						qiskit.QuantumCircuit(a     , a )

		# Apply X (NOT) Gate to Qubits 0 & 1
		circuit.x(0 )
		circuit.x(1 )

		# Map the quantum measurement to the classical bits
		circuit.measure([0, 1]     , [0, 1] )

		# Execute the circuit on the qasm simulator
		SCREAMING_SNAKE_CASE_				:Any				     =						qiskit.execute(a     , a     , shots=1000 )

		# Return the histogram data of the results of the experiment.
		return job.result().get_counts(a )


if __name__ == "__main__":
		SCREAMING_SNAKE_CASE__     					=			single_qubit_measure(2, 2)
		print(F'''Total count for various states are: {counts}''')






