Closed HuangJunye closed 2 years ago
Here's the gist of a notebook reproducing the error: https://gist.github.com/HuangJunye/cce1a2c2f6a04cc865eeb54170288acb
This issue boils down to a mismatching qubit operator of the ground state Hamiltonian and the hopping operators. All of these are checked for their commutativity. QEOM appears to rely on using the untapered qubit op here. However, the hopping operators are actually already being mapped+reduced+tapered. This causes a mismatch.
The question is now whether the reliance on using the untapered operator is actually required or whether using convert_match
instead of map
on the line linked above is sufficient. It appears to fix this particular bug but it will still cause problems when using z2symmetry_reduction="auto"
(in which case a straight forward test appears to run into the same issue as #342).
If QEOM needs to perform tapering manually then the internal Z2Symmetry which is being used inside of TwoQubitReduction
needs to be made available in QubitConverter.z2symmetries
(which is where QEOM gets the symmetry information from).
Here is a "partial fix" which changes map -> convert_match
and adds two unittests for QEOM:
Z2Symmetries
(which runs into [EDIT: here used to be a linked issue. But it was the wrong ID and I don't recall which one was supposed to be linked to.]) diff --git a/qiskit_nature/algorithms/excited_states_solvers/qeom.py b/qiskit_nature/algorithms/excited_states_solvers/qeom.py
index d0987c189..8b98c0252 100644
--- a/qiskit_nature/algorithms/excited_states_solvers/qeom.py
+++ b/qiskit_nature/algorithms/excited_states_solvers/qeom.py
@@ -105,7 +105,7 @@ class QEOM(ExcitedStatesSolver):
groundstate_result = self._gsc.solve(problem)
# 2. Prepare the excitation operators
- self._untapered_qubit_op_main = self._gsc._qubit_converter.map(problem.second_q_ops()[0])
+ self._untapered_qubit_op_main = self._gsc._qubit_converter.convert_match(problem.second_q_ops()[0])
matrix_operators_dict, size = self._prepare_matrix_operators(problem)
# 3. Evaluate eom operators
diff --git a/test/algorithms/excited_state_solvers/test_excited_states_solvers.py b/test/algorithms/excited_state_solvers/test_excited_states_solvers.py
index f1eac8f7e..34c5e859b 100644
--- a/test/algorithms/excited_state_solvers/test_excited_states_solvers.py
+++ b/test/algorithms/excited_state_solvers/test_excited_states_solvers.py
@@ -21,7 +21,7 @@ from qiskit.algorithms import NumPyMinimumEigensolver, NumPyEigensolver
from qiskit_nature.drivers import UnitsType
from qiskit_nature.drivers.second_quantization import PySCFDriver
-from qiskit_nature.mappers.second_quantization import JordanWignerMapper
+from qiskit_nature.mappers.second_quantization import JordanWignerMapper, ParityMapper
from qiskit_nature.converters.second_quantization import QubitConverter
from qiskit_nature.problems.second_quantization import ElectronicStructureProblem
from qiskit_nature.algorithms import (
@@ -85,6 +85,28 @@ class TestNumericalQEOMESCCalculation(QiskitNatureTestCase):
for idx, energy in enumerate(self.reference_energies):
self.assertAlmostEqual(results.computed_energies[idx], energy, places=4)
+ def test_vqe_mes_2q(self):
+ """Test VQEUCCSDFactory with QEOM and 2-qubit reduction"""
+ converter = QubitConverter(ParityMapper(), two_qubit_reduction=True)
+ solver = VQEUCCFactory(self.quantum_instance)
+ gsc = GroundStateEigensolver(converter, solver)
+ esc = QEOM(gsc, "sd")
+ results = esc.solve(self.electronic_structure_problem)
+
+ for idx, energy in enumerate(self.reference_energies):
+ self.assertAlmostEqual(results.computed_energies[idx], energy, places=4)
+
+ def test_vqe_mes_z2(self):
+ """Test VQEUCCSDFactory with QEOM and Z2Symmetries"""
+ converter = QubitConverter(ParityMapper(), two_qubit_reduction=True, z2symmetry_reduction="auto")
+ solver = VQEUCCFactory(self.quantum_instance)
+ gsc = GroundStateEigensolver(converter, solver)
+ esc = QEOM(gsc, "sd")
+ results = esc.solve(self.electronic_structure_problem)
+
+ for idx, energy in enumerate(self.reference_energies):
+ self.assertAlmostEqual(results.computed_energies[idx], energy, places=4)
+
def test_numpy_factory(self):
"""Test NumPyEigenSolverFactory with ExcitedStatesEigensolver"""
Information
What is the current behavior?
Error message:
QiskitError: 'Sum of amplitudes-squared does not equal one.'
Steps to reproduce the problem
Add these code after the example code in the README.
What is the expected behavior?
Returns ElectronicStructureResult. This is the result when
two_qubit_reduction
is set toFalse
inQubitConverter
:Suggested solutions