# Importing standard Qiskit libraries
from qiskit import QuantumCircuit, execute, Aer
from qiskit.visualization import *
from qiskit.quantum_info import state_fidelity
# Magic function to render plots in the notebook after the cell executing the plot command
%matplotlib inline

def run_on_qasm_simulator(quantum_circuit, num_shots):
    """Takes a circuit, the number of shots and a backend and returns the counts for running the circuit
    on the qasm_simulator backend."""
    qasm_simulator = Aer.get_backend('qasm_simulator')
    job = execute(quantum_circuit, backend=qasm_simulator, shots=num_shots)
    result = job.result()
    counts = result.get_counts(quantum_circuit)
    return counts

def oracle_f1():
    "Oracle implementing function f1"
    qc = QuantumCircuit(3)
    qc.cnot(0,2)    
    qc.cnot(1,2)    
    qc.x(2)
    qc.cnot(1,2)    
    qc.cnot(0,2)    
    return qc

def oracle_f2():
    "Oracle implementing function f2"
    qc = QuantumCircuit(3)
    qc.cnot(0,2)
    qc.x(2)
    qc.cnot(1,2)
    return qc

# We visualize the oracle


# Create a quantum circuit for 3 qubits and 2 classical registers
qc_deutch_josza_oracle1 = QuantumCircuit(3,2)
# Add the Hadamard gate

# Apply the oracle

# Add the z-gate acting on the ancilla

# Apply the oracle again

# Add the Hadamard gate

# Add measurement to the first two qubits
qc_deutch_josza_oracle1.barrier()
qc_deutch_josza_oracle1.measure(range(2),range(2))
# Visualize the circuit


# The number of shots we use
num_shots = 100
# Now we run the circuit

# Visualize the results in form of a histogram


# We visualize the oracle


# Create a quantum circuit for 3 qubits and 2 classical registers
qc_deutch_josza_oracle2 = QuantumCircuit(3,2)
# Add the Hadamard gate

# Apply the oracle

# Add the z-gate acting on the ancilla

# Apply the oracle again

# Add the Hadamard gate

# Add measurement to the first two qubits

# Visualize the circuit


# The number of shots we use
num_shots = 100
# Now we run the circuit

# Visualize the results in form of a histogram
