英文:
Where has the "units" sub-module in qiskit_nature gone?
问题
我正在尝试按照qiskit "Electronic Structure"教程进行操作,但在第一步设置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"时重新组织了内容而丢失了?如果是这样,为什么"nature"模块上的教程没有反映这一点呢?
【注意】:这是您要翻译的内容。
英文:
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?
答案1
得分: 0
units.py
模块位于Qiskit Nature的根目录中。没有名为units的包/文件夹/子模块,它是一个单独的文件。
英文:
The module units.py
is there in Qiskit Nature in the root. There is no package/folder/submodule called units. Its a single file.
答案2
得分: 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
英文:
pip install --upgrade qiskit_nature
maybe work around it, replace the import statement from qiskit_nature.units import DistanceUnit with qiskit_nature.units._units
答案3
得分: 0
我假设您正在尝试运行最新的教程,但您没有安装最新版本的Qiskit Nature。这基于以下三点观察:
- 缺少
units
模块,该模块仅在Qiskit Nature v0.5.0中添加。 - 也缺少
second_q
模块,该模块也在该版本中添加。 - 此外,您说您正在使用Python 3.6,但在版本0.4.0中已删除对该版本的支持。
因此,我强烈推测您安装了Qiskit Nature v0.3.2,这是pip在该Python版本下应该解析到的最后一个发布版本。
现在,您如何解决这个问题:我强烈建议您首先切换到更新的Python版本。3.6版本已于2021年12月23日到达了其生命周期的终点1。
我建议您升级到Python 3.9,它将在2025年之前得到支持,并且已在所有平台上进行了“战斗测试”。
一旦您升级了Python版本,您将需要重新安装Qiskit Nature:
pip3 install --upgrade qiskit-nature
英文:
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
units
module is missing which only got added in Qiskit Nature v0.5.0 - The
second_q
module is missing, too, which also got added in that version. - 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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论