qiskit_nature中的“单位”子模块去哪儿了?

Where has the "units" sub-module in qiskit_nature gone?

提问人:Tico 提问时间:5/25/2023 更新时间:5/25/2023 访问量:69

问:

我正在尝试遵循这个qiskit“电子结构”教程,但是在第一步中,使用以下命令设置PySCF驱动程序

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,
)

产生错误。该错误表示 qiskit_nature 中没有模块“units”。

我已经用 pip(pip3、python 3.6)安装了qiskit_nature,当我列出 qiskit_nature 的子模块时,我得到了

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

我检查了大部分,似乎任何地方都没有“单元”模块。虽然上述对子模块“units”的调用可能是微不足道的和/或被规避的,但子模块去哪儿了?是不是因为当他们把“qiskit.chemistry”移植到“nature”上时,他们重新组织了东西?如果是这样,为什么关于“自然”模块的教程没有反映这一点?

计量单位 QISKIT

评论


答:

0赞 Steve Wood 5/25/2023 #1

模块 units.py 位于 Qiskit Nature 的根目录中。没有称为单元的包/文件夹/子模块。它是一个文件。

评论

0赞 Tico 5/25/2023
哦,谢谢。你知道为什么“from qiskit_nature.units import DistanceUnit”会失败吗?我之所以问,是因为如果类似的调用/导入以类似的方式失败,这将很快成为一个问题。(另外,从技术上讲,鉴于每个 python 文件都是它自己的模块,我想知道标题是否是错误的)
0赞 Tico 5/25/2023
我刚刚检查了鹦鹉螺qiskit_nature.__path__,那里没有“units.py”。只有 constants.py、deprecation.py、exceptions.py、__init.py、settings.py 和 version.py。这与你刚刚链接到的 github 存储库不同。
0赞 Jacob Vespers 5/25/2023 #2

pip install --upgrade qiskit_nature

也许可以解决它,将 qiskit_nature.units import DistanceUnit 中的 import 语句替换为 qiskit_nature.units._units

评论

0赞 Tico 5/25/2023
谢谢。那是我做的第一件事。它没有做太多事情。然后我在安装目录中复制了 units.py 文件,这解决了导入的问题,但是几行后,找不到来自模块“second_q”的导入。这似乎是第二个量化模块,但究竟是哪个模块仍然是个问题。在属性下有第二个量化,在转换器下有另一个量化,在问题下有另一个量化。似乎使用 pip 安装的qiskit_nature与 @SteveWood 链接到的 qiskit_nature git 存储库几乎没有相似之处。我只是决定抓住那个回购。
0赞 mrossinek 5/25/2023
@Tico:史蒂夫链接到的回购是正确的。但是在 0.3.2 版本(正如我在回答中解释的那样,您在 Python 3.6 下安装的那个)和最新的开发分支(称为该存储库的登录页面)之间,发生了很多变化。您可以在此处找到更改摘要: qiskit.org/ecosystem/nature/release_notes.html 如果你确实无法升级 Python,但仍然想使用 Qiskit Nature,你需要参考你实际使用的版本的文档。main
0赞 mrossinek 5/25/2023
(我用完了角色......目前,该网站不包含旧版本的文档。但是您可以通过 Github 访问它。这是 stable/0.3 分支: github.com/Qiskit/qiskit-nature/tree/stable/0.3 您可以克隆它,然后从那里在终端中构建文档,如下所述: github.com/Qiskit/qiskit-nature/blob/stable/0.3/...
0赞 Tico 5/25/2023
@mrossinek - 谢谢。我接受了你的答案作为答案,因为它引起了我的注意,我需要注意的一切 - 一个简短的“修复”:暂时在另一台机器上使用更新的 python 版本......等。长期修复,在同一台机器上拥有单独的 python 环境,满足各种项目的需求。
0赞 mrossinek 5/25/2023 #3

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 module is missing which only got added in Qiskit Nature v0.5.0units
  2. The module is missing, too, which also got added in that version.second_q
  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

评论

0赞 Tico 5/25/2023
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.