Skip to content
This repository was archived by the owner on Dec 7, 2021. It is now read-only.

Return Ground State Energy result in Chemistry to replace (lines, dict) #861

Merged
merged 15 commits into from
Mar 20, 2020
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ SPHINXOPTS =

.PHONY: lint style test test_ci spell copyright html coverage coverage_erase

all_check: spell style lint copyright html
all_check: spell style lint html

lint:
pylint -rn --ignore=gauopen qiskit/aqua qiskit/chemistry qiskit/finance qiskit/ml qiskit/optimization test tools
Expand Down
15 changes: 2 additions & 13 deletions qiskit/chemistry/applications/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,10 @@

MolecularGroundStateEnergy

Application Results
===================

.. autosummary::
:toctree: ../stubs/
:nosignatures:

MolecularGroundStateEnergyResult

"""

from .molecular_ground_state_energy import (MolecularGroundStateEnergy,
MolecularGroundStateEnergyResult)
from .molecular_ground_state_energy import MolecularGroundStateEnergy

__all__ = [
'MolecularGroundStateEnergy',
'MolecularGroundStateEnergyResult'
'MolecularGroundStateEnergy'
]
56 changes: 5 additions & 51 deletions qiskit/chemistry/applications/molecular_ground_state_energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@

from qiskit.providers import BaseBackend
from qiskit.aqua import QuantumInstance
from qiskit.aqua.algorithms import MinimumEigensolver, AlgorithmResult, MinimumEigensolverResult, \
VQE
from qiskit.aqua.algorithms import MinimumEigensolver, VQE
from qiskit.aqua.operators import Z2Symmetries
from qiskit.chemistry import QiskitChemistryError
from qiskit.chemistry.components.initial_states import HartreeFock
from qiskit.chemistry.components.variational_forms import UCCSD
from qiskit.chemistry.core import (Hamiltonian, TransformationType, QubitMappingType,
ChemistryOperator)
ChemistryOperator, MolecularGroundStateResult)
from qiskit.chemistry.drivers import BaseDriver


Expand Down Expand Up @@ -83,7 +82,7 @@ def solver(self, solver: MinimumEigensolver) -> None:
def compute_energy(self,
callback: Optional[Callable[[List, int, str, bool, Optional[Z2Symmetries]],
MinimumEigensolver]] = None
) -> 'MolecularGroundStateEnergyResult':
) -> MolecularGroundStateResult:
"""
Compute the ground state energy of the molecule that was supplied via the driver

Expand All @@ -96,7 +95,7 @@ def compute_energy(self,
for use as the solver here.

Returns:
A MolecularGroundStateEnergyResult
A molecular ground state result
Raises:
QiskitChemistryError: If no MinimumEigensolver was given and no callback is being
used that could supply one instead.
Expand All @@ -122,14 +121,7 @@ def compute_energy(self,
aux_operators = aux_operators if self.solver.supports_aux_operators() else None

raw_result = self.solver.compute_minimum_eigenvalue(operator, aux_operators)
lines, core_result = core.process_algorithm_result(raw_result)

mgse = MolecularGroundStateEnergyResult()
mgse.energy = core_result['energy']
mgse.printable = lines
mgse.raw_result = raw_result

return mgse
return core.process_algorithm_result(raw_result)

@staticmethod
def get_default_solver(quantum_instance: Union[QuantumInstance, BaseBackend]) ->\
Expand Down Expand Up @@ -160,41 +152,3 @@ def cb_default_solver(num_particles, num_orbitals,
vqe.quantum_instance = quantum_instance
return vqe
return cb_default_solver


class MolecularGroundStateEnergyResult(AlgorithmResult):
""" Ground state energy result."""

@property
def energy(self) -> float:
""" Returns energy """
return self.get('energy')

@energy.setter
def energy(self, value: float) -> None:
""" Sets energy """
self.data['energy'] = value

@property
def printable(self) -> List[str]:
""" Returns printable """
return self.get('printable')

@printable.setter
def printable(self, value: List[str]) -> None:
""" Sets printable """
self.data['printable'] = value

def print_result(self) -> None:
""" Prints the printable result """
print(*self.printable, sep='\n')

@property
def raw_result(self) -> MinimumEigensolverResult:
""" Returns raw result from MinimumEigensolver """
return self.get('raw_result')

@raw_result.setter
def raw_result(self, value: MinimumEigensolverResult) -> None:
""" Sets raw result from MinimumEigensolver """
self.data['raw_result'] = value
11 changes: 9 additions & 2 deletions qiskit/chemistry/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# This code is part of Qiskit.
#
# (C) Copyright IBM 2018, 2019.
# (C) Copyright IBM 2018, 2020.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand Down Expand Up @@ -35,6 +35,9 @@
:nosignatures:

ChemistryOperator
MolecularChemistryResult
MolecularGroundStateResult
MolecularExcitedStatesResult

Core
====
Expand All @@ -49,10 +52,14 @@

"""

from .chemistry_operator import ChemistryOperator
from .chemistry_operator import (ChemistryOperator, MolecularChemistryResult,
MolecularGroundStateResult, MolecularExcitedStatesResult)
from .hamiltonian import Hamiltonian, TransformationType, QubitMappingType

__all__ = ['ChemistryOperator',
'MolecularChemistryResult',
'MolecularGroundStateResult',
'MolecularExcitedStatesResult',
'Hamiltonian',
'TransformationType',
'QubitMappingType']
Loading