wy_qcos.transpiler.cmss.optimizer package

Submodules

wy_qcos.transpiler.cmss.optimizer.adjacent_optimization module

class wy_qcos.transpiler.cmss.optimizer.adjacent_optimization.AdjacentPhaseOptPass

基类:object

Merge adjacent phase gates.

run(dag, basis_gates=None)

Optimize the dag by merging adjacent phase gates.

参数:
  • dag (DAGCircuit) -- dag to be optimized.

  • basis_gates (set, optional) -- basis gates after decompose.

返回:

the number of reduced gates.

返回类型:

int

wy_qcos.transpiler.cmss.optimizer.clifford_rz_optimization module

class wy_qcos.transpiler.cmss.optimizer.clifford_rz_optimization.CliffordRzOptimization(verbose=False)

基类:object

property hadamard_templates: list[OptimizingTemplate]

Generate Hadamard gate optimization templates.

返回:

a list of h gate optimization templates.

返回类型:

list[OptimizingTemplate]

property single_qubit_gate_templates
property cnot_ctrl_template
property cnot_targ_template
reduce_hadamard_gates(dag, basis_gates=None)

Hadamard gate reduction algorithm.

参数:
  • dag (DAGCircuit) -- the DAG to be optimized.

  • basis_gates (set, optional) -- basis gates after decompose.

返回:

the count of reduced H gates.

返回类型:

int

get_next_node_on_specific_qubit(dag, cur_node, qubit)

Get the next node on a specific qubit.

We need the direct successor of a node along a specific qubit. However, DAGCircuit.successors returns all topological successors regardless of qubits. Therefore, we determine whether two nodes are directly adjacent on a given qubit by analyzing the predecessors of the candidate successor node.

参数:
  • dag (DAGCircuit) -- the dag containing the cur_node.

  • cur_node (DAGOpNode) -- the current node.

  • qubit (int) -- get the next node on this qubit.

返回:

the next node.

返回类型:

DAGOpNode

cancel_single_qubit_gates(dag, basis_gates=None)

Merge Rz gates using commutation rules.

参数:
  • dag (DAGCircuit) -- the DAG to be optimized.

  • basis_gates (set, optional) -- basis gates after decompose.

返回:

the count of reduced Rz gates.

返回类型:

int

cancel_two_qubit_gates(dag, basis_gates=None)

Merge cx gates using commutation rules.

参数:
  • dag (DAGCircuit) -- the DAG to be optimized.

  • basis_gates (set, optional) -- basis gates after decompose.

返回:

the count of reduced Rz gates.

返回类型:

int

merge_rotations(dag, basis_gates=None)

Optimize Rz gates using phase polynomials.

参数:
  • dag (DAGCircuit) -- dag to be optimized.

  • basis_gates (set, optional) -- basis gates after decompose.

返回:

the count of reduced Rz gates.

返回类型:

int

parse_cnot_rz_circuit(node_list, dag)

Optimize Rz gates using phase polynomials.

This function identifies phase polynomials in linear function representation and merges Rz gates on the same linear functions.

参数:
  • node_list (list[DAGOpNode]) -- subcircuit of Rz, CX, X gates.

  • dag (DAGCircuit) -- dag to be optimized, including the subcircuit.

返回:

the count of reduced Rz gates.

返回类型:

int

run(dag, basis_gates=None)

Optimize circuit with commutation rules.

参数:
  • dag (DAGCircuit) -- dag to be optimized.

  • basis_gates (set, optional) -- basis gates after decompose.

返回:

optimized dag.

返回类型:

DAGCircuit

wy_qcos.transpiler.cmss.optimizer.gate_optimizer module

wy_qcos.transpiler.cmss.optimizer.gate_optimizer.pass_hermitian(ir)

如果末尾的两个门相同,且都为hermitian,则消去.

参数:

ir (list) -- 中间表示

返回:

passed

wy_qcos.transpiler.cmss.optimizer.gate_optimizer.pass_merge_theta(ir)

如果末尾的两个门是作用在同一比特上的同一类旋转门,则角度可以合并.

参数:

ir (list) -- 中间表示

返回:

passed

wy_qcos.transpiler.cmss.optimizer.gate_optimizer.pass_u_udg(ir)

如果末尾的两个门是作用在同一比特上的s和sdg或者t和tdg,则可以消去.

参数:

ir (list) -- 中间表示

返回:

passes

wy_qcos.transpiler.cmss.optimizer.gate_optimizer.pass_three_gate_model(ir)

HZH -> X, HXH -> Z, XRy(θ)X -> Ry(-θ).

参数:

ir (list) -- 中间表示

返回:

passes

wy_qcos.transpiler.cmss.optimizer.gate_optimizer.do_pass(ir)

一次执行pass,直到ir不发生变化.

参数:

ir (list) -- 中间表示

wy_qcos.transpiler.cmss.optimizer.gate_optimizer.optimize_gate(ir, opt_level=Constant.DEFAULT_OPTIMIZATION_LEVEL)

基础门优化.

优化策略主要包含如下几个:
  1. 连续的两个作用在相同比特上的厄米共轭门可以消除

  2. 连续两个相同的选择门,可以合并旋转角

  3. 旋转角->0的门等同于I,可以忽略

  4. HZH -> X, HXH -> Z

  5. XRy(θ)X -> -Ry(θ)

参数:
  • ir (list) -- ir

  • opt_level (int) -- optimization level

返回:

optimized gates

wy_qcos.transpiler.cmss.optimizer.gate_optimizer.do_optimize_pass(dag, pass_list, basis_gates=None)

Iteratively apply optimization passes.

Iteratively apply a sequence of optimization passes to a DAGCircuit until no further reduction in circuit size is observed.

参数:
  • dag (DAGCircuit) -- The DAGCircuit to be optimized.

  • pass_list (list) -- A list of optimization passes.

  • basis_gates (set, optional) -- basis gates after decompose.

wy_qcos.transpiler.cmss.optimizer.gate_optimizer.optimize(ir, opt_level=Constant.DEFAULT_OPTIMIZATION_LEVEL, verbose=False, basis_gates=None)

Optimize the input ir.

参数:
  • ir (list) -- the ir to be optimized.

  • opt_level (int, optional) -- optimization level. Defaults to 1.

  • verbose (bool, optional) -- whether print optimization information. Defaults to False.

  • basis_gates (set, optional) -- basis gates after decompose.

返回:

optimized ir.

返回类型:

list

wy_qcos.transpiler.cmss.optimizer.inverse_cancellation module

class wy_qcos.transpiler.cmss.optimizer.inverse_cancellation.InverseCancellation(gates_to_cancel)

基类:object

Cancel inverse gates.

Cancel specific Gates which are inverses of each other when they occur back-to-back.

参数:

gates_to_cancel (list[GateOperation | tuple[GateOperation, GateOperation]])

run(dag, basis_gates=None)

Run the InverseCancellation pass on dag.

参数:
  • dag (DAGCircuit) -- the directed acyclic graph to run on.

  • basis_gates (set, optional) -- basis gates after decompose.

返回:

the count of reduced gates.

返回类型:

int

wy_qcos.transpiler.cmss.optimizer.subcircuit_rewrite module

class wy_qcos.transpiler.cmss.optimizer.subcircuit_rewrite.EquivalencePass

基类:object

Process equivalence templates.

param_transform(template, mapping, new_nodes)

Process special equivalence templates, like x-ry-x.

参数:
  • template (OptimizingTemplate) -- equivalence template.

  • mapping (dict) -- mapping nodes return by template.compare().

  • new_nodes (dict) -- replaced nodes return by dag.substitute_node_with_dag.

property get_equivalence_circuits
replace_equivalence_circuits(dag, equivalence_circuits)

Replace all equivalence circuits in dag.

参数:
  • dag (DAGCircuit) -- dag to be optimized.

  • equivalence_circuits (list) -- equivalence circuits templates.

返回:

the number of reduced gates.

返回类型:

int

run(dag, basis_gates=None)

Optimize the dag with equivalence templates.

参数:
  • dag (DAGCircuit) -- dag to be optimized.

  • basis_gates (set, optional) -- basis gates after decompose.

返回:

the number of reduced gates.

返回类型:

int

wy_qcos.transpiler.cmss.optimizer.template module

class wy_qcos.transpiler.cmss.optimizer.template.OptimizingTemplate(template, replacement=None, anchor=0, weight=1, param_transform=None)

基类:object

参数:
  • template (DAGCircuit)

  • replacement (DAGCircuit | None)

  • anchor (int)

  • weight (int)

  • param_transform (Callable | None)

compare(dag, start_node, anchor)

Compare template dag with circuit dag from start_node.

参数:
  • dag (DAGCircuit) -- the circuit to be compared.

  • start_node (DAGOpNode) -- the node to start compare in dag.

  • anchor (int) -- the anchor qubit in the circuit corresponding to the template.anchor.

返回:

mapping from node in template to node in dag.

返回类型:

dict

wy_qcos.transpiler.cmss.optimizer.template.generate_hadamard_gate_templates()

Generate Hadamard gate optimization templates.

Each template is composed of qubit count, reduction count, template

circuit, and replacement circuit.

返回:

a list of OptimizingTemplate.

返回类型:

list[OptimizingTemplate]

wy_qcos.transpiler.cmss.optimizer.template.generate_single_qubit_gate_templates()
返回类型:

list[OptimizingTemplate]

wy_qcos.transpiler.cmss.optimizer.template.generate_cnot_ctrl_templates()
返回类型:

list[OptimizingTemplate]

wy_qcos.transpiler.cmss.optimizer.template.generate_cnot_targ_templates()
返回类型:

list[OptimizingTemplate]

wy_qcos.transpiler.cmss.optimizer.template.search_template(graph, template)

Search template DAG in another DAG.

参数:
  • graph (rx.PyDAG | DAGCircuit) -- the DAG to search in.

  • template (rx.PyDAG) -- the DAG to search for.

返回:

dict is the mapping from graph to template,

list is the matched nodes in graph.

返回类型:

tuple(dict, list)

wy_qcos.transpiler.cmss.optimizer.template.replace_all(dag, template)

Replace all subcircuit in dag with template.

参数:
  • dag (DAGCircuit) -- the dag to be modified.

  • template (OptimizingTemplate) -- search for template.template in dag, and replace it with template.replacement.

返回:

the number of reduced gates.

返回类型:

int

wy_qcos.transpiler.cmss.optimizer.template.filter_templates_by_basis(templates, basis_gates, ignore_replacement=True)

Filter templates by basis gates.

参数:
  • templates (list[OptimizingTemplate]) -- templates to be filtered.

  • basis_gates (set) -- basis gates after decompose.

  • ignore_replacement (bool) -- If true, just filter templates only by template.template.

返回:

filtered templates.

返回类型:

list

Module contents