GlobalFoldPass¶
- class GlobalFoldPass(scale_factor)[source]¶
Bases:
TransformationPassGlobal unitary folding with fractional scale-factor support.
For a target scale factor
son a circuit ofdunitary gates:k = (s - 1) // 2 # full forward-and-back folds remainder = s - (1 + 2k) n = round(remainder · d / 2) # gates folded at the tail
The returned DAG is
U · (U† · U)^k · L† · LwhereLis the sub-circuit of the lastnunitary gates ofU. Post-transform gate count isd · (1 + 2k) + 2nand effective scale factor is1 + 2k + 2n/d. Non-unitary instructions (measure,reset,barrier) are ignored when countingdand selecting the tail.Example — for a 4-gate circuit:
requested s | k | n | size | effective s ---------------------------------------- 1.5 | 0 | 1 | 6 | 1.5 2.0 | 0 | 2 | 8 | 2.0 3.0 | 1 | 0 | 12 | 3.0 3.5 | 1 | 1 | 14 | 3.5
The achievable scales form a grid of granularity
2/d— for smalldthe effective scale may differ from the request. Useeffective_scale()to query the realised value.Mirrors Mitiq’s
fold_globalbehavior. Deterministic: the same(circuit, scale_factor)always produces the same folded circuit.Note: this pass folds the full unitary and has no per-gate exclude mechanism — use
LocalFoldPasswithexclude={"cx", ...}if you need to protect specific gates from folding.- Parameters:
scale_factor (
float) – Real number ≥ 1.1.0is a pass-through.- Raises:
ValueError – If
scale_factor< 1.
Methods Summary
effective_scale(dag)Scale factor actually realised on
dag(may differ from the requested value when the gate count is too small for the fractional part to round cleanly — see_compute_effective_scale).run(dag)Fold
dagin place and return the mutated DAG.Methods Documentation
- effective_scale(dag)[source]¶
Scale factor actually realised on
dag(may differ from the requested value when the gate count is too small for the fractional part to round cleanly — see_compute_effective_scale).- Return type:
- run(dag)[source]¶
Fold
dagin place and return the mutated DAG.The input is consumed — callers that need the original should deepcopy before invoking the pass. Matches the standard Qiskit
TransformationPasscontract.- Return type:
- Returns:
The same
dagobject, mutated to contain the folded circuit.