


'''simple docstring'''
import json
import pathlib
import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision, slow
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
		import torch

if is_vision_available():
		from PIL import Image

		from transformers import ConditionalDetrImageProcessor
class      lowercase			(							unittest.TestCase      ):

		"""simple docstring"""

		def __init__(	self					,     UpperCamelCase_					,     UpperCamelCase_=7					,     UpperCamelCase_=3					,     UpperCamelCase_=30					,     UpperCamelCase_=400					,     UpperCamelCase_=True					,     UpperCamelCase_=None					,     UpperCamelCase_=True					,     UpperCamelCase_=[0.5, 0.5, 0.5]					,     UpperCamelCase_=[0.5, 0.5, 0.5]					,     UpperCamelCase_=True					,     UpperCamelCase_=1 / 255					,     UpperCamelCase_=True					,     ):

							'''simple docstring'''


							UpperCamelCase__     :Any							      =				size if size is not None else {'''shortest_edge''': 18, '''longest_edge''': 1333}
							UpperCamelCase__     :List[Any]							      =				parent
							UpperCamelCase__     :Any							      =				batch_size
							UpperCamelCase__     :Dict							      =				num_channels
							UpperCamelCase__     :str							      =				min_resolution
							UpperCamelCase__     :Optional[Any]							      =				max_resolution
							UpperCamelCase__     :Optional[Any]							      =				do_resize
							UpperCamelCase__     :Any							      =				size
							UpperCamelCase__     :Any							      =				do_normalize
							UpperCamelCase__     :Any							      =				image_mean
							UpperCamelCase__     :Dict							      =				image_std
							UpperCamelCase__     :Tuple							      =				do_rescale
							UpperCamelCase__     :int							      =				rescale_factor
							UpperCamelCase__     :int							      =				do_pad




		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							return {
							    "do_resize": self.do_resize,
							    "size": self.size,
							    "do_normalize": self.do_normalize,
							    "image_mean": self.image_mean,
							    "image_std": self.image_std,
							    "do_rescale": self.do_rescale,
							    "rescale_factor": self.rescale_factor,
							    "do_pad": self.do_pad,
							}




		def 					lowerCAmelCase__       (	self					,     UpperCamelCase_					,     UpperCamelCase_=False							):

							'''simple docstring'''


							if not batched:
												UpperCamelCase__     :Any							      =				image_inputs[0]
												if isinstance(UpperCamelCase_					,     Image.Image							):
																	UpperCamelCase__      ,       UpperCamelCase__     :List[str]							      =				image.size
												else:
																	UpperCamelCase__      ,       UpperCamelCase__     :Optional[int]							      =				image.shape[1], image.shape[2]
												if w < h:
																	UpperCamelCase__     :List[str]							      =				int(self.size['''shortest_edge'''] * h / w							)
																	UpperCamelCase__     :Any							      =				self.size['''shortest_edge''']
												elif w > h:
																	UpperCamelCase__     :Union[str, Any]							      =				self.size['''shortest_edge''']
																	UpperCamelCase__     :List[Any]							      =				int(self.size['''shortest_edge'''] * w / h							)
												else:
																	UpperCamelCase__     :Tuple							      =				self.size['''shortest_edge''']
																	UpperCamelCase__     :Union[str, Any]							      =				self.size['''shortest_edge''']

							else:
												UpperCamelCase__     :Tuple							      =				[]
												for image in image_inputs:
																	UpperCamelCase__      ,       UpperCamelCase__     :Tuple							      =				self.get_expected_values([image]							)
																	expected_values.append((expected_height, expected_width)							)
												UpperCamelCase__     :str							      =				max(UpperCamelCase_					,     key=lambda UpperCamelCase_							: item[0]							)[0]
												UpperCamelCase__     :int							      =				max(UpperCamelCase_					,     key=lambda UpperCamelCase_							: item[1]							)[1]

							return expected_height, expected_width



@require_torch
@require_vision
class      lowercase			(							A__			,	unittest.TestCase      ):

		"""simple docstring"""

		_a									=       ConditionalDetrImageProcessor if is_vision_available() else None




		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :Optional[int]							      =				ConditionalDetrImageProcessingTester(self							)




		@property
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							return self.image_processor_tester.prepare_image_processor_dict()




		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :str							      =				self.image_processing_class(**self.image_processor_dict							)
							self.assertTrue(hasattr(UpperCamelCase_					,     '''image_mean'''							)							)
							self.assertTrue(hasattr(UpperCamelCase_					,     '''image_std'''							)							)
							self.assertTrue(hasattr(UpperCamelCase_					,     '''do_normalize'''							)							)
							self.assertTrue(hasattr(UpperCamelCase_					,     '''do_resize'''							)							)
							self.assertTrue(hasattr(UpperCamelCase_					,     '''size'''							)							)




		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :Dict							      =				self.image_processing_class.from_dict(self.image_processor_dict							)
							self.assertEqual(image_processor.size					,     {'''shortest_edge''': 18, '''longest_edge''': 1333}							)
							self.assertEqual(image_processor.do_pad					,     UpperCamelCase_							)

							UpperCamelCase__     :Union[str, Any]							      =				self.image_processing_class.from_dict(
							    self.image_processor_dict					,     size=42					,     max_size=84					,     pad_and_return_pixel_mask=UpperCamelCase_							)
							self.assertEqual(image_processor.size					,     {'''shortest_edge''': 42, '''longest_edge''': 84}							)
							self.assertEqual(image_processor.do_pad					,     UpperCamelCase_							)




		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							pass




		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :Optional[int]							      =				self.image_processing_class(**self.image_processor_dict							)
							# create random PIL images
							UpperCamelCase__     :Optional[Any]							      =				prepare_image_inputs(self.image_processor_tester					,     equal_resolution=UpperCamelCase_							)
							for image in image_inputs:
												self.assertIsInstance(UpperCamelCase_					,     Image.Image							)

							# Test not batched input
							UpperCamelCase__     :str							      =				image_processing(image_inputs[0]					,     return_tensors='''pt'''							).pixel_values

							UpperCamelCase__      ,       UpperCamelCase__     :Tuple							      =				self.image_processor_tester.get_expected_values(UpperCamelCase_							)

							self.assertEqual(
							    encoded_images.shape					,     (1, self.image_processor_tester.num_channels, expected_height, expected_width)					,     )

							# Test batched
							UpperCamelCase__      ,       UpperCamelCase__     :Tuple							      =				self.image_processor_tester.get_expected_values(UpperCamelCase_					,     batched=UpperCamelCase_							)

							UpperCamelCase__     :List[Any]							      =				image_processing(UpperCamelCase_					,     return_tensors='''pt'''							).pixel_values
							self.assertEqual(
							    encoded_images.shape					,     (
							        self.image_processor_tester.batch_size,
							        self.image_processor_tester.num_channels,
							        expected_height,
							        expected_width,
							    )					,     )




		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :int							      =				self.image_processing_class(**self.image_processor_dict							)
							# create random numpy tensors
							UpperCamelCase__     :Optional[Any]							      =				prepare_image_inputs(self.image_processor_tester					,     equal_resolution=UpperCamelCase_					,     numpify=UpperCamelCase_							)
							for image in image_inputs:
												self.assertIsInstance(UpperCamelCase_					,     np.ndarray							)

							# Test not batched input
							UpperCamelCase__     :Tuple							      =				image_processing(image_inputs[0]					,     return_tensors='''pt'''							).pixel_values

							UpperCamelCase__      ,       UpperCamelCase__     :Optional[Any]							      =				self.image_processor_tester.get_expected_values(UpperCamelCase_							)

							self.assertEqual(
							    encoded_images.shape					,     (1, self.image_processor_tester.num_channels, expected_height, expected_width)					,     )

							# Test batched
							UpperCamelCase__     :Dict							      =				image_processing(UpperCamelCase_					,     return_tensors='''pt'''							).pixel_values

							UpperCamelCase__      ,       UpperCamelCase__     :Tuple							      =				self.image_processor_tester.get_expected_values(UpperCamelCase_					,     batched=UpperCamelCase_							)

							self.assertEqual(
							    encoded_images.shape					,     (
							        self.image_processor_tester.batch_size,
							        self.image_processor_tester.num_channels,
							        expected_height,
							        expected_width,
							    )					,     )




		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :str							      =				self.image_processing_class(**self.image_processor_dict							)
							# create random PyTorch tensors
							UpperCamelCase__     :Dict							      =				prepare_image_inputs(self.image_processor_tester					,     equal_resolution=UpperCamelCase_					,     torchify=UpperCamelCase_							)
							for image in image_inputs:
												self.assertIsInstance(UpperCamelCase_					,     torch.Tensor							)

							# Test not batched input
							UpperCamelCase__     :str							      =				image_processing(image_inputs[0]					,     return_tensors='''pt'''							).pixel_values

							UpperCamelCase__      ,       UpperCamelCase__     :str							      =				self.image_processor_tester.get_expected_values(UpperCamelCase_							)

							self.assertEqual(
							    encoded_images.shape					,     (1, self.image_processor_tester.num_channels, expected_height, expected_width)					,     )

							# Test batched
							UpperCamelCase__     :Union[str, Any]							      =				image_processing(UpperCamelCase_					,     return_tensors='''pt'''							).pixel_values

							UpperCamelCase__      ,       UpperCamelCase__     :Any							      =				self.image_processor_tester.get_expected_values(UpperCamelCase_					,     batched=UpperCamelCase_							)

							self.assertEqual(
							    encoded_images.shape					,     (
							        self.image_processor_tester.batch_size,
							        self.image_processor_tester.num_channels,
							        expected_height,
							        expected_width,
							    )					,     )




		@slow
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :Union[str, Any]							      =				Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''							)
							with open('''./tests/fixtures/tests_samples/COCO/coco_annotations.txt'''					,     '''r'''							) as f:
												UpperCamelCase__     :Any							      =				json.loads(f.read()							)

							UpperCamelCase__     :Tuple							      =				{'''image_id''': 39769, '''annotations''': target}

							# encode them
							UpperCamelCase__     :Dict							      =				ConditionalDetrImageProcessor.from_pretrained('''microsoft/conditional-detr-resnet-50'''							)
							UpperCamelCase__     :int							      =				image_processing(images=UpperCamelCase_					,     annotations=UpperCamelCase_					,     return_tensors='''pt'''							)

							# verify pixel values
							UpperCamelCase__     :Optional[int]							      =				torch.Size([1, 3, 800, 1066]							)
							self.assertEqual(encoding['''pixel_values'''].shape					,     UpperCamelCase_							)

							UpperCamelCase__     :Union[str, Any]							      =				torch.tensor([0.2796, 0.3138, 0.3481]							)
							self.assertTrue(torch.allclose(encoding['''pixel_values'''][0, 0, 0, :3]					,     UpperCamelCase_					,     atol=1e-4							)							)

							# verify area
							UpperCamelCase__     :int							      =				torch.tensor([5887.9600, 11250.2061, 489353.8438, 837122.7500, 147967.5156, 165732.3438]							)
							self.assertTrue(torch.allclose(encoding['''labels'''][0]['''area''']					,     UpperCamelCase_							)							)
							# verify boxes
							UpperCamelCase__     :Optional[Any]							      =				torch.Size([6, 4]							)
							self.assertEqual(encoding['''labels'''][0]['''boxes'''].shape					,     UpperCamelCase_							)
							UpperCamelCase__     :Dict							      =				torch.tensor([0.5503, 0.2765, 0.0604, 0.2215]							)
							self.assertTrue(torch.allclose(encoding['''labels'''][0]['''boxes'''][0]					,     UpperCamelCase_					,     atol=1e-3							)							)
							# verify image_id
							UpperCamelCase__     :Optional[Any]							      =				torch.tensor([39769]							)
							self.assertTrue(torch.allclose(encoding['''labels'''][0]['''image_id''']					,     UpperCamelCase_							)							)
							# verify is_crowd
							UpperCamelCase__     :List[Any]							      =				torch.tensor([0, 0, 0, 0, 0, 0]							)
							self.assertTrue(torch.allclose(encoding['''labels'''][0]['''iscrowd''']					,     UpperCamelCase_							)							)
							# verify class_labels
							UpperCamelCase__     :List[Any]							      =				torch.tensor([75, 75, 63, 65, 17, 17]							)
							self.assertTrue(torch.allclose(encoding['''labels'''][0]['''class_labels''']					,     UpperCamelCase_							)							)
							# verify orig_size
							UpperCamelCase__     :Union[str, Any]							      =				torch.tensor([480, 640]							)
							self.assertTrue(torch.allclose(encoding['''labels'''][0]['''orig_size''']					,     UpperCamelCase_							)							)
							# verify size
							UpperCamelCase__     :List[Any]							      =				torch.tensor([800, 1066]							)
							self.assertTrue(torch.allclose(encoding['''labels'''][0]['''size''']					,     UpperCamelCase_							)							)




		@slow
		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :List[Any]							      =				Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''							)
							with open('''./tests/fixtures/tests_samples/COCO/coco_panoptic_annotations.txt'''					,     '''r'''							) as f:
												UpperCamelCase__     :Optional[int]							      =				json.loads(f.read()							)

							UpperCamelCase__     :Union[str, Any]							      =				{'''file_name''': '''000000039769.png''', '''image_id''': 39769, '''segments_info''': target}

							UpperCamelCase__     :Optional[int]							      =				pathlib.Path('''./tests/fixtures/tests_samples/COCO/coco_panoptic'''							)

							# encode them
							UpperCamelCase__     :Optional[int]							      =				ConditionalDetrImageProcessor(format='''coco_panoptic'''							)
							UpperCamelCase__     :str							      =				image_processing(images=UpperCamelCase_					,     annotations=UpperCamelCase_					,     masks_path=UpperCamelCase_					,     return_tensors='''pt'''							)

							# verify pixel values
							UpperCamelCase__     :Dict							      =				torch.Size([1, 3, 800, 1066]							)
							self.assertEqual(encoding['''pixel_values'''].shape					,     UpperCamelCase_							)

							UpperCamelCase__     :int							      =				torch.tensor([0.2796, 0.3138, 0.3481]							)
							self.assertTrue(torch.allclose(encoding['''pixel_values'''][0, 0, 0, :3]					,     UpperCamelCase_					,     atol=1e-4							)							)

							# verify area
							UpperCamelCase__     :Union[str, Any]							      =				torch.tensor([147979.6875, 165527.0469, 484638.5938, 11292.9375, 5879.6562, 7634.1147]							)
							self.assertTrue(torch.allclose(encoding['''labels'''][0]['''area''']					,     UpperCamelCase_							)							)
							# verify boxes
							UpperCamelCase__     :int							      =				torch.Size([6, 4]							)
							self.assertEqual(encoding['''labels'''][0]['''boxes'''].shape					,     UpperCamelCase_							)
							UpperCamelCase__     :Tuple							      =				torch.tensor([0.2625, 0.5437, 0.4688, 0.8625]							)
							self.assertTrue(torch.allclose(encoding['''labels'''][0]['''boxes'''][0]					,     UpperCamelCase_					,     atol=1e-3							)							)
							# verify image_id
							UpperCamelCase__     :Optional[int]							      =				torch.tensor([39769]							)
							self.assertTrue(torch.allclose(encoding['''labels'''][0]['''image_id''']					,     UpperCamelCase_							)							)
							# verify is_crowd
							UpperCamelCase__     :Optional[Any]							      =				torch.tensor([0, 0, 0, 0, 0, 0]							)
							self.assertTrue(torch.allclose(encoding['''labels'''][0]['''iscrowd''']					,     UpperCamelCase_							)							)
							# verify class_labels
							UpperCamelCase__     :str							      =				torch.tensor([17, 17, 63, 75, 75, 93]							)
							self.assertTrue(torch.allclose(encoding['''labels'''][0]['''class_labels''']					,     UpperCamelCase_							)							)
							# verify masks
							UpperCamelCase__     :Optional[Any]							      =				822873
							self.assertEqual(encoding['''labels'''][0]['''masks'''].sum().item()					,     UpperCamelCase_							)
							# verify orig_size
							UpperCamelCase__     :Optional[Any]							      =				torch.tensor([480, 640]							)
							self.assertTrue(torch.allclose(encoding['''labels'''][0]['''orig_size''']					,     UpperCamelCase_							)							)
							# verify size
							UpperCamelCase__     :Tuple							      =				torch.tensor([800, 1066]							)
							self.assertTrue(torch.allclose(encoding['''labels'''][0]['''size''']					,     UpperCamelCase_							)							)



'''simple docstring'''
import qiskit


def     a   (    __a				,      __a     )						->			qiskit.result.counts.Counts:



					'''simple docstring'''






					UpperCamelCase__     :int							      =				qiskit.Aer.get_backend('''aer_simulator'''     )

					# Create a Quantum Circuit acting on the q register
					UpperCamelCase__     :Any							      =				qiskit.QuantumCircuit(__a				,      __a     )

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

					# Execute the circuit on the simulator
					UpperCamelCase__     :Optional[int]							      =				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__":
		print(F"""Total count for various states are: {single_qubit_measure(1, 1)}""")