

'''simple docstring'''

import unittest
from functools import partial

import torch

from accelerate import Accelerator, debug_launcher
from accelerate.state import AcceleratorState, GradientState
from accelerate.test_utils import require_cpu, require_huggingface_suite
from accelerate.utils import GradientAccumulationPlugin





def 				lowercase (					__magic_name__=2			,   __magic_name__=True			,   __magic_name__=False							):



					'''simple docstring'''







					UpperCAmelCase		:							List[str]        =       Accelerator(step_scheduler_with_optimizer=__magic_name__			,   split_batches=__magic_name__							)
					UpperCAmelCase		:							Optional[Any]        =       torch.nn.Linear(2			,   4							)
					UpperCAmelCase		:							List[Any]        =       torch.optim.AdamW(model.parameters()			,   lr=1.0							)
					UpperCAmelCase		:							Any        =       torch.optim.lr_scheduler.OneCycleLR(__magic_name__			,   max_lr=0.0_1			,   steps_per_epoch=2			,   epochs=1							)
					UpperCAmelCase ,			UpperCAmelCase ,			UpperCAmelCase		:							str        =       accelerator.prepare(__magic_name__			,   __magic_name__			,   __magic_name__							)

					# Optimizer has stepped
					scheduler.step()
					if step_scheduler_with_optimizer or (num_processes == 1):
										assert (
										    scheduler.scheduler.last_epoch == num_processes
										), F"Last Epoch ({scheduler.scheduler.last_epoch}) != Num Processes ({num_processes})"
					else:
										assert (
										    scheduler.scheduler.last_epoch != num_processes
										), F"Last Epoch ({scheduler.scheduler.last_epoch}) == Num Processes ({num_processes})"





def 				lowercase (					__magic_name__=2			,   __magic_name__=True			,   __magic_name__=False							):



					'''simple docstring'''







					UpperCAmelCase		:							Tuple        =       Accelerator(step_scheduler_with_optimizer=__magic_name__			,   split_batches=__magic_name__							)
					UpperCAmelCase		:							Tuple        =       torch.nn.Linear(2			,   4							)
					UpperCAmelCase		:							Tuple        =       torch.optim.AdamW(model.parameters()			,   lr=1.0							)
					UpperCAmelCase		:							Union[str, Any]        =       torch.optim.lr_scheduler.LambdaLR(__magic_name__			,   lr_lambda=lambda __magic_name__							: 1 - n / 10							)
					UpperCAmelCase ,			UpperCAmelCase ,			UpperCAmelCase		:							Dict        =       accelerator.prepare(__magic_name__			,   __magic_name__			,   __magic_name__							)

					# Optimizer has stepped
					UpperCAmelCase		:							int        =       False
					scheduler.step()
					UpperCAmelCase		:							Union[str, Any]        =       1 - (num_processes if (step_scheduler_with_optimizer and not split_batches) else 1) / 10
					assert (
					    scheduler.get_last_lr()[0] == expected_lr
					), F"Wrong lr found at first step, expected {expected_lr}, got {scheduler.get_last_lr()[0]}"

					# Optimizer has not stepped
					UpperCAmelCase		:							Dict        =       True
					scheduler.step()
					if not step_scheduler_with_optimizer:
										UpperCAmelCase		:							List[str]        =       1 - 2 / 10
					assert (
					    scheduler.get_last_lr()[0] == expected_lr
					), F"Wrong lr found at second step, expected {expected_lr}, got {scheduler.get_last_lr()[0]}"





def 				lowercase (					__magic_name__ = 2							):



					'''simple docstring'''







					from transformers import get_linear_schedule_with_warmup

					UpperCAmelCase		:							Any        =       [1, 2, 4]
					for num_steps in steps:
										UpperCAmelCase		:							Any        =       GradientAccumulationPlugin(num_steps=__magic_name__			,   adjust_scheduler=num_steps > 1							)
										UpperCAmelCase		:							List[str]        =       Accelerator(gradient_accumulation_plugin=__magic_name__							)
										UpperCAmelCase		:							Optional[Any]        =       torch.nn.Linear(2			,   4							)
										UpperCAmelCase		:							List[str]        =       torch.optim.AdamW(model.parameters()			,   lr=1_0.0							)
										UpperCAmelCase		:							str        =       get_linear_schedule_with_warmup(optimizer=__magic_name__			,   num_warmup_steps=0			,   num_training_steps=20							)

										UpperCAmelCase ,			UpperCAmelCase ,			UpperCAmelCase		:							Optional[Any]        =       accelerator.prepare(__magic_name__			,   __magic_name__			,   __magic_name__							)

										for i in range(10 * num_steps							):
															with accelerator.accumulate(__magic_name__							):
																				optimizer.step()
																				scheduler.step()

															if i == (10 * num_steps - 2):
																				assert (
																				    scheduler.get_last_lr()[0] != 0
																				), F"Wrong lr found at second-to-last step, expected non-zero, got {scheduler.get_last_lr()[0]}. num_steps: {num_steps}"
										assert (
										    scheduler.get_last_lr()[0] == 0
										), F"Wrong lr found at last step, expected 0, got {scheduler.get_last_lr()[0]}"
										GradientState._reset_state()







@require_cpu
class   UpperCamelCase__   (       unittest.TestCase       ):


		"""simple docstring"""

		def 				A_	(			self      ):


							'''simple docstring'''

							debug_launcher(partial(snake_case   ,      num_processes=1      )   ,      num_processes=1      )
							debug_launcher(partial(snake_case   ,      num_processes=1   ,      split_batches=snake_case      )   ,      num_processes=1      )







		def 				A_	(			self      ):


							'''simple docstring'''

							debug_launcher(partial(snake_case   ,      num_processes=1      )   ,      num_processes=1      )
							debug_launcher(partial(snake_case   ,      num_processes=1   ,      split_batches=snake_case      )   ,      num_processes=1      )







		def 				A_	(			self      ):


							'''simple docstring'''

							debug_launcher(partial(snake_case   ,      num_processes=1   ,      step_scheduler_with_optimizer=snake_case      )   ,      num_processes=1      )







		def 				A_	(			self      ):


							'''simple docstring'''

							debug_launcher(partial(snake_case   ,      num_processes=1   ,      step_scheduler_with_optimizer=snake_case      )   ,      num_processes=1      )







		def 				A_	(			self      ):


							'''simple docstring'''

							AcceleratorState._reset_state(snake_case      )
							debug_launcher(snake_case      )
							debug_launcher(partial(snake_case   ,      num_processes=1   ,      split_batches=snake_case      )   ,      num_processes=1      )







		def 				A_	(			self      ):


							'''simple docstring'''

							AcceleratorState._reset_state(snake_case      )
							debug_launcher(snake_case      )
							debug_launcher(partial(snake_case   ,      num_processes=1   ,      split_batches=snake_case      )   ,      num_processes=1      )







		def 				A_	(			self      ):


							'''simple docstring'''

							AcceleratorState._reset_state(snake_case      )
							debug_launcher(partial(snake_case   ,      step_scheduler_with_optimizer=snake_case      )      )







		def 				A_	(			self      ):


							'''simple docstring'''

							AcceleratorState._reset_state(snake_case      )
							debug_launcher(partial(snake_case   ,      step_scheduler_with_optimizer=snake_case      )      )







		@require_huggingface_suite
		def 				A_	(			self      ):


							'''simple docstring'''

							AcceleratorState._reset_state(snake_case      )
							debug_launcher(partial(snake_case   ,      num_processes=1      )      )
							debug_launcher(snake_case      )



'''simple docstring'''

import math

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





def 				lowercase (					__magic_name__ = 1			,   __magic_name__ = 1							):



					'''simple docstring'''







					if isinstance(__magic_name__			,   __magic_name__							) or isinstance(__magic_name__			,   __magic_name__							):
										raise TypeError("inputs must be integers."							)
					if (bit_a < 0) or (bit_a < 0):
										raise ValueError("inputs must be positive."							)
					if (math.floor(__magic_name__							) != bit_a) or (math.floor(__magic_name__							) != 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
					UpperCAmelCase		:							List[Any]        =       QuantumRegister(2			,   "qr"							)
					UpperCAmelCase		:							Optional[int]        =       ClassicalRegister(2			,   "cr"							)

					UpperCAmelCase		:							Optional[int]        =       QuantumCircuit(__magic_name__			,   __magic_name__							)

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

					# send the information
					UpperCAmelCase		:							Any        =       str(__magic_name__							) + str(__magic_name__							)

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

					UpperCAmelCase		:							Tuple        =       Aer.get_backend("aer_simulator"							)
					UpperCAmelCase		:							Any        =       execute(__magic_name__			,   __magic_name__			,   shots=1000							)

					return job.result().get_counts(__magic_name__							)


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