qat.experimental.dialect.pulse.transforms.constants module

class FoldConstantConstantOp

Bases: RewritePattern

Finds arithmetic operations whose operands are both constant-like and folds them into a single ConstantOp with the result of the operation as its value.

This is hooked in from canonicalization passes, and eliminates redundant arithmetic operations in the pulse dialect.

For example,

%frequency1 = pulse.constant<5e9> : !pulse.frequency
%frequency2 = pulse.constant<1e9> : !pulse.frequency
%result = pulse.add(%frequency1, %frequency2) : !pulse.frequency

can be replaced with

match_and_rewrite(op: Operation, rewriter: PatternRewriter) None

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

Return type:

None

class PulseConstantFoldAdapter

Bases: ABC

Abstract base class for constant folding adapters.

abstract fold(op, lhs, rhs)

Using the context of the binary operation, folds two attributes from constant- like operations into a single constant attribute if possible, returning None if the attributes cannot be folded.

Return type:

Attribute | None

class ScalarConstantFoldAdapter(attr_constructor, exponent_map=None)

Bases: PulseConstantFoldAdapter

Base class for folding binary operations on scalar attributes in the pulse dialect.

Unpacks the values from the attributes, promotes units if necessary, applies the binary operation, and then constructs a new attribute with the result.

Parameters:
  • attr_constructor (type[Attribute]) – A callable that takes the result of the binary operation (and unit if applicable) and returns a new attribute.

  • exponent_map (Optional[dict[Enum, int]]) – An optional mapping from unit enum values to decimal exponents If provided, the adapter will align the units of the two attributes using these exponents before performing the binary operation.

fold(op, lhs, rhs)

Folds two scalar attributes, potentially with units, into a single attribute if possible, returning None if the attributes cannot be folded.

Return type:

Attribute | None

class WaveformConstantFoldAdapter

Bases: PulseConstantFoldAdapter

Adapter for folding binary operations on SampledWaveformAttrs, which requires special handling to ensure that the widths and sample times of the waveforms are compatible.

fold(op, lhs, rhs)

Folds two attributes, one of which being a SampledWaveformAttr, into a single SampledWaveformAttr if possible, returning None if the attributes cannot be folded.

Return type:

Attribute | None