




'''simple docstring'''
import numpy as np
import qiskit
def 							snake_case_    (  a__						:      int       ,a__						:      Any     ):



    """simple docstring"""




    __lowercase     							=		qiskit.QuantumCircuit(num_qubits + 1     )

    # First, let's deal with the case in which oracle is balanced
    if case == "balanced":
        # First generate a random number that tells us which CNOTs to
        # wrap in X-gates:
        __lowercase     							=		np.random.randint(1       ,2**num_qubits     )
        # Next, format 'b' as a binary string of length 'n', padded with zeros:
        __lowercase     							=		format(lowercase_       ,f'0{num_qubits}b'     )
        # Next, we place the first X-gates. Each digit in our binary string
        # corresponds to a qubit, if the digit is 0, we do nothing, if it's 1
        # we apply an X-gate to that qubit:
        for index, bit in enumerate(lowercase_     ):
            if bit == "1":
                oracle_qc.x(lowercase_     )
                    # Do the controlled-NOT gates for each qubit, using the output qubit
                    # as the target:
        for index in range(lowercase_     ):
            oracle_qc.cx(lowercase_       ,lowercase_     )
        # Next, place the final X-gates
        for index, bit in enumerate(lowercase_     ):
            if bit == "1":
                oracle_qc.x(lowercase_     )

                # Case in which oracle is constant
    if case == "constant":
        # First decide what the fixed output of the oracle will be
        # (either always 0 or always 1)
        __lowercase     							=		np.random.randint(2     )
        if output == 1:
            oracle_qc.x(lowercase_     )

    __lowercase     							=		oracle_qc.to_gate()
    __lowercase     							=		"""Oracle"""  # To show when we display the circuit
    return oracle_gate
def 							snake_case_    (  a__						:      Optional[Any]       ,a__						:      Union[str, Any]     ):



    """simple docstring"""




    __lowercase     							=		qiskit.QuantumCircuit(num_qubits + 1       ,lowercase_     )
    # Set up the output qubit:
    dj_circuit.x(lowercase_     )
    dj_circuit.h(lowercase_     )
    # And set up the input register:
    for qubit in range(lowercase_     ):
        dj_circuit.h(lowercase_     )
    # Let's append the oracle gate to our circuit:
    dj_circuit.append(lowercase_       ,range(num_qubits + 1     )     )
    # Finally, perform the H-gates again and measure:
    for qubit in range(lowercase_     ):
        dj_circuit.h(lowercase_     )

    for i in range(lowercase_     ):
        dj_circuit.measure(lowercase_       ,lowercase_     )

    return dj_circuit
def 							snake_case_    (  a__						:      List[Any]       ,a__						:      Any     ):



    """simple docstring"""




    __lowercase     							=		qiskit.Aer.get_backend("""aer_simulator"""     )

    __lowercase     							=		dj_oracle(lowercase_       ,lowercase_     )
    __lowercase     							=		dj_algorithm(lowercase_       ,lowercase_     )

    # Execute the circuit on the simulator
    __lowercase     							=		qiskit.execute(lowercase_       ,lowercase_       ,shots=10_00     )

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


if __name__ == "__main__":
  print(F"""Deutsch Jozsa - Constant Oracle: {deutsch_jozsa("constant", 3)}""")
  print(F"""Deutsch Jozsa - Balanced Oracle: {deutsch_jozsa("balanced", 3)}""")










"""simple docstring"""



import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
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 ViTImageProcessor




class       UpperCAmelCase_    (		unittest.TestCase				):




    def __init__(       self		:			Union[str, Any]      ,					snake_case_		:			Tuple      ,					snake_case_		:			Dict=7      ,					snake_case_		:			List[Any]=3      ,					snake_case_		:			Optional[int]=18      ,					snake_case_		:			Tuple=30      ,					snake_case_		:			Dict=400      ,					snake_case_		:			List[str]=True      ,					snake_case_		:			Optional[int]=None      ,					snake_case_		:			List[str]=True      ,					snake_case_		:			Optional[Any]=[0.5, 0.5, 0.5]      ,					snake_case_		:			Optional[int]=[0.5, 0.5, 0.5]      ,					) ->				List[Any]:




     '''simple docstring'''

     A__			=							size if size is not None else {"height": 18, "width": 18}
     A__			=							parent
     A__			=							batch_size
     A__			=							num_channels
     A__			=							image_size
     A__			=							min_resolution
     A__			=							max_resolution
     A__			=							do_resize
     A__			=							size
     A__			=							do_normalize
     A__			=							image_mean
     A__			=							image_std




    def 				__magic_name__				(       self		:			Union[str, Any] ) ->				Dict:




     '''simple docstring'''

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






@require_torch
@require_vision
class       UpperCAmelCase_    (		A_,  unittest.TestCase				):
    lowercase__		   = ViTImageProcessor if is_vision_available() else None




    def 				__magic_name__				(       self		:			int ) ->				Any:




     '''simple docstring'''

     A__			=							ViTImageProcessingTester(self )




    @property
    def 				__magic_name__				(       self		:			Optional[Any] ) ->				str:




     '''simple docstring'''

     return self.image_processor_tester.prepare_image_processor_dict()




    def 				__magic_name__				(       self		:			Tuple ) ->				str:




     '''simple docstring'''

     A__			=							self.image_processing_class(**self.image_processor_dict )
     self.assertTrue(hasattr(snake_case_      ,					"image_mean" ) )
     self.assertTrue(hasattr(snake_case_      ,					"image_std" ) )
     self.assertTrue(hasattr(snake_case_      ,					"do_normalize" ) )
     self.assertTrue(hasattr(snake_case_      ,					"do_resize" ) )
     self.assertTrue(hasattr(snake_case_      ,					"size" ) )




    def 				__magic_name__				(       self		:			Union[str, Any] ) ->				List[str]:




     '''simple docstring'''

     A__			=							self.image_processing_class.from_dict(self.image_processor_dict )
     self.assertEqual(image_processor.size      ,					{"height": 18, "width": 18} )

     A__			=							self.image_processing_class.from_dict(self.image_processor_dict      ,					size=42 )
     self.assertEqual(image_processor.size      ,					{"height": 42, "width": 42} )




    def 				__magic_name__				(       self		:			Any ) ->				Optional[Any]:




     '''simple docstring'''

     pass




    def 				__magic_name__				(       self		:			Optional[int] ) ->				Any:




     '''simple docstring'''

     A__			=							self.image_processing_class(**self.image_processor_dict )
     # create random PIL images
     A__			=							prepare_image_inputs(self.image_processor_tester      ,					equal_resolution=snake_case_ )
     for image in image_inputs:
      self.assertIsInstance(snake_case_      ,					Image.Image )

     # Test not batched input
     A__			=							image_processing(image_inputs[0]      ,					return_tensors="pt" ).pixel_values
     self.assertEqual(
         encoded_images.shape      ,					(
             1,
             self.image_processor_tester.num_channels,
             self.image_processor_tester.size["height"],
             self.image_processor_tester.size["width"],
         )      ,					)

     # Test batched
     A__			=							image_processing(snake_case_      ,					return_tensors="pt" ).pixel_values
     self.assertEqual(
         encoded_images.shape      ,					(
             self.image_processor_tester.batch_size,
             self.image_processor_tester.num_channels,
             self.image_processor_tester.size["height"],
             self.image_processor_tester.size["width"],
         )      ,					)




    def 				__magic_name__				(       self		:			str ) ->				Optional[Any]:




     '''simple docstring'''

     A__			=							self.image_processing_class(**self.image_processor_dict )
     # create random numpy tensors
     A__			=							prepare_image_inputs(self.image_processor_tester      ,					equal_resolution=snake_case_      ,					numpify=snake_case_ )
     for image in image_inputs:
      self.assertIsInstance(snake_case_      ,					np.ndarray )

     # Test not batched input
     A__			=							image_processing(image_inputs[0]      ,					return_tensors="pt" ).pixel_values
     self.assertEqual(
         encoded_images.shape      ,					(
             1,
             self.image_processor_tester.num_channels,
             self.image_processor_tester.size["height"],
             self.image_processor_tester.size["width"],
         )      ,					)

     # Test batched
     A__			=							image_processing(snake_case_      ,					return_tensors="pt" ).pixel_values
     self.assertEqual(
         encoded_images.shape      ,					(
             self.image_processor_tester.batch_size,
             self.image_processor_tester.num_channels,
             self.image_processor_tester.size["height"],
             self.image_processor_tester.size["width"],
         )      ,					)




    def 				__magic_name__				(       self		:			Dict ) ->				Union[str, Any]:




     '''simple docstring'''

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

     # Test not batched input
     A__			=							image_processing(image_inputs[0]      ,					return_tensors="pt" ).pixel_values
     self.assertEqual(
         encoded_images.shape      ,					(
             1,
             self.image_processor_tester.num_channels,
             self.image_processor_tester.size["height"],
             self.image_processor_tester.size["width"],
         )      ,					)

     # Test batched
     A__			=							image_processing(snake_case_      ,					return_tensors="pt" ).pixel_values
     self.assertEqual(
         encoded_images.shape      ,					(
             self.image_processor_tester.batch_size,
             self.image_processor_tester.num_channels,
             self.image_processor_tester.size["height"],
             self.image_processor_tester.size["width"],
         )      ,					)





