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

Commit d028eec

Browse files
paulineollitraultPanagiotis BarkoutsosCryorismanoelmarquesmrossinek
authored
Bosonic algorithms and support for Chemistry (#1356)
* fixes in ground state * patch MES result to GSC result instead of returning a tuple * files fixes for GSC interface * rm utf8 headers * fix spell, lint, mypy * Remove `custom_excitation_pool` from AdaptVQE `compute_ground_state` function Rather than ignoring the arguments given by the interface, we can remove this additional argument in favor of enabling the user to set this custom excitation pool through the `MESFactory`. An example on how to achieve such a thing can be seen in the corresponding unittest. * fix mypy * fix lint * Re-enable DeprecationWarnings after VQEAdapt has been initialized * Fixes several minor nit-picks - copyright years - faulty renames - faulty merge side-effects - missing setters * make MESFactory an interface only * make MESFactory an interface only * fix copyright years * derive from MESFactory and update docs * update docstrings and add molecule_info * consistent naming in ``ground(_)state`` * fix spell * more spell, deprecate MGSE * fix deprecation * more style * test fixes * fixes * [WIP] basic Result-interfaces This adds the following interfaces: - qiskit.chemistry.ChemistryResult(AlgorithmResult) - qiskit.chemistry.ground_state_calculation.GroundStateResult(ChemistryResult) - qiskit.chemistry.ground_state_calculation.FermionicGroundStateResult(GroundStateResult) The logic is as follows: ChemistryResult and GroundStateResult are empty interfaces which define a hierarchy for the result classes. They provide a useful granularity for type checking. Once more subclasses are added we can extract common functionality up into the stack as needed. The FermionicGroundStateResult currently is just a port of the old MolecularChemistryResult and MolecularGroundStateResult. Both of these classes are deprecated in this commit. Since this class is currently specific to the GroundStateCalculation it is part of that module. This is, however, subject to change. * Remove BosonicTransformation from this PR The BosonicTransformation will be added in a separate PR aiming to refactor the respective modules. * AdaptVQE actually supports aux_operators * [wip] resolve cyclic import problems Having a `Result` class in either the `ground_state_calculations` or `qubit_operator_transformations` modules leads to a coupling of the two modules that is too tight. I.e. we run into cyclic imports whenever we try to run any code because the `QubitOpTransformation` class needs to load the `Result` class while at the same time it needs to be available in the `GroundStateCalculation` class. Thus, when an additional coupling in between these two modules is created, we have cyclic import. Thus, we drop one level of granularity and only provide a single result-interface on the `qiskit.chemistry` level, here, called `ChemistryResult` (open for discussion). I also moved the `DipoleTuple` to this level to simplify its usage in the other classes. * Make AdaptVQE use the FermionicGSResult * Use FermionicGroundStateResult in MinimumEigensolverGroundStateCalculation * molecule update * molecule update * test molecule added * test commit * new branch * Fix mypy * Filter DeprecationWarnings in unittests This filters all of the DeprecationWarnigns introduced in this PR. In 3 months from now we can remove these tests once the corresponding code is also removed. This commit also adds TODO labels to all of these unittest files which will have to be migrated to work within the new framework. * Add TODO in AdaptVQE unittest * Add missing unittest imports I noticed that in some test files the unittest module is not imported and the `__main__` is not set accordingly. If we do not want to mix these changes into this PR, we can simply revert this commit. * mypy fix * unused code * Create qiskit.chemistry.results module * Replace interpret() with add_context() in QubitOperatorTransformations Instead of an interpret() function, the QubitOperatorTransformation interface defines an add_context() function which is used to augment the given StateResult object with information based on the transformation's context. * Fix GroundStateCalculation classes to work with the results interface * Revert faulty change in github workflow * combining bosonic_operator into bosonic_transformation * HarmonicBasis class to transform a Watson Hamiltonian (vibronic Hamiltonian) in the harmonic basis * Watson Hamiltonian class to store the results of the bosonic driver * now returns a watson hamiltonian and does not take care of the transformation to the harmonic basis anymore * Watson Hamiltonian class to store the results of the bosonic driver * added watson hamiltonian to init * harmonic transformation for watson hamiltonian * added docstring, made compatible with the harmonic basis and watson hamiltonian, replaced the printing ground state functions by a filter function * unitests WIP first commit * remove deprecation suppressing from new tests * support additional aux ops and conv to dict * fix aux_ops=None * lint, style * more test * fixes in test * fix style * fix mypy * fix mypy * fixes in fermionic trafo * fixed bug in direct qubit mapping * remove editor created redundant file * resolved tests * docstring fix * fix error & specify type hint * change typehint Any -> FermionicOp * add missing imports * spell * suggestions from code review * consistent use in .keys() * type hints, minor improvements * Rethink the qiskit.chemistry.results After some discussion we decided to rethink parts of the qiskit.chemistry.results interfaces. We want to minimize the differentiation between grround and excited states and let only the concrete `QubitOperatorTransformation` handle the fermionic and bosonic differentiation. Thus, I apply the following changes: * provide a single `EigenstateResult` which can be either a ground or excited state * derive `ElectronicStructureResult` (prev. `FermionicResult`) from this * use the `FermionicTransformation.interpret()` method to map a general `EigenstateResult` to the type specific for the transformation With the last change we also align the `qiskit.chemistry` module further with the `qiskit.optimization` module where we also use `interpret()` rather than `add_context()` methods (which was the name we intended to use prior to this commit). * Remove unneeded DeprecationWarning from AdaptVQEResult * Update some docstrings * fix lint * revert back to lists of aux_ops * Update qiskit/chemistry/ground_state_calculation/adapt_vqe.py Co-authored-by: Max Rossmannek <max.rossmannek@uzh.ch> * apply suggestions from code review * change typehint to List[float] * Update qiskit/chemistry/core/hamiltonian.py Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com> * test fixes after code review * put back functionalities from bosonic_tranformation to bosonic_operator + created a vibronic_structure_result * excited state interface for matching the ground state interface and handling both electronic and vibrational states * Rename aux_values to aux_operator_eigenvalues This naming is consistent with the EigensolverResult and MinimumEigensolverResult classes. * Remove leftover from dict-style aux_operators * Add an `evaluate_operators` method to the GroundStateCalculation This method can be used to evaluate any additional auxiliary operators after the GSC has finished. This will be necessary especially in the excited state calculations and is in general a nice option for the user to have. The method is similar to how the `VQE` evaluates auxiliary operators internally. However, it can also deal with `MinimumEigensolver`s which do not use a `QuantumInstance`. A curiousity arose because the `VQE` appears to wrap the auxiliary operator results into lists multiple times. In order to ensure interoperability the same is done here. The `AdaptVQE` now derives off of the `MinimumEigensolverGSC` because there was no obvious drawback to this and the benefit of reusing this new method was welcome. Unittests have been added to test the new functionality. * fix lint * Remove erronous TODO * Enforce a FermionicTransformation in the VQEUCCSDFactory * Do not enforce VQEUCCSDFactory type in AdaptVQE Since we check for the VQE and UCCSD types anyways we shouldn't force the user to subclass this factory. * Reuse the VQE object during AdaptVQE * Expose molecule_info and qubit_mapping publicly * fix lint * added interpret function * changed transformation and mapping type names to specify fermionic or bnosonic * added the filter to bosonic_operator and changed the test accordingly (also fixed the test according to the bug in the mapping fixed last week) * auxiliary operator for getting the number of occupied modals per mode plus test for bosonic tranformation * fixes in tests * fixes in tests and revert to molecule_methods * remove two duplicate tests * Expose some VQE arguments in the VQEUCCSDFactory As discussed, we now expose some of the VQE arguments through this factory in order to allow greater flexibility for the user. * test commit * fix spell * fix bugs qeom code and first version of test for numerical qeom * added the build_hopping_operator capability in the transformation * modified results to take excited states components * reverted due to missing part of the test uccsd_HF * remove test EOM todos * lint * more lint * more lint * Prepare EigenstateResult to handle ground and excited states * Deprecate the Enums in the chemistry.core module * Also populate eigenstates in ground state calculations * Add factory for NumPyMinimumEigensolver * Implement `_filter_criterion` in FermionicTransformation * Extract default filter_criterion into interface Rather than checking for a private method being implemented we can obtain the default filter_criterion cleanly. This makes sense because any transformation in theory could implement a default filter. However, we return None in case it is not implemented. * fixing qeom code * Make use of default filter criterion configurable * Check state's type before making at a StateFn * Use `supports_aux_ops` in `returns_groundstate` * Replace Any type-hint where not really necessary The reason for making it a union of lists rather than a list of a union is to ensure that no mixed lists are allowed. * Do not use legacy Operator in new interface The WeightedPauliOp is a legacy operator and should not be used in this new interface. Instead, we now convert the operators to the OperatorFlow before returning them to ensure we only use the new operator types. * fix the eigenstate_result and electronic_structure_result to work with excited states and test eom with Numpy eigensolver for the ground state * clean qeom code * tests for numerical qeom * change of the ExcitedStatesCalculation init so that it does not have a GSC * Except (Minimum)EigensolverResults in interpret() To provide more user-flexibility and better compatibility with the Aqua result classes, the interpret() method is able to handle (Minimum)EigensolverResult classes as well as the EigenstateResult. * Fix tests to work with OperatorBase rather than WeightedPauliOperator * fix es_factory and additional information in FermionicTransformation for Analytical qEOM * Gaussian Forces bosonic driver * commutation rule and hopping operators for bosonic_transformation * rm WPO support in trafo, add test for aux_ops * test bosonic_transformation and fix bugs in filter function * fix bug with aux_ops in filtered numpy eigensolver * test bosonic transformation * Fix docstring * Fix aux_op particle-hole conversion * vqe uvccsd factory * gaussian log driver test adapted to changes in code * added reno * fix bug number of modes in gaussian_log_result * Extend ElectronicStructureResult to work with excited state calculations Since an electronic structure can consist of multiple states and during excited state calculations we obtain energies and auxiliary operator evaluations for each investigated state we expose all finally interpreted result properties as Lists where the first entry should always reflect the ground state properties. * untapered_op for bosonic_transformation * Update unit tests * Fix bosonic tests * testing bosonic qeom * fix bug hopping operators in bosonic_transformation * finish bosonic operator merge with esc * Fix style in bosonic and excited state files * Fix lint * fix small things * fix auxiliary operators * reformatting of electronic structure results print * fix linting * fix mypy * Restructure excited states code - moving modules - renaming classes - adapting tests * more mypy fixes * final mypy fixes * add use_default_filter_criterion argument to NumPyEigensolverFactory * fix naming * fix tests * fix lint and spell * Make commutation rule a boolean This makes sense because it can only ever be one of two things: commuting or anti-commuting. * fix lint * fix mypy * remove warning about only fermionic problems being supported * fix lint * fix unittests * fix spell and style * try fixing sphinx * fix test * fix Steve's comments * Add BosonicBasis to init file * Fix style, lint and test * release note * change error message in bosonic_basis * Do not use the default_filter_criterion for excited states Since we opted to make the default filter criterion of the fermionic case filter non-singlet states this kind of misses the point in the excirted states cases. Thus we now provide a custom filter in the test. For the backlog we should consider a better implementation of the default filter which can handle this automatically. * Rename bosonic_basis module to bosonic_bases * Fix module name in docs Co-authored-by: Panagiotis Barkoutsos <bpa@zurich.ibm.com> Co-authored-by: Cryoris <jules.gacon@googlemail.com> Co-authored-by: Julien Gacon <gaconju@gmail.com> Co-authored-by: Manoel Marques <manoel.marques@ibm.com> Co-authored-by: Max Rossmannek <oss@zurich.ibm.com> Co-authored-by: Anton Dekusar <adekusar@ie.ibm.com> Co-authored-by: Anton Dekusar <62334182+adekusar-drl@users.noreply.github.com> Co-authored-by: Max Rossmannek <max.rossmannek@uzh.ch> Co-authored-by: Panagiotis Barkoutsos <pbarkoutsos@gmail.com> Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com> Co-authored-by: Mario Motta <mario@marios-mbp.almaden.ibm.com> Co-authored-by: woodsp <woodsp@us.ibm.com> Co-authored-by: Stefan Woerner <WOR@zurich.ibm.com>
1 parent 41d9a15 commit d028eec

39 files changed

+1574
-780
lines changed

.pylintdict

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ anc
2121
ancilla
2222
ancillae
2323
ancillas
24+
anharmonic
2425
annealers
2526
ansatz
2627
ansatzes
@@ -57,8 +58,9 @@ bohr
5758
bool
5859
boolean
5960
bools
60-
bopes
61+
boson
6162
bosonic
63+
bopes
6264
bpa
6365
brassard
6466
bravyi
@@ -217,9 +219,9 @@ fcidump
217219
fcompiler
218220
fd
219221
fermionic
222+
fermionicdriver
220223
fermionicoperator
221224
fermionictransformation
222-
fermionicdriver
223225
fermions
224226
fi
225227
fileio
@@ -376,6 +378,7 @@ ljik
376378
lk
377379
lmin
378380
lnot
381+
logfile
379382
loglik
380383
loglikelihood
381384
logn
@@ -760,6 +763,7 @@ vqe
760763
vqe's
761764
vscf
762765
watrous's
766+
watson
763767
wavefunction
764768
wavefunctions
765769
weightedpaulioperator

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,3 +537,4 @@ However there is some code that is included under other licensing as follows:
537537
* The [Gaussian 16 driver](qiskit/chemistry/drivers/gaussiand) in `qiskit.chemistry`
538538
contains [work](qiskit/chemistry/drivers/gaussiand/gauopen) licensed under the
539539
[Gaussian Open-Source Public License](qiskit/chemistry/drivers/gaussiand/gauopen/LICENSE.txt).
540+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.. _qiskit-chemistry-components-bosonic_bases:
2+
3+
.. automodule:: qiskit.chemistry.components.bosonic_bases
4+
:no-members:
5+
:no-inherited-members:
6+
:no-special-members:

qiskit/aqua/operators/legacy/common.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ def evolution_instruction(pauli_list, evo_time, num_time_slices,
384384
return qc.to_instruction()
385385

386386

387-
def commutator(op_a, op_b, op_c=None, sign=-1, threshold=1e-12):
387+
def commutator(op_a, op_b, op_c=None, sign=False, threshold=1e-12):
388388
r"""
389389
Compute commutator of `op_a` and `op_b` or
390390
the symmetric double commutator of `op_a`, `op_b` and `op_c`.
@@ -401,7 +401,7 @@ def commutator(op_a, op_b, op_c=None, sign=-1, threshold=1e-12):
401401
op_a (WeightedPauliOperator): operator a
402402
op_b (WeightedPauliOperator): operator b
403403
op_c (Optional(WeightedPauliOperator)): operator c
404-
sign (int): -1 is anti-commute, 1 is commute
404+
sign (bool): False anti-commutes, True commutes
405405
threshold (float): the truncation threshold
406406
407407
Returns:
@@ -410,11 +410,13 @@ def commutator(op_a, op_b, op_c=None, sign=-1, threshold=1e-12):
410410
Note:
411411
For the final chop, the original codes only contain the paulis with real coefficient.
412412
"""
413+
sign = 1 if sign else -1
414+
413415
op_ab = op_a * op_b
414416
op_ba = op_b * op_a
415417

416418
if op_c is None:
417-
res = op_ab + sign * op_ba
419+
res = op_ab - op_ba
418420
else:
419421
op_ac = op_a * op_c
420422
op_ca = op_c * op_a
@@ -426,9 +428,9 @@ def commutator(op_a, op_b, op_c=None, sign=-1, threshold=1e-12):
426428
op_acb = op_ac * op_b
427429
op_bca = op_b * op_ca
428430

429-
tmp = (op_bac + op_cab + op_acb + op_bca)
431+
tmp = (- op_bac + sign*op_cab - op_acb + sign*op_bca)
430432
tmp = 0.5 * tmp
431-
res = op_abc + op_cba + sign * tmp
433+
res = op_abc - sign * op_cba + tmp
432434

433435
res.simplify()
434436
res.chop(threshold)

qiskit/chemistry/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@
138138
BosonicOperator
139139
FermionicOperator
140140
QMolecule
141+
WatsonHamiltonian
141142
MP2Info
142143
143144
Submodules
@@ -156,6 +157,7 @@
156157

157158
from .qiskit_chemistry_error import QiskitChemistryError
158159
from .qmolecule import QMolecule
160+
from .watson_hamiltonian import WatsonHamiltonian
159161
from .bosonic_operator import BosonicOperator
160162
from .fermionic_operator import FermionicOperator
161163
from .mp2info import MP2Info
@@ -164,6 +166,7 @@
164166

165167
__all__ = ['QiskitChemistryError',
166168
'QMolecule',
169+
'WatsonHamiltonian',
167170
'BosonicOperator',
168171
'FermionicOperator',
169172
'MP2Info',

qiskit/chemistry/algorithms/excited_states_solvers/eigensolver_factories/numpy_eigensolver_factory.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import numpy as np
1717

1818
from qiskit.aqua.algorithms import Eigensolver, NumPyEigensolver
19-
from qiskit.chemistry.transformations import FermionicTransformation
19+
from qiskit.chemistry.transformations import Transformation
2020
from qiskit.aqua.utils.validation import validate_min
2121

2222
from .eigensolver_factory import EigensolverFactory
@@ -38,6 +38,7 @@ def __init__(self,
3838
`filter(eigenstate, eigenvalue, aux_values)` and must return a boolean to indicate
3939
whether to consider this value or not. If there is no
4040
feasible element, the result can even be empty.
41+
use_default_filter_criterion: Whether to use default filter criteria or not
4142
k: How many eigenvalues are to be computed, has a min. value of 1.
4243
use_default_filter_criterion: whether to use the transformation's default filter
4344
criterion if ``filter_criterion`` is ``None``.
@@ -47,8 +48,8 @@ def __init__(self,
4748
self._use_default_filter_criterion = use_default_filter_criterion
4849

4950
@property
50-
def filter_criterion(self) -> Callable[[Union[List, np.ndarray], float, Optional[List[float]]],
51-
bool]:
51+
def filter_criterion(self) -> Callable[[Union[List, np.ndarray], float,
52+
Optional[List[float]]], bool]:
5253
""" returns filter criterion """
5354
return self._filter_criterion
5455

@@ -79,11 +80,11 @@ def use_default_filter_criterion(self, value: bool) -> None:
7980
""" sets whether to use the default filter criterion """
8081
self._use_default_filter_criterion = value
8182

82-
def get_solver(self, transformation: FermionicTransformation) -> Eigensolver:
83+
def get_solver(self, transformation: Transformation) -> Eigensolver:
8384
"""Returns a NumPyEigensolver with the desired filter
8485
8586
Args:
86-
transformation: a fermionic qubit operator transformation.
87+
transformation: a fermionic/bosonic qubit operator transformation.
8788
8889
Returns:
8990
A NumPyEigensolver suitable to compute the ground state of the molecule

qiskit/chemistry/algorithms/excited_states_solvers/excited_states_eigensolver.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
"""The calculation of excited states via an Eigensolver algorithm"""
1414

1515
import logging
16-
1716
from typing import List, Union, Optional, Any
1817

1918
from qiskit.aqua.algorithms import Eigensolver
2019
from qiskit.aqua.operators import WeightedPauliOperator
2120
from qiskit.chemistry import FermionicOperator
2221
from qiskit.chemistry.drivers import BaseDriver
23-
from qiskit.chemistry.results import EigenstateResult
22+
from qiskit.chemistry.results import (EigenstateResult,
23+
ElectronicStructureResult,
24+
VibronicStructureResult)
2425
from qiskit.chemistry.transformations import Transformation
25-
from qiskit.chemistry.results import ElectronicStructureResult, VibronicStructureResult
2626

2727
from .excited_states_solver import ExcitedStatesSolver
2828
from .eigensolver_factories import EigensolverFactory

qiskit/chemistry/algorithms/ground_state_solvers/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818
from .ground_state_eigensolver import GroundStateEigensolver
1919
from .minimum_eigensolver_factories import (MinimumEigensolverFactory,
2020
NumPyMinimumEigensolverFactory,
21-
VQEUCCSDFactory)
22-
21+
VQEUCCSDFactory,
22+
VQEUVCCSDFactory)
2323

2424
__all__ = ['GroundStateSolver',
2525
'AdaptVQE',
2626
'OrbitalOptimizationVQE',
2727
'GroundStateEigensolver',
2828
'MinimumEigensolverFactory',
2929
'NumPyMinimumEigensolverFactory',
30-
'VQEUCCSDFactory'
30+
'VQEUCCSDFactory',
31+
'VQEUVCCSDFactory',
3132
]

qiskit/chemistry/algorithms/ground_state_solvers/ground_state_eigensolver.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,6 @@ def solve(self,
8484
An eigenstate result. Depending on the transformation this can be an electronic
8585
structure or bosonic result.
8686
"""
87-
if aux_operators is not None:
88-
if any(not isinstance(op, (WeightedPauliOperator, FermionicOperator))
89-
for op in aux_operators):
90-
raise NotImplementedError('Currently only fermionic problems are supported.')
91-
9287
# get the operator and auxiliary operators, and transform the provided auxiliary operators
9388
# note that ``aux_operators`` contains not only the transformed ``aux_operators`` passed
9489
# by the user but also additional ones from the transformation

qiskit/chemistry/algorithms/ground_state_solvers/minimum_eigensolver_factories/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
from .minimum_eigensolver_factory import MinimumEigensolverFactory
1616
from .numpy_minimum_eigensolver_factory import NumPyMinimumEigensolverFactory
1717
from .vqe_uccsd_factory import VQEUCCSDFactory
18+
from .vqe_uvccsd_factory import VQEUVCCSDFactory
1819

1920
__all__ = ['MinimumEigensolverFactory',
2021
'NumPyMinimumEigensolverFactory',
21-
'VQEUCCSDFactory'
22+
'VQEUCCSDFactory',
23+
'VQEUVCCSDFactory'
2224
]

0 commit comments

Comments
 (0)