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 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

import numpy as np

from qiskit.opflow import PauliSumOp
from qiskit.quantum_info import Pauli
from qiskit.quantum_info.operators.symplectic import SparsePauliOp
from qiskit_nature.second_q.problems import ElectronicStructureProblem
from qiskit_nature.second_q.mappers import QubitConverter, JordanWignerMapper
from qiskit_nature.second_q.mappers import JordanWignerMapper
from qiskit_nature.second_q.operators import (
FermionicOp,
PolynomialTensor,
Expand All @@ -34,10 +34,14 @@
from .entanglement_forging_ansatz import EntanglementForgingAnsatz
from .entanglement_forging_operator import EntanglementForgingOperator

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.

Since it may violate a user's expectations to modify global state like this, it deserves some comments here of why it's necessary and also deserves mention in the release notes. (At least it is a temporary thing, and will have no effect on Qiskit Nature versions 0.7 and higher.)

Copy link
Member

Choose a reason for hiding this comment

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

Also, it might be better to move this one level up, to entanglement_forging/__init__.py, for increased visibility.


def get_cholesky_op(
l_op: np.ndarray, g: int, converter: QubitConverter, opname: str
) -> PauliSumOp:
l_op: np.ndarray, g: int, converter: JordanWignerMapper, opname: str
) -> SparsePauliOp:
"""
Convert a two-body term into a cholesky operator.

Expand All @@ -52,7 +56,7 @@ def get_cholesky_op(
"""
pt = PolynomialTensor({"+-": l_op[:, :, g]})
fer_op = FermionicOp.from_polynomial_tensor(pt)
cholesky_op = converter.convert(fer_op)
cholesky_op = converter.map(fer_op)
cholesky_op._name = opname + "_chol" + str(g)

return cholesky_op
Expand All @@ -62,7 +66,7 @@ def cholesky_decomposition(
problem: ElectronicStructureProblem,
mo_coeff: np.ndarray | None = None,
orbitals_to_reduce: Sequence[int] | None = None,
) -> tuple[list[PauliSumOp], float]:
) -> tuple[list[SparsePauliOp], float]:
"""
Construct the decomposed Hamiltonian from an input ``ElectronicStructureProblem``.

Expand Down Expand Up @@ -124,7 +128,7 @@ def cholesky_decomposition(


def convert_cholesky_operator(
operator: list[PauliSumOp],
operator: list[SparsePauliOp],
ansatz: EntanglementForgingAnsatz,
) -> EntanglementForgingOperator:
"""
Expand Down Expand Up @@ -153,11 +157,7 @@ def convert_cholesky_operator(
tensor_paulis = set()
superpos_paulis = set()
paulis_each_op = [
{
label: weight
for label, weight in op.primitive.to_list()
if np.abs(weight) > 0
}
{label: weight for label, weight in op.to_list() if np.abs(weight) > 0}
for op in [op1] + list(cholesky_ops)
]

Expand Down Expand Up @@ -242,7 +242,7 @@ def _get_fermionic_ops_with_cholesky(
occupied_orbitals_to_reduce: np.ndarray | None = None,
virtual_orbitals_to_reduce: np.ndarray | None = None,
epsilon_cholesky: float = 1e-10,
) -> tuple[PauliSumOp, list[PauliSumOp], float, np.ndarray, np.ndarray,]:
) -> tuple[SparsePauliOp, list[SparsePauliOp], float, np.ndarray, np.ndarray,]:
r"""
Decompose the Hamiltonian operators into a form appropriate for entanglement forging.

Expand Down Expand Up @@ -335,11 +335,10 @@ def _get_fermionic_ops_with_cholesky(
if halve_transformed_h2:
h2 /= 2 # type: ignore

converter = QubitConverter(JordanWignerMapper())
converter = JordanWignerMapper()
pt = PolynomialTensor({"+-": h1, "++--": to_physicist_ordering(h2)})
fer_op = FermionicOp.from_polynomial_tensor(pt)
qubit_op = converter.convert(fer_op)

qubit_op = converter.map(fer_op)
qubit_op._name = opname + "_onebodyop"

cholesky_ops = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
ElectronicBasis,
)
from qiskit_ibm_runtime import QiskitRuntimeService, Options
from qiskit.opflow import PauliSumOp
from qiskit.quantum_info.operators.symplectic import SparsePauliOp

from .entanglement_forging_ansatz import EntanglementForgingAnsatz
from .entanglement_forging_knitter import EntanglementForgingKnitter
Expand Down Expand Up @@ -363,7 +363,7 @@ def evaluate_eigenvalue(parameters: Sequence[float]) -> float:
def get_qubit_operators(
self,
problem: ElectronicStructureProblem,
) -> list[PauliSumOp]:
) -> list[SparsePauliOp]:
"""Construct decomposed qubit operators from an ``ElectronicStructureProblem``.

Args:
Expand Down