提问人:Tico 提问时间:5/25/2023 更新时间:5/25/2023 访问量:69
qiskit_nature中的“单位”子模块去哪儿了?
Where has the "units" sub-module in qiskit_nature gone?
问:
我正在尝试遵循这个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”上时,他们重新组织了东西?如果是这样,为什么关于“自然”模块的教程没有反映这一点?
答:
模块 units.py
位于 Qiskit Nature 的根目录中。没有称为单元的包/文件夹/子模块。它是一个文件。
评论
pip install --upgrade qiskit_nature
也许可以解决它,将 qiskit_nature.units import DistanceUnit 中的 import 语句替换为 qiskit_nature.units._units
评论
main
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:
- The module is missing which only got added in Qiskit Nature v0.5.0
units
- The module is missing, too, which also got added in that version.
second_q
- 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
评论