gpt4 book ai didi

"The 'qiskit-aer' library is required to use 'Aer provider'(“需要‘qiskit-Aer’库才能使用‘Aer Provider’)

转载 作者:bug小助手 更新时间:2023-10-25 18:23:06 29 4
gpt4 key购买 nike



code
from qiskit import QuantumCircuit,ClassicalRegister,QuantumRegister
qr=QuantumRegister(3)
cr=ClassicalRegister(3)
qc=QuantumCircuit(qr,cr)
qc.x(qr[0])
qc.y(qr[1])
qc.z(qr[2])
qc.measure(qr,range(3))
print(qc.draw())
import qiskit
backend=qiskit.Aer.get_backend('qasm_simulator')
job=qiskit.execute(qc,backend,shorts=1024)
results=job.result()
counts=results.get_counts(qc)
print(counts)

来自qiskit导入量子电路、经典寄存器、量子寄存器的代码qr=量子寄存器(3)cr=经典寄存器(3)qc=量子电路(qr,cr)qc.x(qr[0])qc.y(qr[1])qc.z(qr[2])qc.measure(qr,Range(3))Print(qc.Draw())导入qiskit backend=qiskit.Aer.get_backend(‘qasm_simulator’)=qiskit.Execute(qc,Backend,Short=1024)Resits=job.Result()=Results.get_Counts(QC)Print(Counts)


Error
'File "C:\Users\HPC\Desktop\python_til\QISKIT\q4.py", line 11, in <module> backend=qiskit.Aer.get_backend('qasm_simulator') ^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\HPC\AppData\Local\Programs\Python\Python311\Lib\site-packages\qiskit\__init__.py", line 134, in __getattr__ raise MissingOptionalLibraryError( qiskit.exceptions.MissingOptionalLibraryError: "The 'qiskit-aer' library is required to use 'Aer provider'. You can install it with 'pip install qiskit-aer'."'

错误‘文件“C:\Users\HPC\Desktop\python_til\QISKIT\q4.py”,第11行,在文件backend=qiskit.Aer.get_backend(’qasm_simulator‘)^文件“C:\Users\HPC\AppData\Local\Programs\Python\Python311\Lib\site-packages\qiskit\__init__.py”,行134,在__getattr__raise MissingOptionalLibraryError(qiskit.exceptions.MissingOptionalLibraryError:“需要’qiskit-Aer‘库才能使用’Aer Provider‘。您可以使用’pip Install Qiskit-Aer‘安装它。”“


I expected result but it getting error

我希望得到结果,但结果却错了


更多回答
优秀答案推荐

Qiskit Aer was moved from Qiskit into it's own package as per the message.

根据这条消息,Qiskit Aer被从Qiskit转移到它自己的包装中。


From Qiskit 0.44 release notes

摘自Qiskit 0.44发行说明



The Qiskit Aer project is still active and maintained moving forward it is just no longer included as part of the qiskit package. To continue using qiskit-aer you will need to explicitly install qiskit-aer and import the package from qiskit_aer.



Maybe you did the pip install qiskit-aer but you need to change how Aer is imported so you do it from qiskit_aer not qiskit as follows:

也许您确实通过pip安装了qiskit-Aer,但您需要更改Aer的导入方式,因此您可以从qiskit_Aer而不是qiskit执行以下操作:


import qiskit_aer
backend=qiskit_aer.Aer.get_backend('qasm_simulator')

If you change those lines the code will run, ie this below, which is a lightly version of what you posted above, runs

如果您更改这些行,代码将运行,即下面这是您上面发布的内容的一个简单版本,运行


from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister, execute
qr=QuantumRegister(3)
cr=ClassicalRegister(3)
qc=QuantumCircuit(qr,cr)
qc.x(qr[0])
qc.y(qr[1])
qc.z(qr[2])
qc.measure(qr,range(3))
print(qc.draw())

from qiskit_aer import Aer
backend=Aer.get_backend('qasm_simulator')
job=execute(qc,backend,shorts=1024)
results=job.result()
counts=results.get_counts(qc)
print(counts)

and produces

并生产出


      ┌───┐┌─┐      
q0_0: ┤ X ├┤M├──────
├───┤└╥┘┌─┐
q0_1: ┤ Y ├─╫─┤M├───
├───┤ ║ └╥┘┌─┐
q0_2: ┤ Z ├─╫──╫─┤M├
└───┘ ║ ║ └╥┘
c0: 3/══════╩══╩══╩═
0 1 2
{'011': 1024}

更多回答

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com