GlobalFoldPass

class GlobalFoldPass(scale_factor)[source]

Bases: TransformationPass

Global unitary folding with fractional scale-factor support.

For a target scale factor s on a circuit of d unitary 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† · L where L is the sub-circuit of the last n unitary gates of U. Post-transform gate count is d · (1 + 2k) + 2n and effective scale factor is 1 + 2k + 2n/d. Non-unitary instructions (measure, reset, barrier) are ignored when counting d and 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 small d the effective scale may differ from the request. Use effective_scale() to query the realised value.

Mirrors Mitiq’s fold_global behavior. 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 LocalFoldPass with exclude={"cx", ...} if you need to protect specific gates from folding.

Parameters:

scale_factor (float) – Real number ≥ 1. 1.0 is 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 dag in 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:

float

run(dag)[source]

Fold dag in 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 TransformationPass contract.

Return type:

DAGCircuit

Returns:

The same dag object, mutated to contain the folded circuit.