janus.decompose#

量子门分解模块。

分解函数#

decompose_one_qubit#

janus.decompose.decompose_one_qubit(unitary, basis='U', use_dag=False, atol=1e-12)[源代码]#

decompose_two_qubit_gate#

janus.decompose.decompose_two_qubit_gate(unitary, basis_gate='cx', use_dag=False, atol=1e-12)[源代码]#

将任意两量子比特酉矩阵分解为指定基门的电路。

参数:

unitary (np.ndarray or Gate): 要分解的两量子比特酉矩阵或Gate对象 basis_gate (str): 分解的基门,可以是 'cx', 'cz', 'swap', 'cr' (CRZ) 或 'rxx' use_dag (bool): 如果为True,返回DAGCircuit,否则返回Circuit atol (float): 容差

返回:

Circuit or DAGCircuit: 分解后的电路

decompose_multi_control_toffoli#

janus.decompose.decompose_multi_control_toffoli(num_ctrl_qubits, use_dag=False)[源代码]#

分解多控制Toffoli门为基本门

参数:
  • num_ctrl_qubits (int) -- 控制量子比特数量

  • use_dag (bool) -- 是否返回DAGCircuit

返回:

分解后的电路

返回类型:

Circuit

decompose_controlled_gate#

janus.decompose.decompose_controlled_gate(gate, num_ctrl_qubits=1, use_dag=False)[源代码]#

分解受控量子门

参数:
  • gate (Gate) -- 要分解的门

  • num_ctrl_qubits (int) -- 控制量子比特数量

  • use_dag (bool) -- 是否返回DAGCircuit

返回:

分解后的电路

返回类型:

Circuit

decompose_kak#

janus.decompose.decompose_kak(unitary_or_gate, euler_basis='ZXZ', use_dag=False, atol=1e-12)[源代码]#
参数:

convert_circuit_to_instruction_set#

janus.decompose.convert_circuit_to_instruction_set(circuit, instruction_set, use_dag=False)[源代码]#

将电路转换为指定的指令集

参数:
  • circuit (Circuit) -- Janus电路对象

  • instruction_set (List[str]) -- 目标指令集(门名称列表)

  • use_dag (bool) -- 是否返回DAGCircuit

返回:

转换后的电路

返回类型:

Circuit

分解器类#

OneQubitEulerDecomposer#

class janus.decompose.OneQubitEulerDecomposer(basis='U', use_dag=False)[源代码]#

基类:object

参数:
__init__(basis='U', use_dag=False)[源代码]#
参数:
build_circuit(gates)[源代码]#
返回类型:

Circuit

property basis#
angles(unitary)[源代码]#
参数:

unitary (ndarray)

返回类型:

tuple

angles_and_phase(unitary)[源代码]#
参数:

unitary (ndarray)

返回类型:

tuple

异常#

exception janus.decompose.DecomposeError[源代码]#

分解模块的基础异常类

exception janus.decompose.UnsupportedMethodError[源代码]#

当使用不支持的分解方法时抛出

exception janus.decompose.GateNotSupportedError[源代码]#

当尝试分解不支持的门类型时抛出

exception janus.decompose.ParameterError[源代码]#

当参数无效时抛出

exception janus.decompose.CircuitError[源代码]#

当电路操作出错时抛出

使用示例#

单比特门分解#

from janus.decompose import decompose_one_qubit
import numpy as np

# 分解任意单比特酉矩阵
U = np.array([[1, 0], [0, 1j]])
gates = decompose_one_qubit(U)

两比特门分解#

from janus.decompose import decompose_two_qubit_gate

gates = decompose_two_qubit_gate(U)

KAK 分解#

from janus.decompose import decompose_kak

result = decompose_kak(U)