操作类层次结构¶
Quantum-Resource-Estimator 的核心是 Operation 类层次。
类层次关系¶
Operation- 基类,所有操作的祖先Primitive- 原语操作,叶节点,直接映射 PySparQ 操作Composite- 组合操作,由子操作构成StandardComposite- 默认 T-count 求和的组合操作AbstractComposite- 自定义 T-count 聚合的组合操作
Primitive vs Composite¶
Primitive (原语)
特征 |
说明 |
|---|---|
继承 |
|
节点类型 |
叶节点 |
必须实现 |
|
子操作 |
无 |
Composite (组合)
特征 |
说明 |
|---|---|
继承 |
|
节点类型 |
内部节点 |
必须实现 |
|
子操作 |
有,存储在 |
使用方式¶
from pyqres import Hadamard, CNOT, TCounter
# Primitive:直接计算 T-count
h = Hadamard(['q'])
print(h.t_count()) # 0
# Composite:遍历子操作求和
swap = Swap_General_General(['q1', 'q2'])
counter = TCounter()
swap.traverse(counter)
print(counter.get_result())