这种方法的一个例子是 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───