



'''simple docstring'''





import numpy as np
import qiskit
def 		_a   (  lowerCamelCase_					,						lowerCamelCase_							):
   snake_case   :							int						  =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:
      snake_case   :							str						  =np.random.randint(1					,						2**num_qubits							)
      # Next, format 'b' as a binary string of length 'n', padded with zeros:
      snake_case   :							int						  =format(lowerCamelCase_					,						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(lowerCamelCase_							):
         if bit == "1":
            oracle_qc.x(lowerCamelCase_							)
        # Do the controlled-NOT gates for each qubit, using the output qubit
        # as the target:
      for index in range(lowerCamelCase_							):
         oracle_qc.cx(lowerCamelCase_					,						lowerCamelCase_							)
      # Next, place the final X-gates
      for index, bit in enumerate(lowerCamelCase_							):
         if bit == "1":
            oracle_qc.x(lowerCamelCase_							)

    # 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)
      snake_case   :							Tuple						  =np.random.randint(2							)
      if output == 1:
         oracle_qc.x(lowerCamelCase_							)

   snake_case   :							Union[str, Any]						  =oracle_qc.to_gate()
   snake_case   :							Optional[int]						  ='''Oracle'''  # To show when we display the circuit
   return oracle_gate
def 		_a   (  lowerCamelCase_					,						lowerCamelCase_							):
   snake_case   :							Union[str, Any]						  =qiskit.QuantumCircuit(num_qubits + 1					,						lowerCamelCase_							)
   # Set up the output qubit:
   dj_circuit.x(lowerCamelCase_							)
   dj_circuit.h(lowerCamelCase_							)
   # And set up the input register:
   for qubit in range(lowerCamelCase_							):
      dj_circuit.h(lowerCamelCase_							)
   # Let's append the oracle gate to our circuit:
   dj_circuit.append(lowerCamelCase_					,						range(num_qubits + 1							)							)
   # Finally, perform the H-gates again and measure:
   for qubit in range(lowerCamelCase_							):
      dj_circuit.h(lowerCamelCase_							)

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

   return dj_circuit
def 		_a   (  lowerCamelCase_					,						lowerCamelCase_							):
   snake_case   :							Tuple						  =qiskit.Aer.get_backend('''aer_simulator'''							)

   snake_case   :							List[str]						  =dj_oracle(lowerCamelCase_					,						lowerCamelCase_							)
   snake_case   :							List[str]						  =dj_algorithm(lowerCamelCase_					,						lowerCamelCase_							)

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

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


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 doctest

import projectq
from projectq.ops import H, Measure
def 		_a   (  lowerCamelCase_							):
   snake_case   :							str						  =quantum_engine.allocate_qubit()
   H | qubit
   Measure | qubit
   return int(lowerCamelCase_							)


if __name__ == "__main__":
      doctest.testmod()

      # initialises a new quantum backend
      A			:   Dict			=      projectq.MainEngine()

      # Generate a list of 10 random numbers
      A			:   Dict			=      [get_random_number(quantum_engine) for _ in range(10)]

      # Flushes the quantum engine from memory
      quantum_engine.flush()

      print("""Random numbers""", random_numbers_list)





