Repository: Qiskit/qiskit

Issue:
removing tools/apps
<!-- ⚠️ If you do not respect this template, your issue will be closed -->
<!-- ⚠️ Make sure to browse the opened and closed issues to confirm this idea does not exist. -->

### What is the expected enhancement?
I am going to try the issues first approach :-) 

I will work on a pull request to remove the openquantumcompiler and the tools/apps. This is low priority and is not in the main updates for next release so we dont need to track

I will do these as two seperate pull requests. 


Discussion:
the opencompiler is remove. 

New is to remove the tools/apps does anyone see any problem in removing them and if comments come up we suggest they use acqua. 
Chopping unused and redundant parts is always welcome, thanks Jay! Perhaps it would make sense to aim for the removal of `tools/apps` along with 0.6? I think the tutorials might be their main visible users, and this way we can include the change in a major version in a clean-ish way.
Sure I agree that this should not be part of 0.5.6
Any news about this? The idea is to move them to Aqua?
@chunfuchen this is the issue for removing the tools/app when you do the pr just link to this one.

Resolving patch:
diff --git a/qiskit/tools/apps/__init__.py b/qiskit/tools/apps/__init__.py
deleted file mode 100644
diff --git a/qiskit/tools/apps/fermion.py b/qiskit/tools/apps/fermion.py
deleted file mode 100644
--- a/qiskit/tools/apps/fermion.py
+++ /dev/null
@@ -1,362 +0,0 @@
-# -*- coding: utf-8 -*-
-
-# Copyright 2017, IBM.
-#
-# This source code is licensed under the Apache License, Version 2.0 found in
-# the LICENSE.txt file in the root directory of this source tree.
-
-"""
-A set of functions to map fermionic Hamiltonians to qubit Hamiltonians.
-
-References:
-- E. Wigner and P. Jordan., Über das Paulische Äguivalenzverbot,
-    Z. Phys., 47:631 (1928).
-- S. Bravyi and A. Kitaev. Fermionic quantum computation,
-    Ann. of Phys., 298(1):210–226 (2002).
-- A. Tranter, S. Sofia, J. Seeley, M. Kaicher, J. McClean, R. Babbush,
-    P. Coveney, F. Mintert, F. Wilhelm, and P. Love. The Bravyi–Kitaev
-    transformation: Properties and applications. Int. Journal of Quantum
-    Chemistry, 115(19):1431–1441 (2015).
-- S. Bravyi, J. M. Gambetta, A. Mezzacapo, and K. Temme,
-    arXiv e-print arXiv:1701.08213 (2017).
-
-"""
-import numpy as np
-
-from qiskit.tools.apps.optimization import Hamiltonian_from_file
-from qiskit.tools.qi.pauli import Pauli, sgn_prod
-
-
-def parity_set(j, n):
-    """Computes the parity set of the j-th orbital in n modes
-
-    Args:
-        j (int) : the orbital index
-        n (int) : the total number of modes
-    Returns:
-        numpy.array: Array of mode indexes
-    """
-    indexes = np.array([])
-    if n % 2 == 0:
-        if j < n / 2:
-            indexes = np.append(indexes, parity_set(j, n / 2))
-        else:
-            indexes = np.append(indexes, np.append(
-                parity_set(j - n / 2, n / 2) + n / 2, n / 2 - 1))
-    return indexes
-
-
-def update_set(j, n):
-    """Computes the update set of the j-th orbital in n modes
-
-    Args:
-        j (int) : the orbital index
-        n (int) : the total number of modes
-    Returns:
-        numpy.array: Array of mode indexes
-    """
-    indexes = np.array([])
-    if n % 2 == 0:
-        if j < n / 2:
-            indexes = np.append(indexes, np.append(
-                n - 1, update_set(j, n / 2)))
-        else:
-            indexes = np.append(indexes, update_set(j - n / 2, n / 2) + n / 2)
-    return indexes
-
-
-def flip_set(j, n):
-    """Computes the flip set of the j-th orbital in n modes
-
-    Args:
-        j (int) : the orbital index
-        n (int) : the total number of modes
-    Returns:
-        numpy.array: Array of mode indexes
-    """
-    indexes = np.array([])
-    if n % 2 == 0:
-        if j < n / 2:
-            indexes = np.append(indexes, flip_set(j, n / 2))
-        elif j >= n / 2 and j < n - 1:
-            indexes = np.append(indexes, flip_set(j - n / 2, n / 2) + n / 2)
-        else:
-            indexes = np.append(np.append(indexes, flip_set(
-                j - n / 2, n / 2) + n / 2), n / 2 - 1)
-    return indexes
-
-
-def pauli_term_append(pauli_term, pauli_list, threshold):
-    """Appends a Pauli term to a Pauli list
-
-    If pauli_term is already present in the list adjusts the coefficient
-    of the existing pauli. If the new coefficient is less than
-    threshold the pauli term is deleted from the list
-
-    Args:
-        pauli_term (list): list of [coeff, pauli]
-        pauli_list (list): a list of pauli_terms
-        threshold (float): simplification threshold
-    Returns:
-        list: an updated pauli_list
-    """
-    found = False
-    if np.absolute(pauli_term[0]) > threshold:
-        if pauli_list:   # if the list is not empty
-            for i, _ in enumerate(pauli_list):
-                # check if the new pauli belongs to the list
-                if pauli_list[i][1] == pauli_term[1]:
-                    # if found renormalize the coefficient of existent pauli
-                    pauli_list[i][0] += pauli_term[0]
-                    # remove the element if coeff. value is now less than
-                    # threshold
-                    if np.absolute(pauli_list[i][0]) < threshold:
-                        del pauli_list[i]
-                    found = True
-                    break
-            if found is False:       # if not found add the new pauli
-                pauli_list.append(pauli_term)
-        else:
-            # if list is empty add the new pauli
-            pauli_list.append(pauli_term)
-    return pauli_list
-
-
-def fermionic_maps(h1, h2, map_type, out_file=None, threshold=0.000000000001):
-    """Creates a list of Paulis with coefficients from fermionic one and
-    two-body operator.
-
-    Args:
-        h1 (list): second-quantized fermionic one-body operator
-        h2 (list): second-quantized fermionic two-body operator
-        map_type (str): "JORDAN_WIGNER", "PARITY", "BINARY_TREE"
-        out_file (str): name of the optional file to write the Pauli list on
-        threshold (float): threshold for Pauli simplification
-    Returns:
-        list: A list of Paulis with coefficients
-    """
-    # pylint: disable=invalid-name
-
-    ####################################################################
-    # ###########   DEFINING MAPPED FERMIONIC OPERATORS    #############
-    ####################################################################
-
-    pauli_list = []
-    n = len(h1)  # number of fermionic modes / qubits
-    a = []
-    if map_type == 'JORDAN_WIGNER':
-        for i in range(n):
-            xv = np.append(np.append(np.ones(i), 0), np.zeros(n - i - 1))
-            xw = np.append(np.append(np.zeros(i), 1), np.zeros(n - i - 1))
-            yv = np.append(np.append(np.ones(i), 1), np.zeros(n - i - 1))
-            yw = np.append(np.append(np.zeros(i), 1), np.zeros(n - i - 1))
-            # defines the two mapped Pauli components of a_i and a_i^\dag,
-            # according to a_i -> (a[i][0]+i*a[i][1])/2,
-            # a_i^\dag -> (a_[i][0]-i*a[i][1])/2
-            a.append((Pauli(xv, xw), Pauli(yv, yw)))
-    if map_type == 'PARITY':
-        for i in range(n):
-            if i > 1:
-                Xv = np.append(np.append(np.zeros(i - 1),
-                                         [1, 0]), np.zeros(n - i - 1))
-                Xw = np.append(np.append(np.zeros(i - 1),
-                                         [0, 1]), np.ones(n - i - 1))
-                Yv = np.append(np.append(np.zeros(i - 1),
-                                         [0, 1]), np.zeros(n - i - 1))
-                Yw = np.append(np.append(np.zeros(i - 1),
-                                         [0, 1]), np.ones(n - i - 1))
-            elif i > 0:
-                Xv = np.append((1, 0), np.zeros(n - i - 1))
-                Xw = np.append([0, 1], np.ones(n - i - 1))
-                Yv = np.append([0, 1], np.zeros(n - i - 1))
-                Yw = np.append([0, 1], np.ones(n - i - 1))
-            else:
-                Xv = np.append(0, np.zeros(n - i - 1))
-                Xw = np.append(1, np.ones(n - i - 1))
-                Yv = np.append(1, np.zeros(n - i - 1))
-                Yw = np.append(1, np.ones(n - i - 1))
-            # defines the two mapped Pauli components of a_i and a_i^\dag,
-            # according to a_i -> (a[i][0]+i*a[i][1])/2,
-            # a_i^\dag -> (a_[i][0]-i*a[i][1])/2
-            a.append((Pauli(Xv, Xw), Pauli(Yv, Yw)))
-    if map_type == 'BINARY_TREE':
-        # FIND BINARY SUPERSET SIZE
-        bin_sup = 1
-        while n > np.power(2, bin_sup):
-            bin_sup += 1
-        # DEFINE INDEX SETS FOR EVERY FERMIONIC MODE
-        update_sets = []
-        update_pauli = []
-
-        parity_sets = []
-        parity_pauli = []
-
-        flip_sets = []
-
-        remainder_sets = []
-        remainder_pauli = []
-        for j in range(n):
-
-            update_sets.append(update_set(j, np.power(2, bin_sup)))
-            update_sets[j] = update_sets[j][update_sets[j] < n]
-
-            parity_sets.append(parity_set(j, np.power(2, bin_sup)))
-            parity_sets[j] = parity_sets[j][parity_sets[j] < n]
-
-            flip_sets.append(flip_set(j, np.power(2, bin_sup)))
-            flip_sets[j] = flip_sets[j][flip_sets[j] < n]
-
-            remainder_sets.append(np.setdiff1d(parity_sets[j], flip_sets[j]))
-
-            update_pauli.append(Pauli(np.zeros(n), np.zeros(n)))
-            parity_pauli.append(Pauli(np.zeros(n), np.zeros(n)))
-            remainder_pauli.append(Pauli(np.zeros(n), np.zeros(n)))
-            for k in range(n):
-                if np.in1d(k, update_sets[j]):
-                    update_pauli[j].w[k] = 1
-                if np.in1d(k, parity_sets[j]):
-                    parity_pauli[j].v[k] = 1
-                if np.in1d(k, remainder_sets[j]):
-                    remainder_pauli[j].v[k] = 1
-
-            x_j = Pauli(np.zeros(n), np.zeros(n))
-            x_j.w[j] = 1
-            y_j = Pauli(np.zeros(n), np.zeros(n))
-            y_j.v[j] = 1
-            y_j.w[j] = 1
-            # defines the two mapped Pauli components of a_i and a_i^\dag,
-            # according to a_i -> (a[i][0]+i*a[i][1])/2, a_i^\dag ->
-            # (a_[i][0]-i*a[i][1])/2
-            a.append((update_pauli[j] * x_j * parity_pauli[j],
-                      update_pauli[j] * y_j * remainder_pauli[j]))
-
-    ####################################################################
-    # ###########    BUILDING THE MAPPED HAMILTONIAN     ###############
-    ####################################################################
-
-    # ######################    One-body    #############################
-    for i in range(n):
-        for j in range(n):
-            if h1[i, j] != 0:
-                for alpha in range(2):
-                    for beta in range(2):
-                        pauli_prod = sgn_prod(a[i][alpha], a[j][beta])
-                        pauli_term = [h1[i, j] * 1 / 4 * pauli_prod[1] *
-                                      np.power(-1j, alpha) *
-                                      np.power(1j, beta),
-                                      pauli_prod[0]]
-                        pauli_list = pauli_term_append(
-                            pauli_term, pauli_list, threshold)
-
-    # ######################    Two-body    ############################
-    for i in range(n):
-        for j in range(n):
-            for k in range(n):
-                for m in range(n):
-                    if h2[i, j, k, m] != 0:
-                        for alpha in range(2):
-                            for beta in range(2):
-                                for gamma in range(2):
-                                    for delta in range(2):
-                                        # Note: chemists' notation for the
-                                        # labeling,
-                                        # h2(i,j,k,m) adag_i adag_k a_m a_j
-                                        pauli_prod_1 = sgn_prod(
-                                            a[i][alpha], a[k][beta])
-                                        pauli_prod_2 = sgn_prod(
-                                            pauli_prod_1[0], a[m][gamma])
-                                        pauli_prod_3 = sgn_prod(
-                                            pauli_prod_2[0], a[j][delta])
-
-                                        phase1 = pauli_prod_1[1] *\
-                                            pauli_prod_2[1] * pauli_prod_3[1]
-                                        phase2 = np.power(-1j, alpha + beta) *\
-                                            np.power(1j, gamma + delta)
-
-                                        pauli_term = [
-                                            h2[i, j, k, m] * 1 / 16 * phase1 *
-                                            phase2, pauli_prod_3[0]]
-
-                                        pauli_list = pauli_term_append(
-                                            pauli_term, pauli_list, threshold)
-
-    ####################################################################
-    # ################          WRITE TO FILE         ##################
-    ####################################################################
-
-    if out_file is not None:
-        out_stream = open(out_file, 'w')
-        for pauli_term in pauli_list:
-            out_stream.write(pauli_term[1].to_label() + '\n')
-            out_stream.write('%.15f' % pauli_term[0].real + '\n')
-        out_stream.close()
-    return pauli_list
-
-
-def two_qubit_reduction(ham_in, m, out_file=None, threshold=0.000000000001):
-    """
-    Eliminates the central and last qubit in a list of Pauli that has
-    diagonal operators (Z,I) at those positions.abs
-
-    It can be used to taper two qubits in parity and binary-tree mapped
-    fermionic Hamiltonians when the spin orbitals are ordered in two spin
-    sectors, according to the number of particles in the system.
-
-    Args:
-        ham_in (list): a list of Paulis representing the mapped fermionic
-            Hamiltonian
-        m (int): number of fermionic particles
-        out_file (string or None): name of the optional file to write the Pauli
-            list on
-        threshold (float): threshold for Pauli simplification
-    Returns:
-        list: A tapered Hamiltonian in the form of list of Paulis with
-            coefficients
-    """
-    ham_out = []
-    if m % 4 == 0:
-        par_1 = 1
-        par_2 = 1
-    elif m % 4 == 1:
-        par_1 = -1
-        par_2 = -1    # could be also +1, +1/-1 are  spin-parity sectors
-    elif m % 4 == 2:
-        par_1 = 1
-        par_2 = -1
-    else:
-        par_1 = -1
-        par_2 = -1    # could be also +1, +1/-1 are  spin-parity sectors
-    if isinstance(ham_in, str):
-        # conversion from Hamiltonian text file to pauli_list
-        ham_in = Hamiltonian_from_file(ham_in)
-    # number of qubits
-    n = len(ham_in[0][1].v)
-    for pauli_term in ham_in:  # loop over Pauli terms
-        coeff_out = pauli_term[0]
-        # Z operator encountered at qubit n/2-1
-        if pauli_term[1].v[n // 2 -
-                           1] == 1 and pauli_term[1].w[n // 2 - 1] == 0:
-            coeff_out = par_2 * coeff_out
-        # Z operator encountered at qubit n-1
-        if pauli_term[1].v[n - 1] == 1 and pauli_term[1].w[n - 1] == 0:
-            coeff_out = par_1 * coeff_out
-        v_temp = []
-        w_temp = []
-        for j in range(n):
-            if j != n // 2 - 1 and j != n - 1:
-                v_temp.append(pauli_term[1].v[j])
-                w_temp.append(pauli_term[1].w[j])
-        pauli_term_out = [coeff_out, Pauli(v_temp, w_temp)]
-        ham_out = pauli_term_append(pauli_term_out, ham_out, threshold)
-
-    ####################################################################
-    # ################          WRITE TO FILE         ##################
-    ####################################################################
-
-    if out_file is not None:
-        out_stream = open(out_file, 'w')
-        for pauli_term in ham_out:
-            out_stream.write(pauli_term[1].to_label() + '\n')
-            out_stream.write('%.15f' % pauli_term[0].real + '\n')
-        out_stream.close()
-    return ham_out
diff --git a/qiskit/tools/apps/optimization.py b/qiskit/tools/apps/optimization.py
deleted file mode 100644
--- a/qiskit/tools/apps/optimization.py
+++ /dev/null
@@ -1,479 +0,0 @@
-# -*- coding: utf-8 -*-
-# pylint: disable=unused-import,invalid-name
-
-# Copyright 2018, IBM.
-#
-# This source code is licensed under the Apache License, Version 2.0 found in
-# the LICENSE.txt file in the root directory of this source tree.
-
-"""
-These are tools that are used in the classical optimization and chemistry
-tutorials
-"""
-import copy
-import numpy as np
-
-from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
-from qiskit import execute
-from qiskit.extensions.standard import h, ry, barrier, cz, x, y, z
-from qiskit.tools.qi.pauli import Pauli, label_to_pauli
-
-
-def SPSA_optimization(obj_fun, initial_theta, SPSA_parameters, max_trials,
-                      save_steps=1, last_avg=1):
-    """Minimizes obj_fun(theta) with a simultaneous perturbation stochastic
-    approximation algorithm.
-
-    Args:
-        obj_fun (callable): the function to minimize
-        initial_theta (numpy.array): initial value for the variables of
-            obj_fun
-        SPSA_parameters (list[float]) :  the parameters of the SPSA
-            optimization routine
-        max_trials (int) : the maximum number of trial steps ( = function
-            calls/2) in the optimization
-        save_steps (int) : stores optimization outcomes each 'save_steps'
-            trial steps
-        last_avg (int) : number of last updates of the variables to average
-            on for the final obj_fun
-    Returns:
-        list: a list with the following elements:
-            cost_final : final optimized value for obj_fun
-            theta_best : final values of the variables corresponding to
-                cost_final
-            cost_plus_save : array of stored values for obj_fun along the
-                optimization in the + direction
-            cost_minus_save : array of stored values for obj_fun along the
-                optimization in the - direction
-            theta_plus_save : array of stored variables of obj_fun along the
-                optimization in the + direction
-            theta_minus_save : array of stored variables of obj_fun along the
-                optimization in the - direction
-        list[QuantumCircuit]: the circuits used in optimization
-    """
-
-    theta_plus_save = []
-    theta_minus_save = []
-    cost_plus_save = []
-    cost_minus_save = []
-    theta = initial_theta
-    theta_best = np.zeros(initial_theta.shape)
-    circuits = []
-    for k in range(max_trials):
-        # SPSA Parameters
-        a_spsa = float(SPSA_parameters[0]) / np.power(k + 1 +
-                                                      SPSA_parameters[4],
-                                                      SPSA_parameters[2])
-        c_spsa = float(SPSA_parameters[1]) / np.power(k + 1,
-                                                      SPSA_parameters[3])
-        delta = 2 * np.random.randint(2, size=np.shape(initial_theta)[0]) - 1
-        # plus and minus directions
-        theta_plus = theta + c_spsa * delta
-        theta_minus = theta - c_spsa * delta
-        # cost fuction for the two directions
-        cost_plus, circuits_plus = obj_fun(theta_plus)
-        cost_minus, circuits_minus = obj_fun(theta_minus)
-        # derivative estimate
-        g_spsa = (cost_plus - cost_minus) * delta / (2.0 * c_spsa)
-        # updated theta
-        theta = theta - a_spsa * g_spsa
-        # saving
-        if k % save_steps == 0:
-            print('objective function at theta+ for step # ' + str(k))
-            print("%.7f" % cost_plus)
-            print(('objective function at theta- for step # ' + str(k)))
-            print("%.7f" % cost_minus)
-            theta_plus_save.append(theta_plus)
-            theta_minus_save.append(theta_minus)
-            cost_plus_save.append(cost_plus)
-            cost_minus_save.append(cost_minus)
-        # record circuits ran
-        circuits += circuits_plus
-        circuits += circuits_minus
-
-        if k >= max_trials - last_avg:
-            theta_best += theta / last_avg
-
-    # final cost update
-    cost_final, circuits_final = obj_fun(theta_best)
-    circuits += circuits_final
-    print('Final objective function is: %.7f' % cost_final)
-    return [cost_final, theta_best, cost_plus_save, cost_minus_save,
-            theta_plus_save, theta_minus_save], circuits
-
-
-def SPSA_calibration(obj_fun, initial_theta, initial_c, target_update, stat):
-    """Calibrates and returns the SPSA parameters.
-
-    Args:
-        obj_fun (callable): the function to minimize.
-        initial_theta (numpy.array): initial value for the variables of
-            obj_fun.
-        initial_c (float) : first perturbation of intitial_theta.
-        target_update (float) : the aimed update of variables on the first
-            trial step.
-        stat (int) : number of random gradient directions to average on in
-            the calibration.
-    Returns:
-        numpy.array: An array of 5 SPSA_parameters to use in the optimization.
-        list[QuantumCircuit]: the circuits used in calibration
-    """
-
-    SPSA_parameters = np.zeros((5))
-    SPSA_parameters[1] = initial_c
-    SPSA_parameters[2] = 0.602
-    SPSA_parameters[3] = 0.101
-    SPSA_parameters[4] = 0
-    delta_obj = 0
-    circuits = []
-    for i in range(stat):
-        if i % 5 == 0:
-            print('calibration step # ' + str(i) + ' of ' + str(stat))
-
-        delta = 2 * np.random.randint(2, size=np.shape(initial_theta)[0]) - 1
-        obj_plus, circuits_plus = obj_fun(initial_theta + initial_c * delta)
-        obj_minus, circuits_minus = obj_fun(initial_theta - initial_c * delta)
-        delta_obj += np.absolute(obj_plus - obj_minus) / stat
-        circuits += circuits_plus
-        circuits += circuits_minus
-
-    SPSA_parameters[0] = target_update * 2 / delta_obj \
-        * SPSA_parameters[1] * (SPSA_parameters[4] + 1)
-
-    print('calibrated SPSA_parameters[0] is %.7f' % SPSA_parameters[0])
-
-    return SPSA_parameters, circuits
-
-
-def measure_pauli_z(data, pauli):
-    """Compute the expectation value of Z.
-
-    Z is represented by Z^v where v has length number of qubits and is 1
-    if Z is present and 0 otherwise.
-
-    Args:
-        data (dict): a dictionary of the form data = {'00000': 10}
-        pauli (Pauli): a Pauli object
-    Returns:
-        float: Expected value of pauli given data
- """
-    observable = 0
-    tot = sum(data.values())
-    for key in data:
-        value = 1
-        for j in range(pauli.numberofqubits):
-            if ((pauli.v[j] == 1 or pauli.w[j] == 1) and
-                    key[pauli.numberofqubits - j - 1] == '1'):
-                value = -value
-
-        observable = observable + value * data[key] / tot
-    return observable
-
-
-def Energy_Estimate(data, pauli_list):
-    """Compute expectation value of a list of diagonal Paulis with
-    coefficients given measurement data. If somePaulis are non-diagonal
-    appropriate post-rotations had to be performed in the collection of data
-
-    Args:
-        data (dict): output of the execution of a quantum program
-        pauli_list (list): list of [coeff, Pauli]
-    Returns:
-        float: The expectation value
-    """
-    energy = 0
-    if np.ndim(pauli_list) == 1:
-        energy = pauli_list[0] * measure_pauli_z(data, pauli_list[1])
-    else:
-        for p in pauli_list:
-            energy += p[0] * measure_pauli_z(data, p[1])
-    return energy
-
-
-def index_2_bit(state_index, num_bits):
-    """Returns bit string corresponding to quantum state index
-
-    Args:
-        state_index (int): basis index of a quantum state
-        num_bits (int): the number of bits in the returned string
-    Returns:
-        numpy.array: A integer array with the binary representation of
-            state_index
-    """
-    return np.array([int(c) for c
-                     in np.binary_repr(state_index, num_bits)[::-1]],
-                    dtype=np.uint8)
-
-
-def group_paulis(pauli_list):
-    """
-    Groups a list of (coeff,Pauli) tuples into tensor product basis (tpb) sets
-
-    Args:
-        pauli_list (list): a list of (coeff, Pauli object) tuples.
-    Returns:
-        list: A list of tpb sets, each one being a list of (coeff, Pauli
-            object) tuples.
-    """
-    n = len(pauli_list[0][1].v)
-    pauli_list_grouped = []
-    pauli_list_sorted = []
-    for p_1 in pauli_list:
-        if p_1 not in pauli_list_sorted:
-            pauli_list_temp = []
-            # pauli_list_temp.extend(p_1) # this is going to signal the total
-            # post-rotations of the set (set master)
-            pauli_list_temp.append(list(p_1))
-            pauli_list_temp.append(copy.deepcopy(list(p_1)))
-            pauli_list_temp[0][0] = 0
-            for p_2 in pauli_list:
-                if p_2 not in pauli_list_sorted and p_1[1] != p_2[1]:
-                    j = 0
-                    for i in range(n):
-                        if not ((p_2[1].v[i] == 0 and p_2[1].w[i] == 0) or
-                                (p_1[1].v[i] == 0 and p_1[1].w[i] == 0) or
-                                (p_2[1].v[i] == p_1[1].v[i] and
-                                 p_2[1].w[i] == p_1[1].w[i])):
-                            break
-                        else:
-                            # update master
-                            if p_2[1].v[i] == 1 or p_2[1].w[i] == 1:
-                                pauli_list_temp[0][1].v[i] = p_2[1].v[i]
-                                pauli_list_temp[0][1].w[i] = p_2[1].w[i]
-
-                        j += 1
-
-                    if j == n:
-                        pauli_list_temp.append(p_2)
-                        pauli_list_sorted.append(p_2)
-            pauli_list_grouped.append(pauli_list_temp)
-
-    return pauli_list_grouped
-
-
-def print_pauli_list_grouped(pauli_list_grouped):
-    """Print a list of Pauli operators which has been grouped into tensor
-    product basis (tpb) sets.
-
-    Args:
-        pauli_list_grouped (list of lists of (coeff, pauli) tuples): the
-            list of Pauli operators grouped into tpb sets
-    """
-    for i, _ in enumerate(pauli_list_grouped):
-        print('Post Rotations of TPB set ' + str(i) + ':')
-        print(pauli_list_grouped[i][0][1].to_label())
-        print(str(pauli_list_grouped[i][0][0]) + '\n')
-        for j in range((len(pauli_list_grouped[i]) - 1)):
-            print(pauli_list_grouped[i][j + 1][1].to_label())
-            print("%.7f" % pauli_list_grouped[i][j + 1][0])
-
-        print('\n')
-
-
-def eval_hamiltonian(hamiltonian, input_circuit, shots, device):
-    """Calculates the average value of a Hamiltonian on a state created by the
-     input circuit
-
-    Args:
-        hamiltonian (array or matrix or list): a representation of the
-            Hamiltonian or observables to be measured. If it is a list, it is
-            a list of Pauli operators grouped into tpb sets.
-        input_circuit (QuantumCircuit): input circuit.
-        shots (int): number of shots considered in the averaging. If 1 the
-            averaging is exact.
-        device (str): the backend used to run the simulation.
-    Returns:
-        float: Average value of the Hamiltonian or observable.
-    """
-    energy = 0
-    circuits = []
-
-    if 'statevector' in device:
-        circuits.append(input_circuit)
-        # Hamiltonian is not a pauli_list grouped into tpb sets
-        if not isinstance(hamiltonian, list):
-            result = execute(circuits, device, shots=shots).result()
-            statevector = result.get_statevector()
-            # Diagonal Hamiltonian represented by 1D array
-            if (hamiltonian.shape[0] == 1 or
-                    np.shape(np.shape(np.array(hamiltonian))) == (1,)):
-                energy = np.sum(hamiltonian * np.absolute(statevector) ** 2)
-            # Hamiltonian represented by square matrix
-            elif hamiltonian.shape[0] == hamiltonian.shape[1]:
-                energy = np.inner(np.conjugate(statevector),
-                                  np.dot(hamiltonian, statevector))
-        # Hamiltonian represented by a Pauli list
-        else:
-            # Execute trial circuit with final rotations for each Pauli in
-            # hamiltonian and store from circuits[1] on
-            n_qubits = input_circuit.regs['q'].size
-            q = QuantumRegister(n_qubits, "q")
-            i = 1
-            for p in hamiltonian:
-                circuits.append(copy.deepcopy(input_circuit))
-                for j in range(n_qubits):
-                    if p[1].v[j] == 0 and p[1].w[j] == 1:
-                        circuits[i].x(q[j])
-                    elif p[1].v[j] == 1 and p[1].w[j] == 0:
-                        circuits[i].z(q[j])
-                    elif p[1].v[j] == 1 and p[1].w[j] == 1:
-                        circuits[i].y(q[j])
-                i += 1
-            result = execute(circuits, device, shots=shots).result()
-            # no Pauli final rotations
-            statevector_0 = result.get_statevector(circuits[0])
-            i = 1
-            for p in hamiltonian:
-                statevector_i = result.get_statevector(circuits[i])
-                # inner product with final rotations of (i-1)-th Pauli
-                energy += p[0] * np.inner(np.conjugate(statevector_0),
-                                          statevector_i)
-                i += 1
-    # finite number of shots and hamiltonian grouped in tpb sets
-    else:
-        n = int(len(hamiltonian[0][0][1].v))
-        q = QuantumRegister(n, "q")
-        c = ClassicalRegister(n, "c")
-        i = 0
-        for tpb_set in hamiltonian:
-            circuits.append(copy.deepcopy(input_circuit))
-            for j in range(n):
-                # Measure X
-                if tpb_set[0][1].v[j] == 0 and tpb_set[0][1].w[j] == 1:
-                    circuits[i].h(q[j])
-                # Measure Y
-                elif tpb_set[0][1].v[j] == 1 and tpb_set[0][1].w[j] == 1:
-                    circuits[i].s(q[j]).inverse()
-                    circuits[i].h(q[j])
-                circuits[i].measure(q[j], c[j])
-            i += 1
-        result = execute(circuits, device, shots=shots).result()
-        for j, _ in enumerate(hamiltonian):
-            for k, _ in enumerate(hamiltonian[j]):
-                energy += hamiltonian[j][k][0] *\
-                    measure_pauli_z(result.get_counts(circuits[j]),
-                                    hamiltonian[j][k][1])
-
-    return energy, circuits
-
-
-def trial_circuit_ry(n, m, theta, entangler_map, meas_string=None,
-                     measurement=True):
-    """Creates a QuantumCircuit object ocnsisting in layers of
-    parametrized single-qubit Y rotations and CZ two-qubit gates
-
-    Args:
-        n (int): number of qubits
-        m (int): depth of the circuit
-        theta (array[float]): angles that parametrize the Y rotations
-        entangler_map (dict): CZ connectivity, e.g. {0: [1], 1: [2]}
-        meas_string (str): measure a given Pauli operator at the end of the
-            circuit
-        measurement (bool): whether to measure the qubit (register "q")
-            on classical bits (register "c")
-    Returns:
-        QuantumCircuit: A QuantumCircuit object
-    """
-    q = QuantumRegister(n, "q")
-    c = ClassicalRegister(n, "c")
-    trial_circuit = QuantumCircuit(q, c)
-    trial_circuit.h(q)
-    if meas_string is None:
-        meas_string = [None for x in range(n)]
-    for i in range(m):
-        trial_circuit.barrier(q)
-        for node in entangler_map:
-            for j in entangler_map[node]:
-                trial_circuit.cz(q[node], q[j])
-        for j in range(n):
-            trial_circuit.ry(theta[n * i + j], q[j])
-    trial_circuit.barrier(q)
-    for j in range(n):
-        if meas_string[j] == 'X':
-            trial_circuit.h(q[j])
-        elif meas_string[j] == 'Y':
-            trial_circuit.s(q[j]).inverse()
-            trial_circuit.h(q[j])
-    if measurement:
-        for j in range(n):
-            trial_circuit.measure(q[j], c[j])
-    return trial_circuit
-
-
-def trial_circuit_ryrz(n, m, theta, entangler_map, meas_string=None,
-                       measurement=True):
-    """Creates a QuantumCircuit object consisting in layers of
-    parametrized single-qubit Y and Z rotations and CZ two-qubit gates
-
-    Args:
-        n (int): number of qubits
-        m (int): depth of the circuit
-        theta (array[float]): angles that parametrize the Y and Z rotations
-        entangler_map (dict): CZ connectivity, e.g. {0: [1], 1: [2]}
-        meas_string (str): measure a given Pauli operator at the end of the
-            circuit
-        measurement (bool): whether to measure the qubit (register "q")
-            on classical bits (register "c")
-    Returns:
-        QuantumCircuit: A QuantumCircuit object
-    """
-    q = QuantumRegister(n, "q")
-    c = ClassicalRegister(n, "c")
-    trial_circuit = QuantumCircuit(q, c)
-    trial_circuit.h(q)
-    if meas_string is None:
-        meas_string = [None for x in range(n)]
-    for i in range(m):
-        trial_circuit.barrier(q)
-        for node in entangler_map:
-            for j in entangler_map[node]:
-                trial_circuit.cz(q[node], q[j])
-        for j in range(n):
-            trial_circuit.ry(theta[n * i * 2 + 2 * j], q[j])
-            trial_circuit.rz(theta[n * i * 2 + 2 * j + 1], q[j])
-    trial_circuit.barrier(q)
-    for j in range(n):
-        if meas_string[j] == 'X':
-            trial_circuit.h(q[j])
-        elif meas_string[j] == 'Y':
-            trial_circuit.s(q[j]).inverse()
-            trial_circuit.h(q[j])
-    if measurement:
-        for j in range(n):
-            trial_circuit.measure(q[j], c[j])
-    return trial_circuit
-
-
-def make_Hamiltonian(pauli_list):
-    """Creates a matrix operator out of a list of Paulis.
-
-    Args:
-        pauli_list (list): list of list [coeff,Pauli]
-    Returns:
-        numpy.matrix: A matrix representing pauli_list
-    """
-    Hamiltonian = 0
-    for p in pauli_list:
-        Hamiltonian += p[0] * p[1].to_matrix()
-    return Hamiltonian
-
-
-def Hamiltonian_from_file(file_name):
-    """Creates a matrix operator out of a file with a list
-    of Paulis.
-
-    Args:
-        file_name (str): a text file containing a list of Paulis and
-        coefficients.
-    Returns:
-        list: A matrix representing pauli_list
-    """
-    with open(file_name, 'r+') as file:
-        ham_array = file.readlines()
-    ham_array = [x.strip() for x in ham_array]
-    pauli_list = []
-    for i in range(len(ham_array) // 2):
-        pauli = label_to_pauli(ham_array[2 * i])
-        Numb = float(ham_array[2 * i + 1])
-        pauli_list.append([Numb, pauli])
-    return pauli_list


Test patch:
diff --git a/test/python/test_apps.py b/test/python/test_apps.py
deleted file mode 100644
--- a/test/python/test_apps.py
+++ /dev/null
@@ -1,277 +0,0 @@
-# -*- coding: utf-8 -*-
-
-# Copyright 2017, IBM.
-#
-# This source code is licensed under the Apache License, Version 2.0 found in
-# the LICENSE.txt file in the root directory of this source tree.
-
-# pylint: disable=invalid-name
-
-"""Quick program to test the apps tools modules."""
-
-import unittest
-from unittest.mock import patch
-from io import StringIO
-from scipy import linalg as la
-import numpy as np
-
-from qiskit.tools.apps.optimization import make_Hamiltonian, Hamiltonian_from_file, group_paulis, \
-        trial_circuit_ry, print_pauli_list_grouped, Energy_Estimate
-from qiskit.tools.apps.fermion import parity_set, update_set, flip_set, fermionic_maps, \
-        two_qubit_reduction
-from qiskit.tools.qi.pauli import Pauli
-
-from .common import QiskitTestCase
-
-
-class TestQuantumOptimization(QiskitTestCase):
-    """Tests for quantum optimization"""
-
-    def test_trial_functions(self):
-        """trial_circuit_ry function"""
-        entangler_map = {0: [2], 1: [2], 3: [2], 4: [2]}
-
-        m = 1
-        n = 6
-        theta = np.zeros(m * n)
-
-        trial_circuit = trial_circuit_ry(n, m, theta, entangler_map)
-        qasm_txt = trial_circuit.qasm()
-        self.log.info(qasm_txt)
-        self.assertEqual(len(qasm_txt), 456)
-
-        self.log.info("With No measurement:\n")
-        trial_circuit = trial_circuit_ry(n, m, theta, entangler_map, None, None)
-        qasm_txt = trial_circuit.qasm()
-        self.log.info(qasm_txt)
-        self.assertEqual(len(qasm_txt), 324)
-
-        self.log.info("With Y measurement:\n")
-        meas_sting = ['Y' for x in range(n)]
-        trial_circuit = trial_circuit_ry(n, m, theta, entangler_map, meas_sting)
-        qasm_txt = trial_circuit.qasm()
-        self.log.info(qasm_txt)
-        self.assertEqual(len(qasm_txt), 564)
-
-    def test_group_paulis(self):
-        """ qiskit.tools.apps.optimization.group_paulis function"""
-        ham_name = self._get_resource_path("../performance/H2/H2Equilibrium.txt")
-        zz = np.array([0, 0])
-        oo = np.array([1, 1])
-
-        pauli_list = Hamiltonian_from_file(ham_name)
-        pauli_list_grouped = group_paulis(pauli_list)
-
-        self.assertEqual(len(pauli_list_grouped), 2)
-        r0 = [i[0] for i in pauli_list_grouped]
-        r1 = [i[1] for i in pauli_list_grouped]
-
-        self.assertEqual(len(r0), 2)
-        r00 = [i[0] for i in r0]
-        r01 = [i[1] for i in r0]
-        e01 = [Pauli(oo, zz), Pauli(zz, oo)]
-        self.assertEqual([0, 0], r00)
-        self.assertEqual(e01, r01)
-
-        self.assertEqual(len(r1), 2)
-        r10 = [i[0] for i in r1]
-        r11 = [i[1] for i in r1]
-        e11 = [Pauli(oo, zz), Pauli(zz, oo)]
-        self.assertEqual([0.011279956224107712, 0.18093133934472627], r10)
-        self.assertEqual(e11, r11)
-
-        expected_stout = ("Post Rotations of TPB set 0:\nZZ\n0\n\nZZ\n0.0112800\n"
-                          "II\n-1.0523761\nZI\n0.3979357\nIZ\n"
-                          "0.3979357\n\n\nPost Rotations of TPB set 1:\nXX\n0\n\n"
-                          "XX\n0.1809313")
-        with patch('sys.stdout', new=StringIO()) as fakeOutput:
-            print_pauli_list_grouped(pauli_list_grouped)
-
-        self.assertMultiLineEqual(fakeOutput.getvalue().strip(), expected_stout)
-
-
-class TestHamiltonian(QiskitTestCase):
-    """ Energy_Estimate and make_Hamiltonian functions """
-
-    def test_hamiltonian(self):
-        # pylint: disable=missing-docstring,unexpected-keyword-arg
-        # printing an example from a H2 file
-        hfile = self._get_resource_path("../performance/H2/H2Equilibrium.txt")
-        hamiltonian = make_Hamiltonian(Hamiltonian_from_file(hfile))
-        self.log.info(hamiltonian)
-        # [[-0.24522469381221926 0 0 0.18093133934472627 ]
-        # [0 -1.0636560168497590 0.18093133934472627 0]
-        # [0 0.18093133934472627 -1.0636560168497592 0]
-        # [0.18093133934472627 0 0 -1.8369675149908681]]
-
-        expected_result = [
-            [(-0.245224693812 + 0j), 0j, 0j, (0.180931339345 + 0j)],
-            [0j, (-1.06365601685 + 0j), (0.180931339345 + 0j), 0j],
-            [0j, (0.180931339345 + 0j), (-1.06365601685 + 0j), 0j],
-            [(0.180931339345 + 0j), 0j, 0j, (-1.83696751499 + 0j)]
-        ]
-
-        for i in range(4):
-            with self.subTest(i=i):
-                for result, expected in zip(hamiltonian[i], expected_result[i]):
-                    np.testing.assert_almost_equal(result, expected)
-
-        # printing an example from a graph input
-        n = 3
-        v0 = np.zeros(n)
-        v0[2] = 1
-        v1 = np.zeros(n)
-        v1[0] = 1
-        v1[1] = 1
-        v2 = np.zeros(n)
-        v2[0] = 1
-        v2[2] = 1
-        v3 = np.zeros(n)
-        v3[1] = 1
-        v3[2] = 1
-
-        pauli_list = [(1, Pauli(v0, np.zeros(n))), (1, Pauli(v1, np.zeros(n))),
-                      (1, Pauli(v2, np.zeros(n))), (1, Pauli(v3, np.zeros(n)))]
-        a = make_Hamiltonian(pauli_list)
-        self.log.info(a)
-
-        w, v = la.eigh(a, eigvals=(0, 0))
-        self.log.info(w)
-        self.log.info(v)
-
-        data = {'000': 10}
-        self.log.info(Energy_Estimate(data, pauli_list))
-        data = {'001': 10}
-        self.log.info(Energy_Estimate(data, pauli_list))
-        data = {'010': 10}
-        self.log.info(Energy_Estimate(data, pauli_list))
-        data = {'011': 10}
-        self.log.info(Energy_Estimate(data, pauli_list))
-        data = {'100': 10}
-        self.log.info(Energy_Estimate(data, pauli_list))
-        data = {'101': 10}
-        self.log.info(Energy_Estimate(data, pauli_list))
-        data = {'110': 10}
-        self.log.info(Energy_Estimate(data, pauli_list))
-        data = {'111': 10}
-        self.log.info(Energy_Estimate(data, pauli_list))
-
-
-class TestAppsFermion(QiskitTestCase):
-    """Tests for apps"""
-
-    def setUp(self):
-        self.j1 = 8
-        self.j2 = 3
-        self.j3 = 5
-        self.n = 10
-
-        self.a2 = np.arange(4).reshape(2, 2)
-        self.a5 = np.arange(16).reshape(2, 2, 2, 2)
-        self.e0 = [np.complex(-0.75, 0),
-                   np.complex(0.75, 0),
-                   np.complex(0, -0.25),
-                   np.complex(0, 0.25),
-                   np.complex(-1.5, 0),
-                   np.complex(1.5, 0)]
-        self.zz = np.array([0, 0])
-        self.oz = np.array([1, 0])
-        self.zo = np.array([0, 1])
-        self.oo = np.array([1, 1])
-
-    def test_parity_set(self):
-        """ qiskit.tools.apps.fermion.parity_set function"""
-        r = parity_set(self.j1, self.n)
-        self.assertEqual(r, [4.])
-        r = parity_set(self.j2, self.n)
-        self.assertEqual(r.size, 0)
-
-    def test_update_set(self):
-        """ qiskit.tools.apps.fermion.update_set function"""
-        r = update_set(self.j1, self.n)
-        self.assertEqual(r.size, 0)
-        r = update_set(self.j2, self.n)
-        self.assertEqual(r, [9.])
-
-    def test_flip_set(self):
-        """ qiskit.tools.apps.fermion.flip_set function"""
-        r = flip_set(self.j1, self.n)
-        self.assertEqual(r.size, 0)
-        r = flip_set(self.j2, self.n)
-        self.assertEqual(r.size, 0)
-        r = flip_set(self.j3, self.n)
-        self.assertEqual(r.size, 0)
-
-    def test_fermionic_maps_jordan_wigner(self):
-        """ qiskit.tools.apps.fermion.fermionic_maps with JORDAN_WIGNER map type"""
-        self.e0[0] = np.complex(0.75, 0)
-        r = fermionic_maps(self.a2, self.a5, "JORDAN_WIGNER")
-        self.assertEqual(len(r), 6)
-        r0 = [i[0] for i in r]
-        self.assertEqual(self.e0, r0)
-        r1 = [i[1] for i in r]
-        e = [Pauli(self.oo, self.oo),
-             Pauli(self.zz, self.oo),
-             Pauli(self.zo, self.oo),
-             Pauli(self.oz, self.oo),
-             Pauli(self.zo, self.zz),
-             Pauli(self.zz, self.zz)]
-        self.assertEqual(r1, e)
-
-    def test_fermionic_maps_parity(self):
-        """ qiskit.tools.apps.fermion.fermionic_maps with PARITY map type"""
-        r = fermionic_maps(self.a2, self.a5, "PARITY")
-        self.assertEqual(len(r), 6)
-        r0 = [i[0] for i in r]
-        self.assertEqual(self.e0, r0)
-        r1 = [i[1] for i in r]
-        e = [Pauli(self.zo, self.oz),
-             Pauli(self.zz, self.oz),
-             Pauli(self.oo, self.oz),
-             Pauli(self.oz, self.oz),
-             Pauli(self.oo, self.zz),
-             Pauli(self.zz, self.zz)]
-        self.assertEqual(r1, e)
-
-    def test_fermionic_maps_binary_tree(self):
-        """ qiskit.tools.apps.fermion.fermionic_maps with BINARY_TREE map type"""
-        r = fermionic_maps(self.a2, self.a5, "BINARY_TREE")
-        self.assertEqual(len(r), 6)
-        r0 = [i[0] for i in r]
-        self.assertEqual(self.e0, r0)
-        r1 = [i[1] for i in r]
-        e = [Pauli(self.zo, self.oz),
-             Pauli(self.zz, self.oz),
-             Pauli(self.oo, self.oz),
-             Pauli(self.oz, self.oz),
-             Pauli(self.oo, self.zz),
-             Pauli(self.zz, self.zz)]
-        self.assertEqual(r1, e)
-
-    def test_two_qubit_reduction(self):
-        """ qiskit.tools.apps.fermion.two_qubit_reduction"""
-        pauli_list = []
-        n = 4
-        w = np.arange(n ** 2).reshape(n, n)
-
-        for i in range(n):
-            for j in range(i):
-                if w[i, j] != 0:
-                    wp = np.zeros(n)
-                    vp = np.zeros(n)
-                    vp[n - i - 1] = 1
-                    vp[n - j - 1] = 1
-                    pauli_list.append((w[i, j], Pauli(vp, wp)))
-        r = two_qubit_reduction(pauli_list, 10)
-        r0 = [i[0] for i in r]
-        self.assertEqual([-5, -8, -2, 13], r0)
-        r1 = [i[1] for i in r]
-        e = [Pauli(self.zo, self.zz),
-             Pauli(self.zz, self.zz),
-             Pauli(self.oz, self.zz),
-             Pauli(self.oo, self.zz)]
-        self.assertEqual(e, r1)
-
-
-if __name__ == '__main__':
-    unittest.main()