def setUp(self):
     super().setUp()
     input_file = self._get_resource_path('sample.exactcover')
     with open(input_file) as f:
         self.list_of_subsets = json.load(f)
         qubitOp, offset = exact_cover.get_exact_cover_qubitops(self.list_of_subsets)
         self.algo_input = EnergyInput(qubitOp)
Пример #2
0
    def execute(self, my_knapsack, my_aleatory, debug=False):
        self.my_knapsack = my_knapsack
        self.my_aleatory = my_aleatory
        self.current_efos = 0
        #get instances of Pauli operator for ExactEigensolver
        qubitOp, offset = self._get_knapsack_qubitops(
            [it.value for it in self.my_knapsack.items],
            [it.weight
             for it in self.my_knapsack.items], self.my_knapsack.capacity)
        EnergyInput(qubitOp)
        ee = ExactEigensolver(qubitOp, k=1)  #instance of exactEigensolver
        result = ee.run()  #Run quantum algorithm

        most_lightly = result['eigvecs'][0]  #format result
        x = self._sample_most_likely(most_lightly)
        #solution
        result_solution = x[:len(self.my_knapsack.get_profits())]

        #init solution object
        self.my_best_solution = Solution.init_owner(self)
        self.my_best_solution.position = result_solution
        self.my_best_solution.evaluate()
        out = "\t\tq_solution: " + str(result_solution) + " weight: " +\
            str(self.my_best_solution.weight) + " fitness: " +\
            str(self.my_best_solution.fitness)
        util.if_print_text(out, debug)
Пример #3
0
 def setUp(self):
     super().setUp()
     input_file = self._get_resource_path('sample.exactcover')
     with open(input_file) as file:
         self.list_of_subsets = json.load(file)
         qubit_op, _ = exact_cover.get_operator(self.list_of_subsets)
         self.algo_input = EnergyInput(qubit_op)
Пример #4
0
    def setUp(self):
        super().setUp()
        np.random.seed(50)
        pauli_dict = {
            'paulis': [{"coeff": {"imag": 0.0, "real": -1.052373245772859}, "label": "II"},
                       {"coeff": {"imag": 0.0, "real": 0.39793742484318045}, "label": "IZ"},
                       {"coeff": {"imag": 0.0, "real": -0.39793742484318045}, "label": "ZI"},
                       {"coeff": {"imag": 0.0, "real": -0.01128010425623538}, "label": "ZZ"},
                       {"coeff": {"imag": 0.0, "real": 0.18093119978423156}, "label": "XX"}
                       ]
        }
        qubit_op = Operator.load_from_dict(pauli_dict)
        self.algo_input = EnergyInput(qubit_op)

        backends = ['statevector_simulator', 'qasm_simulator']
        res = {}
        for backend in backends:
            params_no_caching = {
                'algorithm': {'name': 'VQE', 'operator_mode': 'matrix' if backend == 'statevector_simulator' else 'paulis'},
                'problem': {'name': 'energy',
                            'random_seed': 50,
                            'circuit_caching': False,
                            'skip_qobj_deepcopy': False,
                            'skip_qobj_validation': False,
                            'circuit_cache_file': None,
                            },
                'backend': {'provider': 'qiskit.BasicAer', 'name': backend, 'shots': 1000},
            }
            qiskit_aqua = QiskitAqua(params_no_caching, self.algo_input)
            res[backend] = qiskit_aqua.run()
        self.reference_vqe_result = res
Пример #5
0
def get_qubit_op(num_qubits, seed=23412341234):
    G = nx.Graph()

    # """ HAVE DATA -- VIGO
    n = num_qubits
    SEED = seed
    np.random.seed(SEED % (2 ** 31 - 1))
    G = nx.dense_gnm_random_graph(n, n ** 2, seed=SEED)
    for (u, v, w) in G.edges(data=True):
        w['weight'] = np.random.rand() * 0.5 # 0.1

    np.random.seed(int(time.time()))

    w = np.zeros([n, n])
    for i in range(n):
        for j in range(n):
            temp = G.get_edge_data(i, j, default=0)
            if temp != 0:
                w[i, j] = temp['weight']
    # print(w)

    qubitOp, offset = max_cut.get_max_cut_qubitops(w)
    algo_input = EnergyInput(qubitOp)

    pos = nx.spring_layout(G)
    exact = ExactEigensolver(qubitOp).run()
    exact_energy = exact['energy']
    return qubitOp, exact_energy
Пример #6
0
 def setUp(self):
     super().setUp()
     aqua_globals.random_seed = 100
     self.num_nodes = 4
     self.w = random_graph(self.num_nodes, edge_prob=0.8, weight_range=10)
     self.qubit_op, self.offset = graph_partition.get_operator(self.w)
     self.algo_input = EnergyInput(self.qubit_op)
Пример #7
0
    def test_vqe_via_run_algorithm(self):
        """ VQE Via Run Algorithm test """
        coupling_map = [[0, 1]]
        basis_gates = ['u1', 'u2', 'u3', 'cx', 'id']

        params = {
            'problem': {
                'random_seed': self.seed
            },
            'algorithm': {
                'name': 'VQE'
            },
            'backend': {
                'name': 'statevector_simulator',
                'provider': 'qiskit.BasicAer',
                'coupling_map': coupling_map,
                'basis_gates': basis_gates
            },
        }
        result = run_algorithm(params, EnergyInput(self.qubit_op))
        self.assertAlmostEqual(result['energy'], -1.85727503)
        np.testing.assert_array_almost_equal(result['eigvals'], [-1.85727503],
                                             5)
        ref_opt_params = [
            -0.58294401, -1.86141794, -1.97209632, -0.54796022, -0.46945572,
            2.60114794, -1.15637845, 1.40498879, 1.14479635, -0.48416694,
            -0.66608349, -1.1367579, -2.67097002, 3.10214631, 3.10000313,
            0.37235089
        ]
        np.testing.assert_array_almost_equal(result['opt_params'],
                                             ref_opt_params, 5)
        self.assertIn('eval_count', result)
        self.assertIn('eval_time', result)
Пример #8
0
 def setUp(self):
     super().setUp()
     np.random.seed(100)
     self.num_nodes = 3
     self.w = vertexcover.random_graph(self.num_nodes, edge_prob=0.8, weight_range=10)
     self.qubit_op, self.offset = vertexcover.get_vertexcover_qubitops(self.w)
     self.algo_input = EnergyInput(self.qubit_op)
Пример #9
0
 def setUp(self):
     super().setUp()
     input_file = self._get_resource_path('sample.setpacking')
     with open(input_file) as f:
         self.list_of_subsets = json.load(f)
         qubitOp, offset = set_packing.get_set_packing_qubitops(self.list_of_subsets)
         self.algo_input = EnergyInput(qubitOp)
Пример #10
0
 def setUp(self):
     super().setUp()
     warnings.filterwarnings("ignore", message=aqua_globals.CONFIG_DEPRECATION_MSG,
                             category=DeprecationWarning)
     aqua_globals.random_seed = 8123179
     self.w = random_graph(4, edge_prob=0.5, weight_range=10)
     self.qubit_op, self.offset = max_cut.get_operator(self.w)
     self.algo_input = EnergyInput(self.qubit_op)
Пример #11
0
 def setUp(self):
     super().setUp()
     self.seed = 100
     aqua_globals.random_seed = self.seed
     self.num_nodes = 3
     self.w = random_graph(self.num_nodes, edge_prob=0.8, weight_range=10)
     self.qubit_op, self.offset = vertex_cover.get_operator(self.w)
     self.algo_input = EnergyInput(self.qubit_op)
Пример #12
0
 def test_ee_via_run_algorithm(self):
     """ ee via run algorithm test """
     params = {'algorithm': {'name': 'ExactEigensolver'}}
     result = run_algorithm(params, EnergyInput(self.qubit_op))
     self.assertAlmostEqual(result['energy'], -1.85727503)
     np.testing.assert_array_almost_equal(result['energies'], [-1.85727503])
     np.testing.assert_array_almost_equal(result['eigvals'],
                                          [-1.85727503 + 0j])
Пример #13
0
 def setUp(self):
     super().setUp()
     self.K = 5  # K means the size of the clique
     np.random.seed(100)
     self.num_nodes = 5
     self.w = clique.random_graph(self.num_nodes, edge_prob=0.8, weight_range=10)
     self.qubit_op, self.offset = clique.get_clique_qubitops(self.w, self.K)
     self.algo_input = EnergyInput(self.qubit_op)
Пример #14
0
 def setUp(self):
     super().setUp()
     self.k = 5  # K means the size of the clique
     self.seed = 100
     aqua_globals.random_seed = self.seed
     self.num_nodes = 5
     self.w = random_graph(self.num_nodes, edge_prob=0.8, weight_range=10)
     self.qubit_op, self.offset = clique.get_operator(self.w, self.k)
     self.algo_input = EnergyInput(self.qubit_op)
Пример #15
0
 def setUp(self):
     super().setUp()
     np.random.seed(100)
     self.num_nodes = 4
     self.w = graphpartition.random_graph(self.num_nodes,
                                          edge_prob=0.8,
                                          weight_range=10)
     self.qubit_op, self.offset = graphpartition.get_graphpartition_qubitops(
         self.w)
     self.algo_input = EnergyInput(self.qubit_op)
Пример #16
0
 def setUp(self):
     super().setUp()
     aqua_globals.random_seed = 100
     self.n = 2
     self.k = 1
     self.instance = np.zeros((self.n, self.n))
     self.instance[0, 1] = 0.8
     self.instance[1, 0] = 0.8
     self.qubit_op = get_operator(self.instance, self.n, self.k)
     self.algo_input = EnergyInput(self.qubit_op)
Пример #17
0
 def test_ee_via_run_algorithm_k4(self):
     """ ee via run algorithm k4 test """
     params = {'algorithm': {'name': 'ExactEigensolver', 'k': 4}}
     result = run_algorithm(params, EnergyInput(self.qubit_op))
     self.assertAlmostEqual(result['energy'], -1.85727503)
     self.assertEqual(len(result['eigvals']), 4)
     self.assertEqual(len(result['eigvecs']), 4)
     np.testing.assert_array_almost_equal(
         result['energies'],
         [-1.85727503, -1.24458455, -0.88272215, -0.22491125])
 def setUp(self):
     super().setUp()
     np.random.seed(100)
     self.n = 2
     self.q = 1
     self.instance = np.ones((self.n, self.n))
     self.instance[0, 1] = 0.8
     self.instance[1, 0] = 0.8
     # self.instance = -1 * self.instance
     self.qubit_op = get_portfoliodiversification_qubitops(self.instance, self.n, self.q)
     self.algo_input = EnergyInput(self.qubit_op)
Пример #19
0
 def setUp(self):
     super().setUp()
     np.random.seed(100)
     self.n = 2
     self.K = 1
     self.instance = np.zeros((self.n, self.n))
     self.instance[0, 1] = 0.8
     self.instance[1, 0] = 0.8
     self.qubit_op = get_vehiclerouting_qubitops(self.instance, self.n,
                                                 self.K)
     self.algo_input = EnergyInput(self.qubit_op)
Пример #20
0
 def setUp(self):
     super().setUp()
     aqua_globals.random_seed = 100
     self.n = 2
     self.q = 1
     self.instance = np.ones((self.n, self.n))
     self.instance[0, 1] = 0.8
     self.instance[1, 0] = 0.8
     # self.instance = -1 * self.instance
     self.qubit_op = get_qubit_op(self.instance, self.n, self.q)
     self.algo_input = EnergyInput(self.qubit_op)
Пример #21
0
 def test_clique(self):
     """ Clique test """
     params = {
         'problem': {'name': 'ising'},
         'algorithm': {'name': 'ExactEigensolver'}
     }
     result = run_algorithm(params, EnergyInput(self.qubit_op))
     x = sample_most_likely(result['eigvecs'][0])
     ising_sol = clique.get_graph_solution(x)
     np.testing.assert_array_equal(ising_sol, [1, 1, 1, 1, 1])
     oracle = self._brute_force()
     self.assertEqual(clique.satisfy_or_not(ising_sol, self.w, self.k), oracle)
Пример #22
0
 def test_exact_cover(self):
     """ Exact Cover test """
     params = {
         'problem': {'name': 'ising'},
         'algorithm': {'name': 'ExactEigensolver'}
     }
     result = run_algorithm(params, EnergyInput(self.qubit_op))
     x = sample_most_likely(result['eigvecs'][0])
     ising_sol = exact_cover.get_solution(x)
     np.testing.assert_array_equal(ising_sol, [0, 1, 1, 0])
     oracle = self._brute_force()
     self.assertEqual(exact_cover.check_solution_satisfiability(ising_sol, self.list_of_subsets),
                      oracle)
Пример #23
0
    def test_vertex_cover(self):
        """ Vertex cover test """
        params = {
            'problem': {'name': 'ising'},
            'algorithm': {'name': 'ExactEigensolver'}
        }
        result = run_algorithm(params, EnergyInput(self.qubit_op))

        x = sample_most_likely(result['eigvecs'][0])
        sol = vertex_cover.get_graph_solution(x)
        np.testing.assert_array_equal(sol, [0, 1, 1])
        oracle = self._brute_force()
        self.assertEqual(np.count_nonzero(sol), oracle)
Пример #24
0
 def setUp(self):
     super().setUp()
     np.random.seed(50)
     pauli_dict = {
         'paulis': [{"coeff": {"imag": 0.0, "real": -1.052373245772859}, "label": "II"},
                    {"coeff": {"imag": 0.0, "real": 0.39793742484318045}, "label": "ZI"},
                    {"coeff": {"imag": 0.0, "real": -0.39793742484318045}, "label": "IZ"},
                    {"coeff": {"imag": 0.0, "real": -0.01128010425623538}, "label": "ZZ"},
                    {"coeff": {"imag": 0.0, "real": 0.18093119978423156}, "label": "XX"}
                    ]
     }
     qubit_op = WeightedPauliOperator.from_dict(pauli_dict)
     self.algo_input = EnergyInput(qubit_op)
Пример #25
0
    def test_partition(self):
        """ Partition test """
        params = {
            'problem': {
                'name': 'ising'
            },
            'algorithm': {
                'name': 'ExactEigensolver'
            }
        }
        result = run_algorithm(params, EnergyInput(self.qubit_op))

        x = sample_most_likely(result['eigvecs'][0])
        np.testing.assert_array_equal(x, [0, 1, 0])
Пример #26
0
 def test_graph_partition(self):
     """ Graph Partition test """
     params = {
         'problem': {
             'name': 'ising'
         },
         'algorithm': {
             'name': 'ExactEigensolver'
         }
     }
     result = run_algorithm(params, EnergyInput(self.qubit_op))
     x = sample_most_likely(result['eigvecs'][0])
     # check against the oracle
     ising_sol = graph_partition.get_graph_solution(x)
     np.testing.assert_array_equal(ising_sol, [0, 1, 0, 1])
     oracle = self._brute_force()
     self.assertEqual(graph_partition.objective_value(x, self.w), oracle)
Пример #27
0
    def setUp(self):
        super().setUp()
        np.random.seed(50)
        pauli_dict = {
            'paulis': [{
                "coeff": {
                    "imag": 0.0,
                    "real": -1.052373245772859
                },
                "label": "II"
            }, {
                "coeff": {
                    "imag": 0.0,
                    "real": 0.39793742484318045
                },
                "label": "IZ"
            }, {
                "coeff": {
                    "imag": 0.0,
                    "real": -0.39793742484318045
                },
                "label": "ZI"
            }, {
                "coeff": {
                    "imag": 0.0,
                    "real": -0.01128010425623538
                },
                "label": "ZZ"
            }, {
                "coeff": {
                    "imag": 0.0,
                    "real": 0.18093119978423156
                },
                "label": "XX"
            }]
        }
        qubit_op = WeightedPauliOperator.from_dict(pauli_dict)
        self.algo_input = EnergyInput(qubit_op)
        self.reference_vqe_result = None

        # TODO: only work with optimization_level 0 now
        self.optimization_level = 0
Пример #28
0
 def setUp(self):
     super().setUp()
     self.seed = 50
     aqua_globals.random_seed = self.seed
     pauli_dict = {
         'paulis': [{
             "coeff": {
                 "imag": 0.0,
                 "real": -1.052373245772859
             },
             "label": "II"
         }, {
             "coeff": {
                 "imag": 0.0,
                 "real": 0.39793742484318045
             },
             "label": "IZ"
         }, {
             "coeff": {
                 "imag": 0.0,
                 "real": -0.39793742484318045
             },
             "label": "ZI"
         }, {
             "coeff": {
                 "imag": 0.0,
                 "real": -0.01128010425623538
             },
             "label": "ZZ"
         }, {
             "coeff": {
                 "imag": 0.0,
                 "real": 0.18093119978423156
             },
             "label": "XX"
         }]
     }
     qubit_op = WeightedPauliOperator.from_dict(pauli_dict)
     self.algo_input = EnergyInput(qubit_op)
     self.reference_vqe_result = None
Пример #29
0
    def run_driver(self, params, backend=None):
        """
        Runs the Qiskit Chemistry driver

        Args:
            params (Union(dictionary, filename)): Chemistry input data
            backend (QuantumInstance or BaseBackend): the experimental settings
                to be used in place of backend name
         Raises:
            QiskitChemistryError: Missing Input
        """
        if params is None:
            raise QiskitChemistryError("Missing input.")

        self._operator = None
        self._chemistry_result = None
        self._qiskit_aqua = None
        self._hdf5_file = None
        self._parser = InputParser(params)
        self._parser.parse()

        # before merging defaults attempts to find a provider for the backend in case no
        # provider was passed
        if backend is None and \
                self._parser.get_section_property(JSONSchema.BACKEND, JSONSchema.PROVIDER) is None:
            backend_name = self._parser.get_section_property(
                JSONSchema.BACKEND, JSONSchema.NAME)
            if backend_name is not None:
                self._parser.set_section_property(
                    JSONSchema.BACKEND, JSONSchema.PROVIDER,
                    get_provider_from_backend(backend_name))

        # set provider and name in input file for proper backend schema dictionary build
        if isinstance(backend, BaseBackend):
            self._parser.backend = backend
            self._parser.add_section_properties(
                JSONSchema.BACKEND, {
                    JSONSchema.PROVIDER: get_provider_from_backend(backend),
                    JSONSchema.NAME: backend.name(),
                })

        self._parser.validate_merge_defaults()

        experiment_name = "-- no &NAME section found --"
        if JSONSchema.NAME in self._parser.get_section_names():
            name_sect = self._parser.get_section(JSONSchema.NAME)
            if name_sect is not None:
                experiment_name = str(name_sect)
        logger.info('Running chemistry problem from input file: %s',
                    self._parser.get_filename())
        logger.info('Experiment description: %s', experiment_name.rstrip())

        driver_name = self._parser.get_section_property(
            InputParser.DRIVER, JSONSchema.NAME)
        if driver_name is None:
            raise QiskitChemistryError(
                'Property "{0}" missing in section "{1}"'.format(
                    JSONSchema.NAME, InputParser.DRIVER))

        self._hdf5_file = \
            self._parser.get_section_property(InputParser.DRIVER, InputParser.HDF5_OUTPUT)

        if driver_name not in local_drivers():
            raise QiskitChemistryError(
                'Driver "{0}" missing in local drivers'.format(driver_name))

        work_path = None
        input_file = self._parser.get_filename()
        if input_file is not None:
            work_path = os.path.dirname(os.path.realpath(input_file))

        section = self._parser.get_section(driver_name)
        driver = get_driver_class(driver_name).init_from_input(section)
        driver.work_path = work_path
        molecule = driver.run()

        if work_path is not None and \
                self._hdf5_file is not None and not os.path.isabs(self._hdf5_file):
            self._hdf5_file = os.path.abspath(
                os.path.join(work_path, self._hdf5_file))

        molecule.log()

        if self._hdf5_file is not None:
            molecule.save(self._hdf5_file)
            logger.info("HDF5 file saved '%s'", self._hdf5_file)

        # Run the Hamiltonian to process the QMolecule and get an input for algorithms
        clazz = get_chemistry_operator_class(
            self._parser.get_section_property(InputParser.OPERATOR,
                                              JSONSchema.NAME))
        self._operator = clazz.init_params(
            self._parser.get_section_properties(InputParser.OPERATOR))
        qubit_op, aux_ops = self.operator.run(molecule)
        input_object = EnergyInput(qubit_op, aux_ops)

        logger.debug('Core computed substitution variables %s',
                     self.operator.molecule_info)
        result = self._parser.process_substitutions(
            self.operator.molecule_info)
        logger.debug('Substitutions %s', result)

        aqua_params = {}
        for section_name, section in self._parser.get_sections().items():
            if section_name == JSONSchema.NAME or \
               section_name == InputParser.DRIVER or \
               section_name == driver_name.lower() or \
               section_name == InputParser.OPERATOR or \
               not isinstance(section, dict):
                continue

            aqua_params[section_name] = copy.deepcopy(section)
            if JSONSchema.PROBLEM == section_name and \
                    InputParser.AUTO_SUBSTITUTIONS in aqua_params[section_name]:
                del aqua_params[section_name][InputParser.AUTO_SUBSTITUTIONS]

        self._qiskit_aqua = QiskitAqua(aqua_params, input_object, backend)
Пример #30
0
    def run(self, qmolecule):
        logger.debug('Processing started...')
        # Save these values for later combination with the quantum computation result
        self._hf_energy = qmolecule.hf_energy
        self._nuclear_repulsion_energy = qmolecule.nuclear_repulsion_energy
        self._nuclear_dipole_moment = qmolecule.nuclear_dipole_moment
        self._reverse_dipole_sign = qmolecule.reverse_dipole_sign

        core_list = qmolecule.core_orbitals if self._freeze_core else []
        reduce_list = self._orbital_reduction

        if self._freeze_core:
            logger.info(
                "Freeze_core specified. Core orbitals to be frozen: {}".format(
                    core_list))
        if len(reduce_list) > 0:
            logger.info(
                "Configured orbital reduction list: {}".format(reduce_list))
            reduce_list = [
                x + qmolecule.num_orbitals if x < 0 else x for x in reduce_list
            ]

        freeze_list = []
        remove_list = []

        # Orbitals are specified by their index from 0 to n-1, where n is the number of orbitals the
        # molecule has. The combined list of the core orbitals, when freeze_core is true, with any
        # user supplied orbitals is what will be used. Negative numbers may be used to indicate the
        # upper virtual orbitals, so -1 is the highest, then -2 etc. and these will be converted to the
        # positive 0-based index for computation.
        # In the combined list any orbitals that are occupied are added to a freeze list and an
        # energy is stored from these orbitals to be added later. Unoccupied orbitals are just discarded.
        # Because freeze and eliminate is done in separate steps, with freeze first, we have to re-base
        # the indexes for elimination according to how many orbitals were removed when freezing.
        #
        orbitals_list = list(set(core_list + reduce_list))
        num_alpha = qmolecule.num_alpha
        num_beta = qmolecule.num_beta
        new_num_alpha = num_alpha
        new_num_beta = num_beta
        if len(orbitals_list) > 0:
            orbitals_list = np.array(orbitals_list)
            orbitals_list = orbitals_list[(orbitals_list >= 0) & (
                orbitals_list < qmolecule.num_orbitals)]

            freeze_list_alpha = [i for i in orbitals_list if i < num_alpha]
            freeze_list_beta = [i for i in orbitals_list if i < num_beta]
            freeze_list = np.append(
                freeze_list_alpha,
                [i + qmolecule.num_orbitals for i in freeze_list_beta])

            remove_list_alpha = [i for i in orbitals_list if i >= num_alpha]
            remove_list_beta = [i for i in orbitals_list if i >= num_beta]
            rla_adjust = -len(freeze_list_alpha)
            rlb_adjust = -len(freeze_list_alpha) - len(
                freeze_list_beta) + qmolecule.num_orbitals
            remove_list = np.append(
                [i + rla_adjust for i in remove_list_alpha],
                [i + rlb_adjust for i in remove_list_beta])

            logger.info(
                "Combined orbital reduction list: {}".format(orbitals_list))
            logger.info(
                "  converting to spin orbital reduction list: {}".format(
                    np.append(np.array(orbitals_list),
                              np.array(orbitals_list) +
                              qmolecule.num_orbitals)))
            logger.info(
                "    => freezing spin orbitals: {}".format(freeze_list))
            logger.info(
                "    => removing spin orbitals: {} (indexes accounting for freeze {})"
                .format(
                    np.append(
                        remove_list_alpha,
                        np.array(remove_list_beta) + qmolecule.num_orbitals),
                    remove_list))

            new_num_alpha -= len(freeze_list_alpha)
            new_num_beta -= len(freeze_list_beta)

        new_nel = [new_num_alpha, new_num_beta]

        fer_op = FermionicOperator(h1=qmolecule.one_body_integrals,
                                   h2=qmolecule.two_body_integrals)
        fer_op, self._energy_shift, did_shift = Hamiltonian._try_reduce_fermionic_operator(
            fer_op, freeze_list, remove_list)
        if did_shift:
            logger.info("Frozen orbital energy shift: {}".format(
                self._energy_shift))
        if self._transformation == TransformationType.PH.value:
            fer_op, ph_shift = fer_op.particle_hole_transformation(new_nel)
            self._ph_energy_shift = -ph_shift
            logger.info("Particle hole energy shift: {}".format(
                self._ph_energy_shift))
        logger.debug('Converting to qubit using {} mapping'.format(
            self._qubit_mapping))
        qubit_op = Hamiltonian._map_fermionic_operator_to_qubit(
            fer_op, self._qubit_mapping, new_nel, self._two_qubit_reduction)

        logger.debug('  num paulis: {}, num qubits: {}'.format(
            len(qubit_op.paulis), qubit_op.num_qubits))
        algo_input = EnergyInput(qubit_op)

        def _add_aux_op(aux_op):
            algo_input.add_aux_op(
                Hamiltonian._map_fermionic_operator_to_qubit(
                    aux_op, self._qubit_mapping, new_nel,
                    self._two_qubit_reduction))
            logger.debug('  num paulis: {}'.format(
                len(algo_input.aux_ops[-1].paulis)))

        logger.debug('Creating aux op for Number of Particles')
        _add_aux_op(fer_op.total_particle_number())
        logger.debug('Creating aux op for S^2')
        _add_aux_op(fer_op.total_angular_momentum())
        logger.debug('Creating aux op for Magnetization')
        _add_aux_op(fer_op.total_magnetization())

        if qmolecule.has_dipole_integrals():

            def _dipole_op(dipole_integrals, axis):
                logger.debug('Creating aux op for dipole {}'.format(axis))
                fer_op_ = FermionicOperator(h1=dipole_integrals)
                fer_op_, shift, did_shift_ = self._try_reduce_fermionic_operator(
                    fer_op_, freeze_list, remove_list)
                if did_shift_:
                    logger.info("Frozen orbital {} dipole shift: {}".format(
                        axis, shift))
                ph_shift_ = 0.0
                if self._transformation == TransformationType.PH.value:
                    fer_op_, ph_shift_ = fer_op_.particle_hole_transformation(
                        new_nel)
                    ph_shift_ = -ph_shift_
                    logger.info("Particle hole {} dipole shift: {}".format(
                        axis, ph_shift_))
                qubit_op_ = self._map_fermionic_operator_to_qubit(
                    fer_op_, self._qubit_mapping, new_nel,
                    self._two_qubit_reduction)
                logger.debug('  num paulis: {}'.format(len(qubit_op_.paulis)))
                return qubit_op_, shift, ph_shift_

            op_dipole_x, self._x_dipole_shift, self._ph_x_dipole_shift = _dipole_op(
                qmolecule.x_dipole_integrals, 'x')
            op_dipole_y, self._y_dipole_shift, self._ph_y_dipole_shift = _dipole_op(
                qmolecule.y_dipole_integrals, 'y')
            op_dipole_z, self._z_dipole_shift, self._ph_z_dipole_shift = _dipole_op(
                qmolecule.z_dipole_integrals, 'z')

            algo_input.add_aux_op(op_dipole_x)
            algo_input.add_aux_op(op_dipole_y)
            algo_input.add_aux_op(op_dipole_z)

        logger.info(
            'Molecule num electrons: {}, remaining for processing: {}'.format(
                [num_alpha, num_beta], new_nel))
        nspinorbs = qmolecule.num_orbitals * 2
        new_nspinorbs = nspinorbs - len(freeze_list) - len(remove_list)
        logger.info(
            'Molecule num spin orbitals: {}, remaining for processing: {}'.
            format(nspinorbs, new_nspinorbs))

        self._add_molecule_info(self.INFO_NUM_PARTICLES,
                                [new_num_alpha, new_num_beta])
        self._add_molecule_info(self.INFO_NUM_ORBITALS, new_nspinorbs)
        self._add_molecule_info(
            self.INFO_TWO_QUBIT_REDUCTION, self._two_qubit_reduction
            if self._qubit_mapping == 'parity' else False)

        logger.debug('Processing complete ready to run algorithm')
        return algo_input.qubit_op, algo_input.aux_ops