mindquantum.algorithm.compiler.cu_decompose
- mindquantum.algorithm.compiler.cu_decompose(gate: QuantumGate, with_barrier: bool = False)[源代码]
对任意维度的受控幺正门进行分解。
该门拥有 \(m\) 个控制比特和 \(n\) 个作用比特。 当迭代的调用函数本身时,\(m\) 将会逐步减小并保持 \(n\) 恒定。
- 参数:
gate (
QuantumGate
) - 量子门实例。with_barrier (bool) - 是否在分解时加入
BarrierGate
。默认值:False
。
- 返回:
Circuit
,由单比特门和CNOT门构成的量子线路。
样例:
>>> import mindquantum as mq >>> from mindquantum.algorithm.compiler import cu_decompose >>> from scipy.stats import unitary_group >>> cqs = [0, 2, 4, 5] >>> tqs = [1, 6] >>> m = len(cqs) >>> n = len(tqs) >>> u = unitary_group.rvs(2 ** n, random_state=123) >>> g = mq.UnivMathGate('U', u).on(tqs, cqs) >>> circ = cu_decompose(g) >>> num_cnot = len([g for g in circ if isinstance(g, mq.XGate) and len(g.ctrl_qubits)==1]) >>> print('total gate number: {}, CNOT number: {}'.format(len(circ), num_cnot)) total gate number: 632, CNOT number: 314