mindquantum.algorithm.compiler.qs_decompose
- mindquantum.algorithm.compiler.qs_decompose(gate: QuantumGate, with_barrier: bool = False)[源代码]
任意维幺正量子门的矩阵的香农分解。
该分解方法中的CNOT门数量为:
\[O(4^n)\]了解更多详细信息,请参考 Synthesis of Quantum Logic Circuits。
- 参数:
gate (
QuantumGate
) - 量子门实例。with_barrier (bool) - 是否在分解时加入
BarrierGate
。默认值:False
。
- 返回:
Circuit
,由单比特门和CNOT门构成的量子线路。
样例:
>>> import mindquantum as mq >>> from mindquantum.algorithm.compiler.decompose import qs_decompose >>> from scipy.stats import unitary_group >>> tqs = [1,2,3,6] # arbitrary qubit index order is OK >>> n = len(tqs) # qubit number >>> u = unitary_group.rvs(2 ** n, random_state=123) >>> g = mq.UnivMathGate('U', u).on(tqs) >>> circ = qs_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: 412, CNOT number: 180