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

Suppress warnings from Qiskit Nature #230

Merged
merged 17 commits into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 2 additions & 2 deletions circuit_knitting/forging/cholesky_decomposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ def convert_cholesky_operator(
ansatz: EntanglementForgingAnsatz,
) -> EntanglementForgingOperator:
"""
Convert the Cholesky operator (List[PauliSumOp]) into the entanglement forging format.
Convert the Cholesky operator (List[SparsePauliOp]) into the entanglement forging format.

Args:
operator: A `List[PauliSumOp]` containing the single-body Hamiltonian followed
operator: A `List[SparsePauliOp]` containing the single-body Hamiltonian followed
by the Cholesky operators
shape: [single-body hamiltonian, cholesky_0, ..., cholesky_N]
ansatz: The ansatz for which to compute expectation values of operator. The
Expand Down
28 changes: 26 additions & 2 deletions circuit_knitting_toolbox/entanglement_forging/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
)
import circuit_knitting.forging.cholesky_decomposition as cholesky_module

from qiskit_nature import settings

settings.use_pauli_sum_op = False

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines actually need to be moved to circuit_knitting/forging/__init__.py now that #244 is merged.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And it'd be great if you could add a comment above it:

From now forward, the entanglement forging module requires that SparsePauliOp be used rather than PauliSumOp, as the latter is deprecated in Qiskit Terra 0.24. However, Qiskit Nature still is not expected to change this default until Qiskit Nature 0.7. Here, we modify the global state to opt into the new behavior early. Unfortunately, this means that any code that calls Qiskit Nature in the same process as entanglement forging will need to be updated to use SparsePauliOp as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, once we finally figure out the magic to get everything working, we should double check that this block is actually required to get tests to pass. The migration guide suggests that it is not always necessary to change this setting. If you provide a SparsePauliOp to a function that returns an operator, it should result in a SparsePauliOp regardless of this setting, from what I understand.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this was in fact added after a discussion between @caleb-johnson and Max (Rossmannek). He suggested that we can suppress the warnings with these settings until opflow is dropped, which will be in the 0.8.0 release.

__all__ = [
"EntanglementForgingAnsatz",
"EntanglementForgingKnitter",
Expand All @@ -37,6 +41,26 @@
"convert_cholesky_operator",
]

from qiskit_nature import settings
sys.modules[
"circuit_knitting_toolbox.entanglement_forging.cholesky_decomposition"
] = cholesky_module
sys.modules[
"circuit_knitting_toolbox.entanglement_forging.entanglement_forging_ansatz"
] = entanglement_forging_ansatz
sys.modules[
"circuit_knitting_toolbox.entanglement_forging.entanglement_forging_ground_state_solver"
] = entanglement_forging_ground_state_solver
sys.modules[
"circuit_knitting_toolbox.entanglement_forging.entanglement_forging_knitter"
] = entanglement_forging_knitter
sys.modules[
"circuit_knitting_toolbox.entanglement_forging.entanglement_forging_operator"
] = entanglement_forging_operator

settings.use_pauli_sum_op = False
warn(
f"The package namespace {__name__} is deprecated and will be removed "
"no sooner than Circuit Knitting Toolbox 0.4.0. Use namespace "
"circuit_knitting.forging instead.",
DeprecationWarning,
stacklevel=2,
)