当前位置: 首页 > news >正文

贝尔不等式的验证

在量子计算机上运行一个实验,以演示使用Estimator原型违反CHSH不等式。

import numpy as npfrom qiskit import QuantumCircuit
from qiskit.circuit import Parameter
from qiskit.quantum_info import SparsePauliOpfrom qiskit_ibm_runtime import QiskitRuntimeService
from qiskit_ibm_runtime import EstimatorV2 as Estimatorimport matplotlib.pyplot as plt
import matplotlib.ticker as tck#要在硬件上运行,请选择队列中作业数量最少的后端
service = QiskitRuntimeService(channel="ibm_quantum")
backend = service.least_busy(operational=True, simulator=False, min_num_qubits=127)
backend.name

创建一个参数化的CHSH电路

        首先,我们用参数θ来编写电路,我们称之为θ。Estimator原型机通过直接提供可观测值的期望值,极大地简化了电路的构建和输出分析。许多令人感兴趣的问题,特别是对于噪声系统的近期应用,都可以用期望值来表示。估计器(V2)原语可以根据提供的可观察对象自动更改度量基础。

theta = Parameter("$\\theta$")chsh_circuit = QuantumCircuit(2)
chsh_circuit.h(0)
chsh_circuit.cx(0, 1)
chsh_circuit.ry(theta, 0)
chsh_circuit.draw(output="mpl", idle_wires=False, style="iqp")

 

        创建参数化CHSH电路后,下一步将创建要分配给电路的相位值列表。您可以使用以下代码创建21个相位值的列表,范围从0到2π,间距相等,即0 0,0.1π,0.2π,…,1.9π, 2π。

number_of_phases = 21
phases = np.linspace(0, 2 * np.pi, number_of_phases)
# Phases need to be expressed as list of lists in order to work
individual_phases = [[ph] for ph in phases]

        现在我们需要计算期望值的可观察对象。在我们的例子中,我们正在查看每个量子位的正交基,让第一个量子位的参数化- Y -旋转相对于第二个量子位基几乎连续地扫描测量基。因此,我们将选择可观测值ZZ、ZX、XZ和XX。

# <CHSH1> = <AB> - <Ab> + <aB> + <ab> -> <ZZ> - <ZX> + <XZ> + <XX>
observable1 = SparsePauliOp.from_list([("ZZ", 1), ("ZX", -1), ("XZ", 1), ("XX", 1)])# <CHSH2> = <AB> + <Ab> - <aB> + <ab> -> <ZZ> + <ZX> - <XZ> + <XX>
observable2 = SparsePauliOp.from_list([("ZZ", 1), ("ZX", 1), ("XZ", -1), ("XX", 1)])from qiskit.transpiler.preset_passmanagers import generate_preset_pass_managertarget = backend.target
pm = generate_preset_pass_manager(target=target, optimization_level=3)chsh_isa_circuit = pm.run(chsh_circuit)
chsh_isa_circuit.draw(output="mpl", idle_wires=False, style="iqp")isa_observable1 = observable1.apply_layout(layout=chsh_isa_circuit.layout)
isa_observable2 = observable2.apply_layout(layout=chsh_isa_circuit.layout)

        为了在对Estimator的一次调用中执行整个实验。我们可以创建一个Qiskit Runtime Estimator原型机来计算我们的期望值。EstimatorV2.run()方法接受一个原始统一块(pub)的可迭代对象。每个PUB都是一个可迭代对象,格式为(circuit, observables, parameter_values: Optional, precision: Optional)

# To run on a local simulator:
# Use the StatevectorEstimator from qiskit.primitives instead.estimator = Estimator(mode=backend)pub = (chsh_isa_circuit,  # ISA circuit[[isa_observable1], [isa_observable2]],  # ISA Observablesindividual_phases,  # Parameter values
)job_result = estimator.run(pubs=[pub]).result()chsh1_est = job_result[0].data.evs[0]
chsh2_est = job_result[0].data.evs[1]
fig, ax = plt.subplots(figsize=(10, 6))# results from hardware
ax.plot(phases / np.pi, chsh1_est, "o-", label="CHSH1", zorder=3)
ax.plot(phases / np.pi, chsh2_est, "o-", label="CHSH2", zorder=3)# classical bound +-2
ax.axhline(y=2, color="0.9", linestyle="--")
ax.axhline(y=-2, color="0.9", linestyle="--")# quantum bound, +-2√2
ax.axhline(y=np.sqrt(2) * 2, color="0.9", linestyle="-.")
ax.axhline(y=-np.sqrt(2) * 2, color="0.9", linestyle="-.")
ax.fill_between(phases / np.pi, 2, 2 * np.sqrt(2), color="0.6", alpha=0.7)
ax.fill_between(phases / np.pi, -2, -2 * np.sqrt(2), color="0.6", alpha=0.7)# set x tick labels to the unit of pi
ax.xaxis.set_major_formatter(tck.FormatStrFormatter("%g $\\pi$"))
ax.xaxis.set_major_locator(tck.MultipleLocator(base=0.5))# set labels, and legend
plt.xlabel("Theta")
plt.ylabel("CHSH witness")
plt.legend()
plt.show()

参考:CHSH Inequality | IBM Quantum Learning

http://www.lryc.cn/news/477020.html

相关文章:

  • GR2——在大规模视频数据集上预训练且机器人数据上微调,随后预测动作轨迹和视频(含GR1详解)
  • 伦敦金价格是交易所公布的吗?
  • Oracle SQL Loader概念及用法
  • ReactPress 是什么?
  • MR30分布式IO模块与高效PLC协同
  • 成都睿明智科技有限公司共赴抖音电商蓝海
  • Android15音频进阶之音频策略加载及使用(九十一)
  • Spring设值注入
  • Spring整合Mybatis过程
  • 常见HR问题篇
  • 调用数据集mnist(下载+调用全攻略)
  • 【基础语法】Java Scanner hasNext() 和 hasNextLine() 的区别
  • react使用Fullcalendar 实战用法
  • 优秀项目经理必知的10款项目管理软件推荐
  • 植物神经紊乱不用怕,这些维生素来帮你!
  • NRF52832学习笔记(41)——添加串口库libuarte
  • Moore Perf System 1.1版本
  • SpringBoot+Shirp的权限管理
  • OpenCV图像基础
  • 基于MATLAB的图像拼接技术
  • ComfyUI 快速入门(环境搭建)
  • 将HTML项目上传至Gitee仓库(详细教程)
  • 如何应对Oracle SQL语句的数据去重问题,应该考虑哪几个方面?
  • 论负载均衡技术在Web系统中的应用论文
  • NumPy 数据类型
  • JavaScript——(4)
  • 每日一练 | DHCP Relay(DHCP 中继)
  • `psdparse`:解锁Photoshop PSD文件的Python密钥
  • 考研要求掌握的C语言程度(插入排序)
  • mybatis源码解析-sql执行流程