Skip to content

Commit

Permalink
Fix #192 (#193) (#195)
Browse files Browse the repository at this point in the history
* Add regression test against #192

* Fix #192

* Add reno

* Run black

Co-authored-by: Max Rossmannek <[email protected]>
  • Loading branch information
manoelmarques and mrossinek authored May 19, 2021
1 parent 18bbb43 commit 00b6091
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,10 @@ def symmetry_sector_locator(self, z2_symmetries: Z2Symmetries) -> Optional[List[
Returns:
The sector of the tapered operators with the problem solution.
"""
q_molecule = cast(QMolecule, self._molecule_data_transformed)

hf_bitstr = hartree_fock_bitstring(
num_spin_orbitals=2 * q_molecule.num_molecular_orbitals,
num_particles=self.num_particles)
num_spin_orbitals=z2_symmetries.symmetries[0].num_qubits,
num_particles=self.num_particles,
)
sector_locator = ElectronicStructureProblem._pick_sector(z2_symmetries, hf_bitstr)

return sector_locator
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
fixes:
- |
The `FreezeCoreTransformer` (and `ActiveSpaceTransformer`) were incompatible with the automatic
`Z2Symmetry` reduction. This issue was fixed by correcting the
`ElectronicStructureProblem.symmetry_sector_locator` method.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@
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.problems.second_quantization.electronic.builders.fermionic_op_builder import \
build_ferm_op_from_ints
from qiskit_nature.problems.second_quantization.electronic.builders.fermionic_op_builder import (
build_ferm_op_from_ints,
)
from qiskit_nature.transformers import FreezeCoreTransformer


class TestGroundStateEigensolver(QiskitNatureTestCase):
Expand Down Expand Up @@ -376,6 +378,26 @@ def test_uccsd_hf_aer_qasm_snapshot(self):
result = gsc.solve(self.electronic_structure_problem)
self.assertAlmostEqual(result.total_energies[0], self.reference_energy, places=3)

def test_freeze_core_z2_symmetry_compatibility(self):
"""Regression test against #192.
An issue arose when the FreezeCoreTransformer was combined with the automatic Z2Symmetry
reduction. This regression test ensures that this behavior remains fixed.
"""
driver = HDF5Driver(hdf5_input=self.get_resource_path("LiH_sto3g.hdf5", "transformers"))
problem = ElectronicStructureProblem(driver, [FreezeCoreTransformer()])
qubit_converter = QubitConverter(
ParityMapper(),
two_qubit_reduction=True,
z2symmetry_reduction="auto",
)

solver = NumPyMinimumEigensolverFactory()
gsc = GroundStateEigensolver(qubit_converter, solver)

result = gsc.solve(problem)
self.assertAlmostEqual(result.total_energies[0], -7.882, places=2)


if __name__ == '__main__':
unittest.main()

0 comments on commit 00b6091

Please sign in to comment.