Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seniority zero transformer #640

Closed
Closed
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1ed8d50
Add first version of SeniorityZeroTransformer
jschuhmac Apr 19, 2022
4210b07
Updates recursive transformation of properties in active space transf…
jschuhmac Apr 19, 2022
2f54629
Fix typos and remove mypy errors
jschuhmac Apr 21, 2022
3627c23
Add function to remove properties from GroupedProperty
jschuhmac Apr 21, 2022
2d67cd8
Explicitly remove properties that are not transformed by transformer.
jschuhmac Apr 21, 2022
3922754
Merge branch 'main' into seniority_zero_transformer
mrossinek Apr 22, 2022
4bbd5e8
Implement review suggestions
jschuhmac Apr 22, 2022
540a2fb
Add test for building the restricted second_q_ops.
jschuhmac Apr 22, 2022
0141898
Update qiskit_nature/transformers/second_quantization/electronic/__in…
jschuhmac Apr 22, 2022
7d1ba21
Merge branch 'main' into seniority_zero_transformer
jschuhmac Apr 25, 2022
dbb32ac
Raise error if alpha and beta integrals are not identical
jschuhmac Apr 25, 2022
304425c
Make monkeypatching methods private
jschuhmac Apr 25, 2022
4c91280
Update reno and docstring of SeniorityZeroTransformer
jschuhmac Apr 27, 2022
9000963
Add unittest for remove_property of GroupedProperty
jschuhmac Apr 27, 2022
f22d947
Merge branch 'main' into seniority_zero_transformer
jschuhmac Apr 27, 2022
9adb4d4
Fix CI issues
jschuhmac Apr 27, 2022
99abd12
Fix CI issues
jschuhmac Apr 27, 2022
729bdf7
Merge branch 'main' into seniority_zero_transformer
jschuhmac Apr 28, 2022
f76cd3e
Re-format docstring
jschuhmac Apr 28, 2022
2b75780
Merge branch 'main' into seniority_zero_transformer
jschuhmac May 3, 2022
2e41997
Mention dropping of properties in docstring
jschuhmac May 3, 2022
867cd4e
Update how unsupported properties are handled.
jschuhmac May 4, 2022
f3cfc62
Fix CI issues
jschuhmac May 4, 2022
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
1 change: 1 addition & 0 deletions .pylintdict
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ scipy
sd
sdg
sdt
seniorityzerotransformer
serine
setia
setted
Expand Down
16 changes: 16 additions & 0 deletions qiskit_nature/properties/grouped_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ def add_property(self, prop: Optional[T_co]) -> None:
name = prop.__class__.__name__
self._properties[name] = prop

def remove_property(self, prop: Union[str, Type[Property]]) -> Optional[T_co]:
"""Removes a property from the group.

Args:
prop: the name or type of the property to remove from the group.

Returns:
The removed property (or None).
"""
name: str
if isinstance(prop, str):
name = prop
else:
name = prop.__name__
return self._properties.pop(name, None)

def get_property(self, prop: Union[str, Type[Property]]) -> Optional[T_co]:
"""Gets a property from the group.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2021.
# (C) Copyright IBM 2021, 2022.
#
# 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 All @@ -27,13 +27,16 @@

ActiveSpaceTransformer
FreezeCoreTransformer
SeniorityZeroTransformer

"""

from .active_space_transformer import ActiveSpaceTransformer
from .freeze_core_transformer import FreezeCoreTransformer
from .seniority_zero_transformer import SeniorityZeroTransformer

__all__ = [
"ActiveSpaceTransformer",
"FreezeCoreTransformer",
"SeniorityZeroTransformer",
]
Original file line number Diff line number Diff line change
Expand Up @@ -367,24 +367,13 @@ def _transform_property(self, prop: Property) -> Property:
if isinstance(prop, GroupedProperty):
transformed_property = deepcopy(prop)

# Get the iterator of the Group's properties. We access __iter__() directly to make
# mypy happy :-)
iterator = transformed_property.__iter__()

transformed_internal_property = None
while True:
try:
# Send the transformed internal property to the GroupedProperty generator.
# NOTE: in the first iteration, this variable is None, which is equivalent to
# starting the iterator.
# NOTE: a Generator's send method returns the iterators next value [2].
# [2]: https://docs.python.org/3/reference/expressions.html#generator.send
internal_property = iterator.send(transformed_internal_property)
except StopIteration:
break

for internal_property in iter(prop):
try:
transformed_internal_property = self._transform_property(internal_property)
if transformed_internal_property is not None:
transformed_property.add_property(transformed_internal_property)
else:
transformed_property.remove_property(internal_property.name)
except TypeError:
logger.warning(
"The Property %s of type %s could not be transformed!",
Expand All @@ -393,6 +382,9 @@ def _transform_property(self, prop: Property) -> Property:
)
continue

if len(transformed_property._properties) == 0:
transformed_property = None

elif isinstance(prop, IntegralProperty):
# get matrix operator of IntegralProperty
fock_operator = prop.integral_operator(self._density_inactive)
Expand Down
Loading