mqt.qecc.code_switching.code_switching_compiler¶
Code Switching Compiler to find the minimum number of switches.
Classes¶
Holds all configuration parameters for the MinimalCodeSwitchingCompiler. |
|
A directed graph representation of a quantum circuit for code-switching analysis using min-cut / max-flow optimization. |
Module Contents¶
- class CompilerConfig[source]¶
Holds all configuration parameters for the MinimalCodeSwitchingCompiler.
- class MinimalCodeSwitchingCompiler(gate_set_code_source: set[str], gate_set_code_sink: set[str], config: CompilerConfig | None = None)[source]¶
A directed graph representation of a quantum circuit for code-switching analysis using min-cut / max-flow optimization.
- The graph is constructed such that:
Each quantum operation (e.g. T, H, CNOT) corresponds to one or more nodes.
- Source (SRC) and sink (SNK) nodes represent two different codes:
Source-connected nodes (e.g. H, CNOT) → operations that can be done transversally in a 2D Color Code.
Sink-connected nodes (e.g. T, CNOT) → operations that can be done transversally in a 3D Surface Code.
Infinite-capacity edges enforce code consistency between operations (e.g., CNOT links).
Finite-capacity (temporal) edges represent potential code transitions along qubit timelines.
Attributes:¶
- gate_set_sourceset[str]
Set of gate types supported by code A (e.g., 2D Color Code). This gate set is associated with the source node. Should be provided as a set of strings, e.g., {“H”, “CNOT”}.
- gate_set_sinkset[str]
Set of gate types supported by code B (e.g., 3D Surface Code). This gate set is associated with the sink node. Should be provided as a set of strings, e.g., {“T”, “CNOT”}.
- common_gatesset[str]
Set of gate types that can be performed transversally in both codes.
- configCompilerConfig
Configuration parameters for the compiler.
- Gnx.DiGraph
Directed graph storing the nodes and edges.
- sourcestr
Identifier for the source node (“SRC”).
- sinkstr
Identifier for the sink node (“SNK”).
- compute_idle_bonus(previous_depth: int, current_depth: int, total_edges: int) float[source]¶
Compute a normalized bonus (capacity reduction) for idling qubits.
Formula: idle_time / (total_edges * (idle_time + 1))
This creates a ‘micro-bias’. It ensures that the bonus is always significantly smaller than the base capacity, acting only as a tie-breaker for the min-cut algorithm rather than forcing a cut.
Parameters¶
- previous_depthint
The depth index of the previous active gate.
- current_depthint
The depth index of the current active gate.
- total_edgesint
The total count of temporal edges (qubit-operations) in the circuit.
Returns:¶
- float
The capacity reduction to apply.
- build_from_qiskit(circuit: qiskit.QuantumCircuit, *, one_way_gates: dict[str, tuple[str, str]] | None = None, code_bias: bool = False, idle_bonus: bool = False) None[source]¶
Construct the code-switch graph generically.
Parameters¶
- circuitQuantumCircuit
The input quantum circuit.
- code_biasbool, optional
If True, add bias edges for nodes. Default is False.
- idle_bonusbool, optional
If True, reduce temporal edge capacities based on idle durations via _edge_capacity_with_idle_bonus. Default is False.
- one_way_gatesdict[str, tuple[str, str]], optional
A dict mapping multi-qubit gate names (e.g., “CX”) to direction tuples (e.g., (“SNK”, “SRC”)) specifying which code the control and target qubits should be in for one-way transversal execution. If a common multi-qubit gate is NOT in this dict, it is assumed both qubits must be in the same code (bidirectional infinite edges).
- compute_min_cut() tuple[int, list[tuple[int, int]], set[str], set[str]][source]¶
Compute the minimum s-t cut between the source and sink.
Returns:¶
- tuple[int, list[tuple[int, int]], set[str], set[str]]
- A tuple (num_switches, switch_positions, S, T) where:
num_switches is the count of temporal edges crossing the cut (number of code switches),
switch_positions is a list of (qubit, depth) pairs where switches occur,
S is the set of nodes reachable from the source,
T is the complementary set of nodes.