import tempfile
import unittest

import numpy as np
import torch

from diffusers import ScoreSdeVeScheduler







class __snake_case							(		unittest.TestCase						):
   lowerCAmelCase_								=				(ScoreSdeVeScheduler,)
   lowerCAmelCase_								=				()




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



     """simple docstring"""






     SCREAMING_SNAKE_CASE__     				= 4
     SCREAMING_SNAKE_CASE__     				= 3
     SCREAMING_SNAKE_CASE__     				= 8
     SCREAMING_SNAKE_CASE__     				= 8

     SCREAMING_SNAKE_CASE__     				= torch.rand((batch_size, num_channels, height, width) )

     return sample




   @property
   def       __a		(       self     :							int ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__     				= 4
     SCREAMING_SNAKE_CASE__     				= 3
     SCREAMING_SNAKE_CASE__     				= 8
     SCREAMING_SNAKE_CASE__     				= 8

     SCREAMING_SNAKE_CASE__     				= batch_size * num_channels * height * width
     SCREAMING_SNAKE_CASE__     				= torch.arange(__UpperCamelCase )
     SCREAMING_SNAKE_CASE__     				= sample.reshape(__UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase )
     SCREAMING_SNAKE_CASE__     				= sample / num_elems
     SCREAMING_SNAKE_CASE__     				= sample.permute(3			,      0			,      1			,      2 )

     return sample




   def       __a		(       self     :							Union[str, Any] ):



     """simple docstring"""






     def model(_lowercase     :							int			,      _lowercase     :							Tuple			,      *_lowercase     :							List[Any] ):
       return sample * t / (t + 1)

     return model




   def       __a		(       self     :							Any			,      **_lowercase     :							List[str] ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__     				= {
         """num_train_timesteps""": 20_00,
         """snr""": 0.15,
         """sigma_min""": 0.01,
         """sigma_max""": 13_48,
         """sampling_eps""": 1E-5,
     }

     config.update(**__UpperCamelCase )
     return config




   def       __a		(       self     :							Tuple			,      _lowercase     :							int=0			,      **_lowercase     :							List[Any] ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__     				= dict(self.forward_default_kwargs )

     for scheduler_class in self.scheduler_classes:
       SCREAMING_SNAKE_CASE__     				= self.dummy_sample
       SCREAMING_SNAKE_CASE__     				= 0.1 * sample

       SCREAMING_SNAKE_CASE__     				= self.get_scheduler_config(**__UpperCamelCase )
       SCREAMING_SNAKE_CASE__     				= scheduler_class(**__UpperCamelCase )

       with tempfile.TemporaryDirectory() as tmpdirname:
         scheduler.save_config(__UpperCamelCase )
         SCREAMING_SNAKE_CASE__     				= scheduler_class.from_pretrained(__UpperCamelCase )

       SCREAMING_SNAKE_CASE__     				= scheduler.step_pred(
           __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      generator=torch.manual_seed(0 )			,      **__UpperCamelCase ).prev_sample
       SCREAMING_SNAKE_CASE__     				= new_scheduler.step_pred(
           __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      generator=torch.manual_seed(0 )			,      **__UpperCamelCase ).prev_sample

       assert torch.sum(torch.abs(output - new_output ) ) < 1E-5, "Scheduler outputs are not identical"

       SCREAMING_SNAKE_CASE__     				= scheduler.step_correct(__UpperCamelCase			,      __UpperCamelCase			,      generator=torch.manual_seed(0 )			,      **__UpperCamelCase ).prev_sample
       SCREAMING_SNAKE_CASE__     				= new_scheduler.step_correct(
           __UpperCamelCase			,      __UpperCamelCase			,      generator=torch.manual_seed(0 )			,      **__UpperCamelCase ).prev_sample

       assert torch.sum(torch.abs(output - new_output ) ) < 1E-5, "Scheduler correction are not identical"




   def       __a		(       self     :							str			,      _lowercase     :							str=0			,      **_lowercase     :							Union[str, Any] ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__     				= dict(self.forward_default_kwargs )
     kwargs.update(__UpperCamelCase )

     for scheduler_class in self.scheduler_classes:
       SCREAMING_SNAKE_CASE__     				= self.dummy_sample
       SCREAMING_SNAKE_CASE__     				= 0.1 * sample

       SCREAMING_SNAKE_CASE__     				= self.get_scheduler_config()
       SCREAMING_SNAKE_CASE__     				= scheduler_class(**__UpperCamelCase )

       with tempfile.TemporaryDirectory() as tmpdirname:
         scheduler.save_config(__UpperCamelCase )
         SCREAMING_SNAKE_CASE__     				= scheduler_class.from_pretrained(__UpperCamelCase )

       SCREAMING_SNAKE_CASE__     				= scheduler.step_pred(
           __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      generator=torch.manual_seed(0 )			,      **__UpperCamelCase ).prev_sample
       SCREAMING_SNAKE_CASE__     				= new_scheduler.step_pred(
           __UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      generator=torch.manual_seed(0 )			,      **__UpperCamelCase ).prev_sample

       assert torch.sum(torch.abs(output - new_output ) ) < 1E-5, "Scheduler outputs are not identical"

       SCREAMING_SNAKE_CASE__     				= scheduler.step_correct(__UpperCamelCase			,      __UpperCamelCase			,      generator=torch.manual_seed(0 )			,      **__UpperCamelCase ).prev_sample
       SCREAMING_SNAKE_CASE__     				= new_scheduler.step_correct(
           __UpperCamelCase			,      __UpperCamelCase			,      generator=torch.manual_seed(0 )			,      **__UpperCamelCase ).prev_sample

       assert torch.sum(torch.abs(output - new_output ) ) < 1E-5, "Scheduler correction are not identical"




   def       __a		(       self     :							Any ):



     """simple docstring"""






     for timesteps in [10, 1_00, 10_00]:
       self.check_over_configs(num_train_timesteps=__UpperCamelCase )




   def       __a		(       self     :							Union[str, Any] ):



     """simple docstring"""






     for sigma_min, sigma_max in zip([0.00_01, 0.0_01, 0.01]			,      [1, 1_00, 10_00] ):
       self.check_over_configs(sigma_min=__UpperCamelCase			,      sigma_max=__UpperCamelCase )




   def       __a		(       self     :							List[str] ):



     """simple docstring"""






     for t in [0.1, 0.5, 0.75]:
       self.check_over_forward(time_step=__UpperCamelCase )




   def       __a		(       self     :							Any ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__     				= dict(self.forward_default_kwargs )

     SCREAMING_SNAKE_CASE__     				= self.scheduler_classes[0]
     SCREAMING_SNAKE_CASE__     				= self.get_scheduler_config()
     SCREAMING_SNAKE_CASE__     				= scheduler_class(**__UpperCamelCase )

     SCREAMING_SNAKE_CASE__     				= 3

     SCREAMING_SNAKE_CASE__     				= self.dummy_model()
     SCREAMING_SNAKE_CASE__     				= self.dummy_sample_deter

     scheduler.set_sigmas(__UpperCamelCase )
     scheduler.set_timesteps(__UpperCamelCase )
     SCREAMING_SNAKE_CASE__     				= torch.manual_seed(0 )

     for i, t in enumerate(scheduler.timesteps ):
       SCREAMING_SNAKE_CASE__     				= scheduler.sigmas[i]

       for _ in range(scheduler.config.correct_steps ):
         with torch.no_grad():
           SCREAMING_SNAKE_CASE__     				= model(__UpperCamelCase			,      __UpperCamelCase )
         SCREAMING_SNAKE_CASE__     				= scheduler.step_correct(__UpperCamelCase			,      __UpperCamelCase			,      generator=__UpperCamelCase			,      **__UpperCamelCase ).prev_sample

       with torch.no_grad():
         SCREAMING_SNAKE_CASE__     				= model(__UpperCamelCase			,      __UpperCamelCase )

       SCREAMING_SNAKE_CASE__     				= scheduler.step_pred(__UpperCamelCase			,      __UpperCamelCase			,      __UpperCamelCase			,      generator=__UpperCamelCase			,      **__UpperCamelCase )
       SCREAMING_SNAKE_CASE__				,	SCREAMING_SNAKE_CASE__     				= output.prev_sample, output.prev_sample_mean

     SCREAMING_SNAKE_CASE__     				= torch.sum(torch.abs(__UpperCamelCase ) )
     SCREAMING_SNAKE_CASE__     				= torch.mean(torch.abs(__UpperCamelCase ) )

     assert np.isclose(result_sum.item()			,      1_43_72_75_85_28.0 )
     assert np.isclose(result_mean.item()			,      18_71_45_30.0 )




   def       __a		(       self     :							Any ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__     				= dict(self.forward_default_kwargs )

     SCREAMING_SNAKE_CASE__     				= kwargs.pop("""num_inference_steps"""			,      __UpperCamelCase )

     for scheduler_class in self.scheduler_classes:
       SCREAMING_SNAKE_CASE__     				= self.get_scheduler_config()
       SCREAMING_SNAKE_CASE__     				= scheduler_class(**__UpperCamelCase )

       SCREAMING_SNAKE_CASE__     				= self.dummy_sample
       SCREAMING_SNAKE_CASE__     				= 0.1 * sample

       if num_inference_steps is not None and hasattr(__UpperCamelCase			,      """set_timesteps""" ):
         scheduler.set_timesteps(__UpperCamelCase )
       elif num_inference_steps is not None and not hasattr(__UpperCamelCase			,      """set_timesteps""" ):
         SCREAMING_SNAKE_CASE__     				= num_inference_steps

       SCREAMING_SNAKE_CASE__     				= scheduler.step_pred(__UpperCamelCase			,      0			,      __UpperCamelCase			,      generator=torch.manual_seed(0 )			,      **__UpperCamelCase ).prev_sample
       SCREAMING_SNAKE_CASE__     				= scheduler.step_pred(__UpperCamelCase			,      1			,      __UpperCamelCase			,      generator=torch.manual_seed(0 )			,      **__UpperCamelCase ).prev_sample

       self.assertEqual(output_a.shape			,      sample.shape )
       self.assertEqual(output_a.shape			,      output_a.shape )


import math

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





def        lowerCAmelCase       (				snake_case__   :      int = 1				,					snake_case__   :      int = 1 )->			qiskit.result.counts.Counts:
    if isinstance(snake_case__				,					snake_case__ ) or isinstance(snake_case__				,					snake_case__ ):
        raise TypeError("inputs must be integers." )
    if (bit_a < 0) or (bit_a < 0):
        raise ValueError("inputs must be positive." )
    if (math.floor(snake_case__ ) != bit_a) or (math.floor(snake_case__ ) != 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
    A_								=					QuantumRegister(2				,					"qr" )
    A_								=					ClassicalRegister(2				,					"cr" )

    A_								=					QuantumCircuit(snake_case__				,					snake_case__ )

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

    # send the information
    A_								=					str(snake_case__ ) + str(snake_case__ )

    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(snake_case__				,					snake_case__ )

    A_								=					Aer.get_backend("aer_simulator" )
    A_								=					execute(snake_case__				,					snake_case__				,					shots=1000 )

    return job.result().get_counts(snake_case__ )


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






