可见result包含了全部的运行结果信息,包括运行后端类型、运行任务编号等等。如果我们只关心经过量子电路处理过的大量零态测量结果如何,我们可以直接调用result的get_counts方法。 print(result.get_counts()) 运行结果如下: 通过计算不同测量结果所占的比例,原则上我们就可以推出经历量子电路后的量子态大概是什么样子的。...
我们得到的量子电路 为了和之前得到的statevector结果不一样,我们可以使用.get_counts()来获得测量出0和1的数量: qobj = assemble(qc) result = sim.run(qobj).result() counts = result.get_counts() plot_histogram(counts) 从得到的结果中我们看出,我们100%会测量出\mathinner{|1\rangle}。 我们得到的...
qobj=assemble(qc)state=sim.run(qobj).result().get_statevector()# Execute the circuitprint(state)# Print the result Statevector([0.70710678+0.j, 0.+0.70710678j],dims=(2,)) qobj=assemble(qc)results=sim.run(qobj).result().get_counts()plot_histogram(results) 我们可以看到我们有相等的概率...
1.如果我们在状态中初始化我们的量子比特$|+⟩$,在状态下测量它的概率是多少$|-⟩$? 2.使用Qiskit测量一个$|0⟩$量子比特显示在状态$|+⟩$和$|-⟩$的概率(提示:您可能想使用。get_counts()和plot_histogram())。 3.试着创建一个以Y为基的函数。 在不同的基准上进行测量,可以让我们看到海森堡...
from qiskit import Aer, execute # 选择Aer后端进行模拟 simulator = Aer.get_backend('qasm_simulator') # 运行量子电路并获取结果 job = execute(circuit, simulator) result = job.result() # 打印结果 print(result.get_counts(circuit)) 通过以上步骤,你可以成功启动Qiskit,并创建、运行自己的量子电路。Qisk...
However, the behavior of job.get_counts() still depends on the backend-level settings for the backend that created the job: if the backend was an ideal simulator, .get_counts() will always sample from the result’s stored probability distribution and can generate slightly different counts every...
result.get_counts(circuit)获取电路的测量次数结果。 print打印出测量结果,例如{'00': 512, '11': 512}。 plot_histogram(counts)使用 Qiskit 的可视化功能绘制直方图,以便我们可以直观地看到测量结果的分布。 3. 结论 到这里,我们已经成功实现了一个基本的量子电路,并提取并可视化了结果。你只需简单的几步,就能...
counts = result.get_counts(circuit) print(counts) 可视化结果 Qiskit提供了用于可视化结果的工具,以下是如何绘制结果直方图的方法: plot_histogram(counts) 六、真实量子计算机上运行 IBM Q Experience 您可以在真实的量子计算机上执行您的程序,首先需要注册IBM Q Experience,并获取相关的API token: ...
get_counts()) print(f'backend: {result.backend_name}') This script works with Qiskit Aer. When the script is executed in the current version of cuQuantum Appliance, the multi-node backend is automatically selected and runs the simulation. The backend name is "cusvaer_simulator_statevector"...
result = job.result()# 获取测量结果的计数counts = result.get_counts(qc)print(counts)# 可视化结果plot_histogram(counts) AI代码助手复制代码 6. 总结 本文介绍了如何在 Python 中使用 Qiskit 包进行量子计算机编程。我们首先介绍了 Qiskit 的安装和基本概念,然后详细讲解了如何构建和运行量子电路,最后展示了两...