0

I am trying to follow this qiskit "Electronic Structure" tutorial, but at the very first step, setting up the PySCF driver with the following

from qiskit_nature.units import DistanceUnit
from qiskit_nature.second_q.drivers import PySCFDriver

driver = PySCFDriver(
    atom="H 0 0 0; H 0 0 0.735",
    basis="sto3g",
    charge=0,
    spin=0,
    unit=DistanceUnit.ANGSTROM,
)

produces an error. The error says there is no module "units" in qiskit_nature.

I have installed qiskit_nature with pip (pip3, python 3.6) and when I listed the submodules of qiskit_nature I get

algorithms
circuit
constants
converters
deprecation
drivers
exceptions
mappers
operators
problems
properties
results
runtime
settings
transformers
version

I checked most and there appears not to be a "units" module anywhere. While the call to the submodule "units" in the above may be trivial and/or circumvented, where has the submodule gone? Is it missing because when they ported the "qiskit.chemistry" to "nature" they re-organised things? If so, why do the tutorials on the "nature" module not reflect this?

Tico
  • 11
  • 3

3 Answers3

0

The module units.py is there in Qiskit Nature in the root. There is no package/folder/submodule called units. Its a single file.

Steve Wood
  • 266
  • 1
  • 3
  • Oh Thanks. Do you know why does "from qiskit_nature.units import DistanceUnit" fail? I am asking because if similar calls/imports fail in similar ways, this will fast become an issue.(Also, technically, given every python file is its own module, I wonder if the title is *that* wrong) – Tico May 24 '23 at 23:02
  • I just checked with nautilus qiskit_nature.__path__ and there is no "units.py" in there. There is only constants.py, deprecation.py, exceptions.py, __init.py, settings.py and version.py. That's different from the github repo you just linked to. – Tico May 24 '23 at 23:11
0

pip install --upgrade qiskit_nature

maybe work around it, replace the import statement from qiskit_nature.units import DistanceUnit with qiskit_nature.units._units

  • Thanks. That was the first thing I did. It didn't do much. Then I copied the units.py file in the install directory, which solved the issue for *that* import, but then a few lines later there is an import from a module "second_q" that isn't found. This appears to be a second quantization module, but which one remains the question. There is a second quantization under properties, another under transformers, another under problems. It appears the qiskit_nature installed with pip bears little resemblance to the qiskit_nature git repo linked to by @SteveWood. I just settled on grabbing that repo. – Tico May 25 '23 at 09:51
  • @Tico: the repo which Steve linked to is the correct one. But between version 0.3.2 (the one you get installed under Python 3.6 as I explained in my answer) and the latest development branch (which is called `main` and is the landing page of that repo) a LOT has changed. You can find a summary of the changes here: https://qiskit.org/ecosystem/nature/release_notes.html If you _really_ cannot upgrade Python and still would like to use Qiskit Nature, you need to refer to the documentation of the version which you are actually using. – mrossinek May 25 '23 at 12:42
  • (I ran out of characters...) Currently, the website does not contain the documentation of older versions. But you can access it via Github. This is the stable/0.3 branch: https://github.com/Qiskit/qiskit-nature/tree/stable/0.3 You can clone that and then build the docs from there in your terminal as described here: https://github.com/Qiskit/qiskit-nature/blob/stable/0.3/CONTRIBUTING.md#contributing-to-qiskit-nature – mrossinek May 25 '23 at 12:43
  • @mrossinek - thank you. I accepted your answer as *the* answer because it brought to my attention all I needed to be aware of - a short "fix": works on another machine for the time being with newer python version ... etc. Longer term fix, have separate python environments on the same machine, catering for the various projects. – Tico May 25 '23 at 15:26
0

I am assuming that you are trying to run the latest tutorial but you do not have the latest version of Qiskit Nature installed. This is based on three observatons:

  1. The units module is missing which only got added in Qiskit Nature v0.5.0
  2. The second_q module is missing, too, which also got added in that version.
  3. Furthermore, you say that you are using Python 3.6, support which has been removed in version 0.4.0.

Thus, I strongly assume you installed Qiskit Nature v0.3.2 which is the last release that pip should resolve to under that Python version.

Now, how do you go about solving this problem: I strongly suggest that you first switch to a newer Python version. 3.6 has reached its end of life on Dec 23rd, 2021 1. I suggest you upgrade to Python 3.9 which will be supported into 2025 and has already been "battle-tested" on all platforms.

Once you have upgrade your Python version, you will need to re-install Qiskit Nature:

pip3 install --upgrade qiskit-nature
mrossinek
  • 116
  • I'll accept this as the answer, although I cannot upgrade to newer python versions (some large legacy code *only ever* works with *that* python version). About time I learnt about python environments, I guess. – Tico May 25 '23 at 09:58