janus.compiler#
量子电路编译器模块。
编译函数#
优化 Pass#
BasePass#
RemoveIdentityPass#
MergeRotationsPass#
- class janus.compiler.MergeRotationsPass[源代码]#
基类:
BasePass合并连续的旋转门
例如: RZ(a) - RZ(b) -> RZ(a+b)
- ROTATION_GATES = {'cp', 'crx', 'cry', 'crz', 'cu1', 'mcp', 'mcphase', 'mcrx', 'mcry', 'mcrz', 'mcu1', 'p', 'rx', 'rxx', 'ry', 'ryy', 'rz', 'rzx', 'rzz', 'u1'}#
- run(dag)[源代码]#
执行优化
- 参数:
dag (DAGCircuit) -- 输入 DAG
- 返回:
优化后的 DAG
- 返回类型:
CancelInversesPass#
- class janus.compiler.CancelInversesPass[源代码]#
基类:
BasePass消除相邻的逆门对
例如: X-X, H-H, CX-CX (相同控制和目标) 等
- SELF_INVERSE = {'c3x', 'c4x', 'ccx', 'ccz', 'ch', 'cswap', 'cx', 'cy', 'cz', 'dcx', 'ecr', 'h', 'iswap', 'mcx', 'mcx_gray', 'mcx_recursive', 'mcx_vchain', 'rc3x', 'rccx', 'swap', 'x', 'y', 'z'}#
- run(dag)[源代码]#
执行优化
- 参数:
dag (DAGCircuit) -- 输入 DAG
- 返回:
优化后的 DAG
- 返回类型:
使用示例#
基本编译#
from janus.compiler import compile_circuit
optimized = compile_circuit(qc, optimization_level=2)
自定义 Pass#
from janus.compiler.passes import (
RemoveIdentityPass,
CancelInversesPass,
MergeRotationsPass
)
optimized = compile_circuit(qc, passes=[
RemoveIdentityPass(),
CancelInversesPass(),
MergeRotationsPass(),
])