




import math

import qiskit
from qiskit import Aer, ClassicalRegister, QuantumCircuit, QuantumRegister, execute





def      UpperCAmelCase  (						UpperCamelCase__ = 1						,			UpperCamelCase__ = 1   )     ->     qiskit.result.counts.Counts:







				'''simple docstring'''


				if isinstance(UpperCamelCase__						,			UpperCamelCase__   ) or isinstance(UpperCamelCase__						,			UpperCamelCase__   ):
								raise TypeError("""inputs must be integers."""   )
				if (bit_a < 0) or (bit_a < 0):
								raise ValueError("""inputs must be positive."""   )
				if (math.floor(UpperCamelCase__   ) != bit_a) or (math.floor(UpperCamelCase__   ) != bit_a):
								raise ValueError("""inputs must be exact integers."""   )
				if (bit_a > 1) or (bit_a > 1):
								raise ValueError("""inputs must be less or equal to 1."""   )

				# build registers
				__lowerCAmelCase					=  QuantumRegister(2						,			"""qr"""   )
				__lowerCAmelCase					=  ClassicalRegister(2						,			"""cr"""   )

				__lowerCAmelCase					=  QuantumCircuit(UpperCamelCase__						,			UpperCamelCase__   )

				# entanglement the qubits
				quantum_circuit.h(1   )
				quantum_circuit.cx(1						,			0   )

				# send the information
				__lowerCAmelCase					=  str(UpperCamelCase__   ) + str(UpperCamelCase__   )

				if c_information == "11":
								quantum_circuit.x(1   )
								quantum_circuit.z(1   )
				elif c_information == "10":
								quantum_circuit.z(1   )
				elif c_information == "01":
								quantum_circuit.x(1   )
				else:
								quantum_circuit.i(1   )

				# unentangled the circuit
				quantum_circuit.cx(1						,			0   )
				quantum_circuit.h(1   )

				# measure the circuit
				quantum_circuit.measure(UpperCamelCase__						,			UpperCamelCase__   )

				__lowerCAmelCase					=  Aer.get_backend("""aer_simulator"""   )
				__lowerCAmelCase					=  execute(UpperCamelCase__						,			UpperCamelCase__						,			shots=10_00   )

				return job.result().get_counts(UpperCamelCase__   )


if __name__ == "__main__":
	print(f"""Counts for classical state send: {superdense_coding(1,1)}""")












import argparse
import os

import torch
from emmental.modules import ThresholdBinarizer, TopKBinarizer




def   _SCREAMING_SNAKE_CASE      (	snake_case_		:						str						):
     __magic_name__				=       args.serialization_dir
     __magic_name__				=       args.pruning_method
     __magic_name__				=       args.threshold

     __magic_name__				=       torch.load(os.path.join(snake_case_ ,     '''pytorch_model.bin'''						) ,     map_location='''cpu'''						)

     __magic_name__				=       0  # Number of remaining (not pruned) params in the encoder
     __magic_name__				=       0  # Number of params in the encoder

     print('''name'''.ljust(60 ,     ''' '''						) ,     '''Remaining Weights %''' ,     '''Remaining Weight'''						)
     for name, param in st.items():
          if "encoder" not in name:
               continue

          if "mask_scores" in name:
               if pruning_method == "topK":
                    __magic_name__				=       TopKBinarizer.apply(snake_case_ ,     snake_case_						).sum().item()
               elif pruning_method == "sigmoied_threshold":
                    __magic_name__				=       ThresholdBinarizer.apply(snake_case_ ,     snake_case_ ,     snake_case_						).sum().item()
               elif pruning_method == "l0":
                    __magic_name__		,  __magic_name__				=       -0.1, 1.1
                    __magic_name__				=       torch.sigmoid(snake_case_						)
                    __magic_name__				=       s * (r - l) + l
                    __magic_name__				=       s_bar.clamp(min=0.0 ,     max=1.0						)
                    __magic_name__				=       (mask > 0.0).sum().item()
               else:
                    raise ValueError('''Unknown pruning method'''						)
               remaining_count += mask_ones
               print(name.ljust(60 ,     ''' '''						) ,     str(round(100 * mask_ones / param.numel() ,     3						)						).ljust(20 ,     ''' '''						) ,     str(snake_case_						)						)
          else:
               encoder_count += param.numel()
               if "bias" in name or "LayerNorm" in name:
                    remaining_count += param.numel()

     print(''''''						)
     print('''Remaining Weights (global) %: ''' ,     100 * remaining_count / encoder_count						)


if __name__ == "__main__":
    a_    :				Optional[Any]					=			argparse.ArgumentParser()

    parser.add_argument(
        '--pruning_method',
        choices=['l0', 'topK', 'sigmoied_threshold'],
        type=str,
        required=True,
        help=(
            'Pruning Method (l0 = L0 regularization, topK = Movement pruning, sigmoied_threshold = Soft movement'
            ' pruning)'
        ),
    )
    parser.add_argument(
        '--threshold',
        type=float,
        required=False,
        help=(
            'For `topK`, it is the level of remaining weights (in %) in the fine-pruned model.'
            'For `sigmoied_threshold`, it is the threshold \tau against which the (sigmoied) scores are compared.'
            'Not needed for `l0`'
        ),
    )
    parser.add_argument(
        '--serialization_dir',
        type=str,
        required=True,
        help='Folder containing the model that was previously fine-pruned',
    )

    a_    :				List[Any]					=			parser.parse_args()

    main(args)