qat.experimental.dialect.pulse.transforms.optimize_contiguous_squashable_instructions module

Contiguous pulse-frame optimizations for phase and delay instructions.

Optimize contiguous phases and delays within a frame, leveraging that phase instructions commute with wait instructions. This allows for folding sequences of phase shifts interleaved with waits into a single phase operation. Likewise, sequences of wait instructions interleaved with phase shifts can also be folded into a single wait. This reduces the number of quantum instructions.

class ApplySquashContiguousOptimizations

Bases: ModulePass

Apply commuting + contiguous fold optimizations.

apply(ctx, op)
Return type:

None

name: ClassVar[str] = 'apply-squash-contiguous-optimizations'
class CommuteWaitBeforePhaseShift

Bases: RewritePattern

Commute phase shift operations past wait operations to enable better folding.

Scenario 1: PhaseShift, Wait -> Wait, PhaseShift

%frame = pulse.create_frame(%frequency) {physical_channel = "channel_1"}
    : !pulse.frame
%phase = pulse.constant<0.5> : !pulse.phase
%duration = pulse.constant<1.0e-9> : !pulse.time
%shift = pulse.phase_shift(%frame, %phase) : !pulse.frame
%wait = pulse.wait(%shift, %duration) : !pulse.frame
%acquire = pulse.acquire(%wait, %duration) : !pulse.frame

becomes:

%frame = pulse.create_frame(%frequency) {physical_channel = "channel_1"}
    : !pulse.frame
%phase = pulse.constant<0.5> : !pulse.phase
%duration = pulse.constant<1.0e-9> : !pulse.time
%wait = pulse.wait(%frame, %duration) : !pulse.frame
%shift = pulse.phase_shift(%wait, %phase) : !pulse.frame
%acquire = pulse.acquire(%shift, %duration) : !pulse.frame

This enables subsequent folding of multiple waits or phases that were initially interleaved. Repeated application via GreedyRewritePatternApplier bubbles all waits to one side, after which fold patterns eliminate redundant operations.

match_and_rewrite(op: Operation, rewriter: PatternRewriter) None

Match an operation, and optionally perform a rewrite using the rewriter.

Return type:

None

class FoldContiguousPhases

Bases: RewritePattern

Fold contiguous phase shifts on the same frame into a single phase shift or set.

Scenario 1: PhaseShift + PhaseShift

%frame = pulse.create_frame(%frequency) {physical_channel = "channel_1"}
    : !pulse.frame
%p1 = pulse.constant<0.5> : !pulse.phase
%p2 = pulse.constant<1.0> : !pulse.phase
%shift1 = pulse.phase_shift(%frame, %p1) : !pulse.frame
%shift2 = pulse.phase_shift(%shift1, %p2) : !pulse.frame
%acquire = pulse.acquire(%shift2, %duration) : !pulse.frame

becomes:

%frame = pulse.create_frame(%frequency) {physical_channel = "channel_1"}
    : !pulse.frame
%p1 = pulse.constant<0.5> : !pulse.phase
%p2 = pulse.constant<1.0> : !pulse.phase
%total = pulse.add(%p1, %p2) : !pulse.phase
%merged = pulse.phase_shift(%frame, %total) : !pulse.frame
%acquire = pulse.acquire(%merged, %duration) : !pulse.frame

Scenario 2: PhaseShift + PhaseSet

%frame = pulse.create_frame(%frequency) {physical_channel = "channel_1"}
    : !pulse.frame
%p1 = pulse.constant<0.5> : !pulse.phase
%p2 = pulse.constant<1.0> : !pulse.phase
%shift = pulse.phase_shift(%frame, %p1) : !pulse.frame
%set = pulse.phase_set(%shift, %p2) : !pulse.frame
%acquire = pulse.acquire(%set, %duration) : !pulse.frame

becomes:

Scenario 3: PhaseSet + PhaseShift

%frame = pulse.create_frame(%frequency) {physical_channel = "channel_1"}
    : !pulse.frame
%p1 = pulse.constant<0.5> : !pulse.phase
%p2 = pulse.constant<1.0> : !pulse.phase
%set = pulse.phase_set(%frame, %p1) : !pulse.frame
%shift = pulse.phase_shift(%set, %p2) : !pulse.frame
%acquire = pulse.acquire(%shift, %duration) : !pulse.frame

becomes:

%frame = pulse.create_frame(%frequency) {physical_channel = "channel_1"}
    : !pulse.frame
%p1 = pulse.constant<0.5> : !pulse.phase
%p2 = pulse.constant<1.0> : !pulse.phase
%total = pulse.add(%p1, %p2) : !pulse.phase
%merged = pulse.phase_set(%frame, %total) : !pulse.frame
%acquire = pulse.acquire(%merged, %duration) : !pulse.frame

Scenario 4: PhaseSet + PhaseSet

%frame = pulse.create_frame(%frequency) {physical_channel = "channel_1"}
    : !pulse.frame
%p1 = pulse.constant<0.5> : !pulse.phase
%p2 = pulse.constant<1.0> : !pulse.phase
%set1 = pulse.phase_set(%frame, %p1) : !pulse.frame
%set2 = pulse.phase_set(%set1, %p2) : !pulse.frame
%acquire = pulse.acquire(%set2, %duration) : !pulse.frame

becomes:

%frame = pulse.create_frame(%frequency) {physical_channel = "channel_1"}
    : !pulse.frame
%p2 = pulse.constant<1.0> : !pulse.phase
%merged = pulse.phase_set(%frame, %p2) : !pulse.frame
%acquire = pulse.acquire(%merged, %duration) : !pulse.frame
match_and_rewrite(op: Operation, rewriter: PatternRewriter) None

Match an operation, and optionally perform a rewrite using the rewriter.

Return type:

None

class FoldContiguousWaits

Bases: RewritePattern

Fold contiguous wait operations on the same frame into a single wait.

Scenario 1: Wait + Wait

%frame = pulse.create_frame(%frequency) {physical_channel = "channel_1"}
    : !pulse.frame
%duration1 = pulse.constant<1.0e-9> : !pulse.time
%duration2 = pulse.constant<2.0e-9> : !pulse.time
%wait1 = pulse.wait(%frame, %duration1) : !pulse.frame
%wait2 = pulse.wait(%wait1, %duration2) : !pulse.frame
%acquire = pulse.acquire(%wait2, %duration) : !pulse.frame

becomes:

%frame = pulse.create_frame(%frequency) {physical_channel = "channel_1"}
    : !pulse.frame
%duration1 = pulse.constant<1.0e-9> : !pulse.time
%duration2 = pulse.constant<2.0e-9> : !pulse.time
%total = pulse.add(%duration1, %duration2) : !pulse.time
%merged = pulse.wait(%frame, %total) : !pulse.frame
%acquire = pulse.acquire(%merged, %duration) : !pulse.frame
match_and_rewrite(op: Operation, rewriter: PatternRewriter) None

Match an operation, and optionally perform a rewrite using the rewriter.

Return type:

None