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

Unwrap Tensor objects from Qiskit Nature as necessary #408

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions .github/workflows/test_development_versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ jobs:
python -m pip install --upgrade pip tox
python -m pip install toml typer
python tools/extremal-python-dependencies.py pin-dependencies \
"qiskit @ git+https://github.com/Qiskit/qiskit.git" \
"qiskit-nature @ git+https://github.com/qiskit-community/qiskit-nature.git" \
"qiskit-ibm-runtime @ git+https://github.com/Qiskit/qiskit-ibm-runtime.git" \
--inplace
- name: Modify tox.ini for more thorough check
Expand Down
8 changes: 8 additions & 0 deletions circuit_knitting/forging/cholesky_decomposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
to_chemist_ordering,
to_physicist_ordering,
)
from qiskit_nature.second_q.operators.symmetric_two_body import (
SymmetricTwoBodyIntegrals,
unfold,
)

from .entanglement_forging_ansatz import EntanglementForgingAnsatz
from .entanglement_forging_operator import EntanglementForgingOperator
Expand Down Expand Up @@ -84,6 +88,10 @@ def cholesky_decomposition(
eri = to_chemist_ordering(
problem.hamiltonian.electronic_integrals.two_body.alpha["++--"]
)
if isinstance(hcore, SymmetricTwoBodyIntegrals):
hcore = unfold(hcore)
if isinstance(eri, SymmetricTwoBodyIntegrals):
eri = unfold(eri)
num_alpha = problem.num_alpha
if num_alpha is None:
raise ValueError(
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies = [
"qiskit-aer>=0.12.0",
"qiskit>=0.44.1",
"qiskit-algorithms>=0.2.1",
"qiskit-nature>=0.6.0, <0.7",
"qiskit-nature>=0.6.0",
"qiskit-ibm-runtime>=0.12.2",
]

Expand Down
5 changes: 5 additions & 0 deletions test/forging/test_entanglement_forging_ground_state_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from qiskit_nature.second_q.transformers import ActiveSpaceTransformer
from qiskit_nature.second_q.formats import get_ao_to_mo_from_qcschema
from qiskit_nature.second_q.hamiltonians import ElectronicEnergy
from qiskit_nature.second_q.operators import Tensor

from circuit_knitting.forging import (
EntanglementForgingAnsatz,
Expand Down Expand Up @@ -105,6 +106,10 @@ def test_entanglement_forging_vqe_hydrogen(self):
problem = driver.to_problem(basis=ElectronicBasis.AO)
qcschema = driver.to_qcschema()
mo_coeff = get_ao_to_mo_from_qcschema(qcschema).coefficients.alpha["+-"]
if isinstance(mo_coeff, Tensor):
# Unwrap the Tensor in Qiskit Nature 0.7 and later
# to be compatible with qiskit-nature/pull/1248
mo_coeff = mo_coeff.array

# Specify the ansatz and bitstrings
ansatz = EntanglementForgingAnsatz(
Expand Down
9 changes: 9 additions & 0 deletions test/forging/test_entanglement_forging_knitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from qiskit_nature.second_q.problems import ElectronicStructureProblem, ElectronicBasis
from qiskit_nature.second_q.hamiltonians import ElectronicEnergy
from qiskit_nature.second_q.formats import get_ao_to_mo_from_qcschema
from qiskit_nature.second_q.operators import Tensor

from circuit_knitting.forging import (
EntanglementForgingAnsatz,
Expand Down Expand Up @@ -99,6 +100,10 @@ def test_entanglement_forging_H2(self):

# Specify the decomposition method and get the forged operator
mo_coeff = get_ao_to_mo_from_qcschema(qcschema).coefficients.alpha["+-"]
if isinstance(mo_coeff, Tensor):
# Unwrap the Tensor in Qiskit Nature 0.7 and later
# to be compatible with qiskit-nature/pull/1248
mo_coeff = mo_coeff.array
hamiltonian_terms, energy_shift = cholesky_decomposition(
problem, mo_coeff=mo_coeff
)
Expand Down Expand Up @@ -175,6 +180,10 @@ def test_entanglement_forging_H2O(self): # pylint: disable=too-many-locals

# Specify the decomposition method and get the forged operator
mo_coeff = get_ao_to_mo_from_qcschema(qcschema).coefficients.alpha["+-"]
if isinstance(mo_coeff, Tensor):
# Unwrap the Tensor in Qiskit Nature 0.7 and later
# to be compatible with qiskit-nature/pull/1248
mo_coeff = mo_coeff.array
hamiltonian_terms, energy_shift = cholesky_decomposition(
problem, mo_coeff=mo_coeff, orbitals_to_reduce=orbitals_to_reduce
)
Expand Down
Loading