qiskit-community / qiskit-nature

Qiskit Nature is an open-source, quantum computing, framework for solving quantum mechanical natural science problems.
https://qiskit-community.github.io/qiskit-nature/
Apache License 2.0
303 stars 205 forks source link

Having problem to use Freeze core function #163

Closed anhph closed 3 years ago

anhph commented 3 years ago

Information

What is the current behavior?

when apply FreezeCoreTransformer to driver, and pass it to ElectronicStructureProblem, the problem second_q_ops doesn't work

Steps to reproduce the problem

from qiskit_nature.drivers import PySCFDriver, UnitsType
from qiskit_nature.problems.second_quantization.electronic import ElectronicStructureProblem
from qiskit_nature.transformers import FreezeCoreTransformer
# Use PySCF, a classical computational chemistry software
# package, to compute the one-body and two-body integrals in
# electronic-orbital basis, necessary to form the Fermionic operator
driver = PySCFDriver(atom='O 0.0 0.0 0.0; H 0.757 0.586 0.0; H -0.757 0.586 0.0',
                     unit=UnitsType.ANGSTROM, charge=0, spin=0, basis='sto3g')

problem = ElectronicStructureProblem(FreezeCoreTransformer(driver))

second_q_ops = problem.second_q_ops()

gives

Traceback (most recent call last):
  File "<ipython-input-40-4d83576b02ea>", line 12, in <module>
    second_q_ops = problem.second_q_ops()
  File "/opt/conda/lib/python3.8/site-packages/qiskit_nature/problems/second_quantization/electronic/electronic_structure_problem.py", line 66, in second_q_ops
    self._molecule_data = cast(QMolecule, self.driver.run())
AttributeError: 'FreezeCoreTransformer' object has no attribute 'run'

Use %tb to get the full traceback.

What is the expected behavior?

Suggested solutions

woodsp-ibm commented 3 years ago

The ElectronicStructureProblem takes a driver and list of transformers, so you would do it like this

problem = ElectronicStructureProblem(driver, transformers=[FreezeCoreTransformer()])

See API ref doc here for more info https://qiskit.org/documentation/nature/stubs/qiskit_nature.problems.second_quantization.ElectronicStructureProblem.html

woodsp-ibm commented 3 years ago

@anhph Did my suggestion solve your issue? If so please go ahead and close this.

anhph commented 3 years ago

Yes. Thanks a lot.