linear-algebra - 在 Cirq 中分解量子电路

标签 linear-algebra quantum-computing

我正在研究 Cirq,需要对量子位执行某些酉运算。为此,我在 Cirq 中使用了 MatrixGate() 函数。与 Qiskit 不同,我找不到任何像分解或转译这样的函数来将幺正运算简化为基本的 U3 和 CNOT 门。

例如,如果我想执行以下幺正运算符,

Unitary Operator

为此,我在 Qiskit 中使用了这段代码。在 Cirq 中寻找等效的东西。

qc=QuantumCircuit(2)
qc.unitary(U,[0,1])
qc=transpile(qc,basis_gates=['cx','u3'])
qc.draw(output='mpl')

Unitary Gate

使用Qiskit中的Transpile功能后

Transpiled Unitary Gate

我什至尝试研究 Qiskit 用来分解这些酉运算的余弦-正弦分解算法。如论文中所述,Quantum Circuits for Isometries ,但它们不会轻易产生所需的分解。 请通过以下建议提供帮助:

  1. Cirq 中的一些代码来分解电路或
  2. 将 Qiksit 电路导出到 Cirq 或的解决方法
  3. 分解酉运算的更简单算法。

最佳答案

这种方法的一个例子是 cirq.two_qubit_matrix_to_operations。它使用 kak 分解(cartan 分解)来确定如何使用最少的 CZ 门将酉矩阵转换为一系列操作。

import cirq

desired_matrix = cirq.testing.random_unitary(dim=4)

synthesized_operations = cirq.two_qubit_matrix_to_operations(
    cirq.LineQubit(0),
    cirq.LineQubit(1),
    desired_matrix,
    allow_partial_czs=False,
)
circuit = cirq.Circuit(synthesized_operations)

synthesized_matrix = cirq.unitary(circuit)

cirq.testing.assert_allclose_up_to_global_phase(
    desired_matrix,
    synthesized_matrix,
    atol=1e-4
)

print(desired_matrix.round(3))
print(circuit)

打印(例如):

[[ 0.234-0.169j -0.81 +0.038j -0.327+0.138j -0.364-0.029j]
 [-0.503-0.407j  0.221-0.206j  0.063+0.144j -0.629-0.264j]
 [ 0.271+0.338j  0.337-0.128j -0.343+0.731j -0.165+0.052j]
 [ 0.504+0.236j  0.222+0.269j  0.244-0.371j -0.608-0.043j]]
0: ───PhX(-0.283)^0.631───@───PhX(0.673)^0.5────@───PhX(-0.375)^0.5───@───PhX(0.827)^0.147───Z^-0.269───
                          │                     │                     │
1: ───PhX(0.508)^0.338────@───PhX(0.65)^(5/6)───@───PhX(0.65)^0.995───@───PhX(0.302)^0.512───Z^-0.516───

关于linear-algebra - 在 Cirq 中分解量子电路,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61835652/

相关文章:

visual-studio-2015 - 在 Q# Quantum 开发工具包中出现错误 "Released qubits are not in zero state"

bit - 能不能用一个简单的代码例子来解释qubit和bit的区别?

visual-studio-code - Q# 控制台模板 DOTNET 不适用于 MAC

c++ - Eigen中逆矩阵的计算出错

java - 在 Java 中计算协方差矩阵

python - Python 中的非线性最小二乘法拟合(二维)

python - 使用python增加数组的维数