





'''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 DetrImageProcessor






class       _UpperCamelCase      (			unittest.TestCase			):






				'''simple docstring'''





				def __init__(				self       ,					_a       ,					_a=7       ,					_a=3       ,					_a=30       ,					_a=400       ,					_a=True       ,					_a=None       ,					_a=True       ,					_a=1 / 255       ,					_a=True       ,					_a=[0.5, 0.5, 0.5]       ,					_a=[0.5, 0.5, 0.5]       ,					_a=True       ,					):
											"""simple docstring"""
											# by setting size["longest_edge"] > max_resolution we're effectively not testing this :p
											a__            =							size if size is not None else {'shortest_edge': 18, 'longest_edge': 1333}
											a__            =							parent
											a__            =							batch_size
											a__            =							num_channels
											a__            =							min_resolution
											a__            =							max_resolution
											a__            =							do_resize
											a__            =							size
											a__            =							do_rescale
											a__            =							rescale_factor
											a__            =							do_normalize
											a__            =							image_mean
											a__            =							image_std
											a__            =							do_pad






				def        lowercase__   (				self    ):
											"""simple docstring"""
											return {
											    "do_resize": self.do_resize,
											    "size": self.size,
											    "do_rescale": self.do_rescale,
											    "rescale_factor": self.rescale_factor,
											    "do_normalize": self.do_normalize,
											    "image_mean": self.image_mean,
											    "image_std": self.image_std,
											    "do_pad": self.do_pad,
											}






				def        lowercase__   (				self       ,					_a       ,					_a=False    ):
											"""simple docstring"""
											if not batched:
																		a__            =							image_inputs[0]
																		if isinstance(a_       ,					Image.Image    ):
																									a__            =							image.size
																		else:
																									a__            =							image.shape[1], image.shape[2]
																		if w < h:
																									a__            =							int(self.size['shortest_edge'] * h / w    )
																									a__            =							self.size['shortest_edge']
																		elif w > h:
																									a__            =							self.size['shortest_edge']
																									a__            =							int(self.size['shortest_edge'] * w / h    )
																		else:
																									a__            =							self.size['shortest_edge']
																									a__            =							self.size['shortest_edge']

											else:
																		a__            =							[]
																		for image in image_inputs:
																									a__            =							self.get_expected_values([image]    )
																									expected_values.append((expected_height, expected_width)    )
																		a__            =							max(a_       ,					key=lambda _a    : item[0]    )[0]
																		a__            =							max(a_       ,					key=lambda _a    : item[1]    )[1]

											return expected_height, expected_width






@require_torch
@require_vision
class       _UpperCamelCase      (			_A		,    unittest.TestCase			):






				'''simple docstring'''





				SCREAMING_SNAKE_CASE:List[str]         =	DetrImageProcessor if is_vision_available() else None






				def        lowercase__   (				self    ):
											"""simple docstring"""
											a__            =							DetrImageProcessingTester(self    )






				@property
				def        lowercase__   (				self    ):
											"""simple docstring"""
											return self.image_processor_tester.prepare_image_processor_dict()






				def        lowercase__   (				self    ):
											"""simple docstring"""
											a__            =							self.image_processing_class(**self.image_processor_dict    )
											self.assertTrue(hasattr(a_       ,					'image_mean'    )    )
											self.assertTrue(hasattr(a_       ,					'image_std'    )    )
											self.assertTrue(hasattr(a_       ,					'do_normalize'    )    )
											self.assertTrue(hasattr(a_       ,					'do_rescale'    )    )
											self.assertTrue(hasattr(a_       ,					'rescale_factor'    )    )
											self.assertTrue(hasattr(a_       ,					'do_resize'    )    )
											self.assertTrue(hasattr(a_       ,					'size'    )    )
											self.assertTrue(hasattr(a_       ,					'do_pad'    )    )






				def        lowercase__   (				self    ):
											"""simple docstring"""
											a__            =							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       ,					a_    )

											a__            =							self.image_processing_class.from_dict(
											    self.image_processor_dict       ,					size=42       ,					max_size=84       ,					pad_and_return_pixel_mask=a_    )
											self.assertEqual(image_processor.size       ,					{'shortest_edge': 42, 'longest_edge': 84}    )
											self.assertEqual(image_processor.do_pad       ,					a_    )






				def        lowercase__   (				self    ):
											"""simple docstring"""
											pass






				def        lowercase__   (				self    ):
											"""simple docstring"""
											# Initialize image_processing
											a__            =							self.image_processing_class(**self.image_processor_dict    )
											# create random PIL images
											a__            =							prepare_image_inputs(self.image_processor_tester       ,					equal_resolution=a_    )
											for image in image_inputs:
																		self.assertIsInstance(a_       ,					Image.Image    )

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

											a__            =							self.image_processor_tester.get_expected_values(a_    )

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

											# Test batched
											a__            =							self.image_processor_tester.get_expected_values(a_       ,					batched=a_    )

											a__            =							image_processing(a_       ,					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        lowercase__   (				self    ):
											"""simple docstring"""
											# Initialize image_processing
											a__            =							self.image_processing_class(**self.image_processor_dict    )
											# create random numpy tensors
											a__            =							prepare_image_inputs(self.image_processor_tester       ,					equal_resolution=a_       ,					numpify=a_    )
											for image in image_inputs:
																		self.assertIsInstance(a_       ,					np.ndarray    )

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

											a__            =							self.image_processor_tester.get_expected_values(a_    )

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

											# Test batched
											a__            =							image_processing(a_       ,					return_tensors='pt'    ).pixel_values

											a__            =							self.image_processor_tester.get_expected_values(a_       ,					batched=a_    )

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






				def        lowercase__   (				self    ):
											"""simple docstring"""
											# Initialize image_processing
											a__            =							self.image_processing_class(**self.image_processor_dict    )
											# create random PyTorch tensors
											a__            =							prepare_image_inputs(self.image_processor_tester       ,					equal_resolution=a_       ,					torchify=a_    )
											for image in image_inputs:
																		self.assertIsInstance(a_       ,					torch.Tensor    )

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

											a__            =							self.image_processor_tester.get_expected_values(a_    )

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

											# Test batched
											a__            =							image_processing(a_       ,					return_tensors='pt'    ).pixel_values

											a__            =							self.image_processor_tester.get_expected_values(a_       ,					batched=a_    )

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






				@slow
				def        lowercase__   (				self    ):
											"""simple docstring"""
											# prepare image and target
											a__            =							Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'    )
											with open('./tests/fixtures/tests_samples/COCO/coco_annotations.txt'       ,					'r'    ) as f:
																		a__            =							json.loads(f.read()    )

											a__            =							{'image_id': 3_9769, 'annotations': target}

											# encode them
											a__            =							DetrImageProcessor.from_pretrained('facebook/detr-resnet-50'    )
											a__            =							image_processing(images=a_       ,					annotations=a_       ,					return_tensors='pt'    )

											# verify pixel values
											a__            =							torch.Size([1, 3, 800, 1066]    )
											self.assertEqual(encoding['pixel_values'].shape       ,					a_    )

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

											# verify area
											a__            =							torch.tensor([5887.9600, 1_1250.2061, 48_9353.8438, 83_7122.7500, 14_7967.5156, 16_5732.3438]    )
											self.assertTrue(torch.allclose(encoding['labels'][0]['area']       ,					a_    )    )
											# verify boxes
											a__            =							torch.Size([6, 4]    )
											self.assertEqual(encoding['labels'][0]['boxes'].shape       ,					a_    )
											a__            =							torch.tensor([0.5503, 0.2765, 0.0604, 0.2215]    )
											self.assertTrue(torch.allclose(encoding['labels'][0]['boxes'][0]       ,					a_       ,					atol=1e-3    )    )
											# verify image_id
											a__            =							torch.tensor([3_9769]    )
											self.assertTrue(torch.allclose(encoding['labels'][0]['image_id']       ,					a_    )    )
											# verify is_crowd
											a__            =							torch.tensor([0, 0, 0, 0, 0, 0]    )
											self.assertTrue(torch.allclose(encoding['labels'][0]['iscrowd']       ,					a_    )    )
											# verify class_labels
											a__            =							torch.tensor([75, 75, 63, 65, 17, 17]    )
											self.assertTrue(torch.allclose(encoding['labels'][0]['class_labels']       ,					a_    )    )
											# verify orig_size
											a__            =							torch.tensor([480, 640]    )
											self.assertTrue(torch.allclose(encoding['labels'][0]['orig_size']       ,					a_    )    )
											# verify size
											a__            =							torch.tensor([800, 1066]    )
											self.assertTrue(torch.allclose(encoding['labels'][0]['size']       ,					a_    )    )






				@slow
				def        lowercase__   (				self    ):
											"""simple docstring"""
											# prepare image, target and masks_path
											a__            =							Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'    )
											with open('./tests/fixtures/tests_samples/COCO/coco_panoptic_annotations.txt'       ,					'r'    ) as f:
																		a__            =							json.loads(f.read()    )

											a__            =							{'file_name': '000000039769.png', 'image_id': 3_9769, 'segments_info': target}

											a__            =							pathlib.Path('./tests/fixtures/tests_samples/COCO/coco_panoptic'    )

											# encode them
											a__            =							DetrImageProcessor.from_pretrained('facebook/detr-resnet-50-panoptic'    )
											a__            =							image_processing(images=a_       ,					annotations=a_       ,					masks_path=a_       ,					return_tensors='pt'    )

											# verify pixel values
											a__            =							torch.Size([1, 3, 800, 1066]    )
											self.assertEqual(encoding['pixel_values'].shape       ,					a_    )

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

											# verify area
											a__            =							torch.tensor([14_7979.6875, 16_5527.0469, 48_4638.5938, 1_1292.9375, 5879.6562, 7634.1147]    )
											self.assertTrue(torch.allclose(encoding['labels'][0]['area']       ,					a_    )    )
											# verify boxes
											a__            =							torch.Size([6, 4]    )
											self.assertEqual(encoding['labels'][0]['boxes'].shape       ,					a_    )
											a__            =							torch.tensor([0.2625, 0.5437, 0.4688, 0.8625]    )
											self.assertTrue(torch.allclose(encoding['labels'][0]['boxes'][0]       ,					a_       ,					atol=1e-3    )    )
											# verify image_id
											a__            =							torch.tensor([3_9769]    )
											self.assertTrue(torch.allclose(encoding['labels'][0]['image_id']       ,					a_    )    )
											# verify is_crowd
											a__            =							torch.tensor([0, 0, 0, 0, 0, 0]    )
											self.assertTrue(torch.allclose(encoding['labels'][0]['iscrowd']       ,					a_    )    )
											# verify class_labels
											a__            =							torch.tensor([17, 17, 63, 75, 75, 93]    )
											self.assertTrue(torch.allclose(encoding['labels'][0]['class_labels']       ,					a_    )    )
											# verify masks
											a__            =							82_2873
											self.assertEqual(encoding['labels'][0]['masks'].sum().item()       ,					a_    )
											# verify orig_size
											a__            =							torch.tensor([480, 640]    )
											self.assertTrue(torch.allclose(encoding['labels'][0]['orig_size']       ,					a_    )    )
											# verify size
											a__            =							torch.tensor([800, 1066]    )
											self.assertTrue(torch.allclose(encoding['labels'][0]['size']       ,					a_    )    )










'''simple docstring'''

import qiskit







def a_     (    __UpperCAmelCase				,							__UpperCAmelCase					)				->					qiskit.result.counts.Counts:





			"""simple docstring"""







			snake_case:    Union[str, Any]      							=qiskit.Aer.get_backend('aer_simulator'					)

			# Create a Quantum Circuit acting on the q register
			snake_case:    Dict      							=qiskit.QuantumCircuit(__UpperCAmelCase				,							__UpperCAmelCase					)

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

			# Execute the circuit on the simulator
			snake_case:    Dict      							=qiskit.execute(__UpperCAmelCase				,							__UpperCAmelCase				,							shots=10_00					)

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


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




