'''simple docstring'''




import numpy as np
import qiskit





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

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

    A_     =   oracle_qc.to_gate()
    A_     =   '''Oracle'''  # To show when we display the circuit
    return oracle_gate





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

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

    return dj_circuit





def      _UpperCAmelCase    (							_UpperCamelCase    :	str,   _UpperCamelCase    :	int   )	->      qiskit.result.counts.Counts:
    A_     =   qiskit.Aer.get_backend('''aer_simulator'''   )

    A_     =   dj_oracle(_UpperCamelCase,   _UpperCamelCase   )
    A_     =   dj_algorithm(_UpperCamelCase,   _UpperCamelCase   )

    # Execute the circuit on the simulator
    A_     =   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"""Deutsch Jozsa - Constant Oracle: {deutsch_jozsa('constant', 3)}""")
  print(F"""Deutsch Jozsa - Balanced Oracle: {deutsch_jozsa('balanced', 3)}""")







'''simple docstring'''




from scipy.constants import g





def      _UpperCAmelCase    (							_UpperCamelCase    :	float,   _UpperCamelCase    :	float   )	->      float:
    if mass < 0:
        # handling of negative values of mass
        raise ValueError('''The mass of a body cannot be negative'''   )
    if height < 0:
        # handling of negative values of height
        raise ValueError('''The height above the ground cannot be negative'''   )
    return mass * g * height


if __name__ == "__main__":
  from doctest import testmod

  testmod(name='potential_energy')






