Skip to content

Commit

Permalink
Introduction of Property objects (#220)
Browse files Browse the repository at this point in the history
* [WIP] ElectronicEnergy Property object

* Generalize to n-body integrals

* Extract fermionic op builder for electronic energy

* [WIP] ParticleNumber Property

* Fix lint

* Add remaining aux_op-based properties

* Make tests slow again (as they used to be)

* Fix some matrix dimensions

We really need to properly handle different bases...

* WIP: prepare proper Basis handling

* Add simple BasisTransform

* Remove register_length from Property base class

* Do not use future annotations to support Python 3.6

* Fix lint

* Fix _2BodyElectronicIntegrals.to_spin

* Fix mypy in CI

* Very, VERY (!!!) early PoC vibrational integrals

* WIP: some improvements

* Add OccupiedModals property

* Some cleanup

* Fix spell

* Fix lint

* Allow empty operator initialization

* Revert "Allow empty operator initialization"

This reverts commit 3692340.

* Fix empty op case in VibrationalOp

* Simplify some properties

* Some naming updates

* Fix DipoleMoment

* Restructure properties submodule

* Fix style

* Fix mypy

* Fix spell

* Prepare property unittests

* Prepare properties documentation

* Address TODOs in properties.electronic

* Fix spell

* Address TODOs in properties.vibrational

* Add TODOs in structure problem classes

* Add unittests for ElectronicIntegrals

* Add unittests for HarmonicBasis

* Remove unused test directories

- electronic bases are merely static files which cannot really be tested
- vibrational integrals can basically only be tested as part of the vibrational basis tests

* Add HarmonicBasis operator construction tests

* Fix lint

* Remove unused builder utilities

Unfortunately, the UVCC and CHC unittests still rely on one of the removed, private methods.
For now, I moved them to the unittest suite but we will properly migrate those tests in the future.

* Fix auto-generated docs stubs

* Add some TODO marks for the future

* Fix spell

* De-duplicate code

* Use names for special ints/floats

* Extract input type validation

* Make naming consistent

* Remove unused imports

* Extract raw testing resources

* Fix docstring titles

* Fix Property valid type assertion

* Add Property base class tests

* Add vibrational property tests

* Add electronic property tests

* Fix linters

* Update docstring

* Remove interpret method stub from subclasses for now

* Make ElectronicBasisTransform variables public

* Extract common base class for ElectronicEnergy and DipoleMoment

* Replace raw assert statements

* Expose ERI_TRUNCATION_LEVEL overwrite option

* Fix linters

* Fix mypy

* Remove unused import

* Relocate qiskit_nature.properties to qiskit_nature.properties.second_quantization

* Fix mypy in CI

* Add missing docs

* Extract validation methods

* Extract integral threshold

* Simplify OccupiedModals

Co-authored-by: Dariusz Lasecki <dal@zurich.ibm.com>

* Replace bare assert statements

Co-authored-by: Dariusz Lasecki <dal@zurich.ibm.com>
  • Loading branch information
mrossinek and Dariusz Lasecki committed Jun 25, 2021
1 parent bc2162b commit b4a46bf
Show file tree
Hide file tree
Showing 95 changed files with 3,157 additions and 906 deletions.
2 changes: 2 additions & 0 deletions .pylintdict
Expand Up @@ -91,6 +91,7 @@ eigensolution
eigensolver
eigensolvers
eigenstate
eigenstateresult
eigenstates
einact
endian
Expand Down Expand Up @@ -360,6 +361,7 @@ untransforms
uvcc
vals
variational
verbatim
vibrational
vibrationalop
vibro
Expand Down
6 changes: 6 additions & 0 deletions docs/apidocs/qiskit_nature.properties.rst
@@ -0,0 +1,6 @@
.. _qiskit_nature-properties:

.. automodule:: qiskit_nature.properties
:no-members:
:no-inherited-members:
:no-special-members:
@@ -0,0 +1,6 @@
.. _qiskit_nature-properties-second_quantization-electronic-bases:

.. automodule:: qiskit_nature.properties.second_quantization.electronic.bases
:no-members:
:no-inherited-members:
:no-special-members:
@@ -0,0 +1,6 @@
.. _qiskit_nature-properties-second_quantization-electronic-integrals:

.. automodule:: qiskit_nature.properties.second_quantization.electronic.integrals
:no-members:
:no-inherited-members:
:no-special-members:
@@ -0,0 +1,6 @@
.. _qiskit_nature-properties-second_quantization-electronic:

.. automodule:: qiskit_nature.properties.second_quantization.electronic
:no-members:
:no-inherited-members:
:no-special-members:
6 changes: 6 additions & 0 deletions docs/apidocs/qiskit_nature.properties.second_quantization.rst
@@ -0,0 +1,6 @@
.. _qiskit_nature-properties-second_quantization:

.. automodule:: qiskit_nature.properties.second_quantization
:no-members:
:no-inherited-members:
:no-special-members:
@@ -0,0 +1,6 @@
.. _qiskit_nature-properties-second_quantization-vibrational-bases:

.. automodule:: qiskit_nature.properties.second_quantization.vibrational.bases
:no-members:
:no-inherited-members:
:no-special-members:
@@ -0,0 +1,6 @@
.. _qiskit_nature-properties-second_quantization-vibrational-integrals:

.. automodule:: qiskit_nature.properties.second_quantization.vibrational.integrals
:no-members:
:no-inherited-members:
:no-special-members:
@@ -0,0 +1,6 @@
.. _qiskit_nature-properties-second_quantization-vibrational:

.. automodule:: qiskit_nature.properties.second_quantization.vibrational
:no-members:
:no-inherited-members:
:no-special-members:
1 change: 1 addition & 0 deletions qiskit_nature/__init__.py
Expand Up @@ -41,6 +41,7 @@
mappers
operators
problems
properties
results
runtime
transformers
Expand Down
24 changes: 24 additions & 0 deletions qiskit_nature/operators/second_quantization/fermionic_op.py
Expand Up @@ -357,3 +357,27 @@ def _to_sparse_label(label):
return " ".join(
filter(None, (label_transformation[c].format(i=i) for i, c in enumerate(label)))
)

@classmethod
def zero(cls, register_length: int) -> "FermionicOp":
"""Constructs a zero-operator.
Args:
register_length: the length of the operator.
Returns:
The zero-operator of the given length.
"""
return FermionicOp(("I_0", 0.0), register_length=register_length)

@classmethod
def one(cls, register_length: int) -> "FermionicOp":
"""Constructs a unity-operator.
Args:
register_length: the length of the operator.
Returns:
The unity-operator of the given length.
"""
return FermionicOp(("I_0", 1.0), register_length=register_length)
40 changes: 40 additions & 0 deletions qiskit_nature/operators/second_quantization/vibrational_op.py
Expand Up @@ -546,3 +546,43 @@ def _build_dense_label(self, label: str, partial_sum_modals: List[int]) -> Tuple
op, mode_index, modal_index = re.split("[*_]", label)
index = partial_sum_modals[int(mode_index)] + int(modal_index)
return (op, index)

@classmethod
def zero(cls, num_modes: int, num_modals: Union[int, List[int]]) -> "VibrationalOp":
"""Constructs a zero-operator.
Args:
num_modes : number of modes.
num_modals: number of modals - described by a list of integers where each integer
describes the number of modals in a corresponding mode; in case of the
same number of modals in each mode it is enough to provide an integer
that describes the number of them; the total number of modals defines a
`register_length`
Returns:
The zero-operator of the given length.
"""
if isinstance(num_modals, int):
num_modals = [num_modals] * num_modes

return VibrationalOp(("I" * sum(num_modals), 0.0), num_modes, num_modals)

@classmethod
def one(cls, num_modes: int, num_modals: Union[int, List[int]]) -> "VibrationalOp":
"""Constructs a unity-operator.
Args:
num_modes : number of modes.
num_modals: number of modals - described by a list of integers where each integer
describes the number of modals in a corresponding mode; in case of the
same number of modals in each mode it is enough to provide an integer
that describes the number of them; the total number of modals defines a
`register_length`
Returns:
The unity-operator of the given length.
"""
if isinstance(num_modals, int):
num_modals = [num_modals] * num_modes

return VibrationalOp(("I" * sum(num_modals), 1.0), num_modes, num_modals)

This file was deleted.

This file was deleted.

Expand Up @@ -12,6 +12,8 @@

"""Utility methods to build fermionic hopping operators."""

# TODO: re-implement these as properties?

from typing import cast, Callable, Dict, List, Tuple, Union

from qiskit.opflow import PauliSumOp
Expand Down

0 comments on commit b4a46bf

Please sign in to comment.