wy_qcos.transpiler.cmss.decomposer package

Submodules

wy_qcos.transpiler.cmss.decomposer.decomposer module

class wy_qcos.transpiler.cmss.decomposer.decomposer.Decomposer

基类:object

Entry point for circuit decomposition.

This class finds optimal decomposition paths for all operations in a circuit and applies them to generate an equivalent target circuit.

decompose(source, target)

Decomposes all operations in a circuit.

For each operation in the source circuit, this method finds the shortest decomposition path based on the equivalence graph and replaces the operation accordingly.

参数:
  • source (list[BaseOperation]) -- A list of operations to be decomposed.

  • target (list[str]) -- A list of str representing the target basis.

返回:

A list of operations representing the decomposed circuit.

返回类型:

list[BaseOperation]

get_decompose_rules(source, target)

Build the full decomposition table for given source gates.

This method queries the global equivalence graph and builds a full decomposition table that expands each source ParamGate into a sequence of ParamGates expressed only in the given target (basis) gate set.

Gates whose names are included in target will be treated as basis gates and will not be decomposed further.

参数:
  • source (list[str]) -- List of source gate names that require decomposition.

  • target (list[str]) -- List of target (basis) gate names. Gates in this set are considered terminal and will not be expanded further.

返回:

  • decomposition_table:

    Mapping from each template ParamGate to its fully expanded list of ParamGate objects expressed only using target gates.

  • usage_stats:

    Mapping from gate name to integer usage count collected during decomposition.

返回类型:

A tuple containing

抛出:
  • RuntimeError -- If the global equivalence graph has not been initialized.

  • ValueError -- If a required decomposition rule is missing in the graph.

apply_decompose_rules(circuit, table)

Apply a decomposition table to a quantum circuit.

This method rewrites each gate in the input circuit using a precomputed decomposition table. If a gate matches a ParamGate template in the table, it is replaced by the corresponding expanded sequence. Parameter expressions are evaluated and qubits are remapped during expansion.

参数:
  • circuit (list[BaseOperation]) -- List of BaseOperation objects representing the input circuit to be decomposed.

  • table (dict[ParamGate, list[ParamGate]]) -- Decomposition table produced by build_full_decomposition_table, mapping ParamGate templates to expanded ParamGate sequences.

返回:

A new list of BaseOperation objects where all decomposable gates have been replaced by their target-basis expansions.

抛出:

ValueError -- If parameter expression evaluation fails during expansion.

返回类型:

list[BaseOperation]

wy_qcos.transpiler.cmss.decomposer.equivalence_graph module

class wy_qcos.transpiler.cmss.decomposer.equivalence_graph.ParamGate(name, qubits, params=())

基类:object

Represents a parameterized quantum gate.

This class contains:
  • name (str): The name of the gate (e.g., 'u3', 'cx').

  • qubits (list[str]): list of qubit identifiers this gate acts on.

  • params (list[str], optional): list of parameter expressions for the gate.

参数:
  • name (str)

  • qubits (tuple[str, ...])

  • params (tuple[str, ...])

name: str
qubits: tuple[str, ...]
params: tuple[str, ...] = ()
class wy_qcos.transpiler.cmss.decomposer.equivalence_graph.EquivalenceRule(dsl)

基类:object

Represents an equivalence rule for decomposing quantum gates.

The rule is specified in a DSL string, for example:

"cx() q0,q1 -> u(pi/2,0,pi) q1 | cp(pi) q0,q1 | u(pi/2,0,pi) q1"

参数:

dsl (str)

target

The target gate to be decomposed.

Type:

ParamGate

sources

list of gates that represent the decomposition.

Type:

list[ParamGate]

class wy_qcos.transpiler.cmss.decomposer.equivalence_graph.RuleEdge(src: str, dst: str, rule: wy_qcos.transpiler.cmss.decomposer.equivalence_graph.EquivalenceRule, kind: str)

基类:object

参数:
src: str
dst: str
rule: EquivalenceRule
kind: str
class wy_qcos.transpiler.cmss.decomposer.equivalence_graph.EquivalenceGraph

基类:object

Graph of equivalence rules for quantum gate decomposition.

rules

list of all equivalence rules in the graph.

Type:

list[EquivalenceRule]

get_optimal_decomposition_rule_dictionary(source, target)

Generate optimal decomposition rules.

Generates a dictionary of optimal decomposition rules for given source and target operations.

参数:
  • source (list[str]) -- List of source gate names to be decomposed.

  • target (list[str]) -- List of target operations to achieve.

返回:

A mapping from operation name to equivalence rule.

返回类型:

dict[str, EquivalenceRule]

rule_edges()

Return all edges in the equivalence rule graph.

Each edge represents a transformation relationship derived from a rule. An edge goes from a source gate to a target gate and carries the rule that produces the target from the source.

返回:

A list of RuleEdge objects representing all producer edges in the equivalence rule graph.

返回类型:

list[RuleEdge]

to_dot()

Generate a Graphviz DOT representation of the rule graph.

This visualization shows:

  • Gate nodes as ellipses.

  • Rule nodes as boxes.

  • Directed edges from source gates to rule nodes, and from rule nodes to target gates.

返回:

A DOT-format string that can be rendered by Graphviz to visualize the equivalence rule graph.

返回类型:

str

build_full_decomposition_table(source, target)

Build full decomposition table for all non-target gates.

参数:
  • source (list[str]) -- Source gate names that may require decomposition.

  • target (list[str]) -- Target gate name set (basis gates).

返回:

Decomposition table and gate expansion count map.

返回类型:

tuple[dict[ParamGate, list[ParamGate]], dict[str, int]]

抛出:

ValueError -- If decomposition rule missing.

wy_qcos.transpiler.cmss.decomposer.euler_decomposer module

class wy_qcos.transpiler.cmss.decomposer.euler_decomposer.EulerDecomposer

基类:object

set_matrix(matrix)
euler_zyz_decomposition()

Decompose the unitary matrix into Rz(λ) Ry(θ) Rz(ϕ).

返回:

global phase lam: λ theta: θ phi: ϕ

返回类型:

coe

euler_u3_decomposition()

Decompose the unitary matrix into U3(λ,θ,ϕ).

返回:

global phase lam: λ theta: θ phi: ϕ

返回类型:

coe

reconstruct_from_zyz(theta, phi, lam)

Reconstruct matrix use Rz(λ) Ry(θ) Rz(ϕ).

参数:
  • lam -- λ.

  • theta -- θ.

  • phi -- ϕ.

返回:

the reconstructed Rz(λ) Ry(θ) Rz(ϕ) matrix.

reconstruct_from_u3(theta, phi, lam)

Reconstruct matrix use U3(λ,θ,ϕ).

参数:
  • lam -- λ.

  • theta -- θ.

  • phi -- ϕ.

返回:

the reconstructed U3(λ,θ,ϕ) matrix.

run(basis='zyz')

Euler decompose ,decompose the unitary matrix into u3 or zyz gate.

参数:

basis -- zyz or u3

返回:

lam, theta, phi.

wy_qcos.transpiler.cmss.decomposer.generate_su4_matrix module

class wy_qcos.transpiler.cmss.decomposer.generate_su4_matrix.GenerateSU4

基类:object

random_unitary(N)

Generate random unitary matrix.

参数:

N -- matrix order

返回:

matrix

uniform()

Generate (kx, ky, kz) that satisfy all constraints.

返回:

kx, ky, kz

wy_qcos.transpiler.cmss.decomposer.kak_decomposer module

class wy_qcos.transpiler.cmss.decomposer.kak_decomposer.KAKDecomposer

基类:object

set_matrix(matrix)

Set the matrix to be decomposed.

参数:

matrix -- unitary matrix.

get_glob_phase(mat)

Remove the global phase of unitary matrix.

参数:

mat -- unitary matrix.

返回:

matrix without global phase.

decompose_matrix(mat)

Split a 4x4 matrix into two 2x2 matrices, and a global factor.

参数:

mat -- 4x4 unitary matrix.

返回:

a pair of 2x2 unit-determinant matrices.

simu_svd()

Simultaneous SVD of two matrices, based on Eckart-Young theorem.

返回:

q_left, q_right, ashn, phase.

run()

KAK decomposition of an arbitrary two-qubit gate.

返回:

including 1 ashn gate and 4 single-qubit gates.

euler_decompose(mat)

Obtain the U3 parameters of a 2x2 unitary matrix.

参数:

mat -- 2x2 unitary matrix

返回:

lam, theta, phi.

wy_qcos.transpiler.cmss.decomposer.rule_applier module

class wy_qcos.transpiler.cmss.decomposer.rule_applier.RuleApplier

基类:object

Applies equivalence rules (RulePath) to actual quantum circuits.

This class is responsible for mapping placeholder gates in rules to real gates in the circuit, automatically handling qubit and parameter mapping.

apply_one_rule(op, rule)

Applies a single equivalence rule to a specific gate operation.

参数:
返回:

list of new gate operations after

applying the rule.

返回类型:

list[BaseOperation]

备注

  • Placeholder qubits in the rule are automatically mapped to

    the gate's qubits.

  • Placeholder parameters are automatically evaluated using

    the gate's argument values.

  • The symbol 'pi' is automatically available in parameter

    expressions.

apply_path(circuit, target, rule_dict)

Recursively decompose a quantum circuit using equivalence rules.

Each gate in the input circuit is recursively decomposed using the provided equivalence rules until it becomes a target gate. Results of gate decompositions are memoized to avoid repeated work and improve performance.

参数:
  • circuit (list[BaseOperation]) -- A list of BaseOperation objects representing the original quantum circuit.

  • target (list[str]) -- A list of gate names that are considered target (basis) gates. Gates whose name is in this list will not be decomposed further.

  • rule_dict (dict[str, EquivalenceRule]) -- A mapping from gate names to their corresponding EquivalenceRule objects used for decomposition.

返回:

A list of BaseOperation objects representing the fully decomposed circuit, containing only target gates.

抛出:

KeyError -- If a gate is not in the target set and no decomposition rule is found for it in rule_dict.

返回类型:

list[BaseOperation]

apply_with_decomposition_table(circuit, table)

Apply a pre-built decomposition table to a circuit.

Each gate in the input circuit is replaced by its fully expanded decomposition sequence if a matching ParamGate template exists in the table. Parameter expressions are numerically evaluated using numexpr with the gate argument environment.

参数:
  • circuit (list[BaseOperation]) -- List of BaseOperation objects representing the input circuit.

  • table (dict[ParamGate, list[ParamGate]]) -- Mapping from template ParamGate to its expanded ParamGate decomposition sequence.

返回:

A new list of BaseOperation objects after decomposition.

抛出:

ValueError -- If parameter expression evaluation fails.

返回类型:

list[BaseOperation]

Module contents