qat.experimental.dialect.q1_scf.ir.ops module

q1_scf dialect operations.

Structured control flow for a single QBlox Q1 sequencer. The dialect sits above q1_cf, the target-specific block CFG, and below the pulse level.

It defines one conditional and two loop containers together with two terminators:

  • IfOp is the structured conditional used for single-sequencer feedforward.

  • WhileOp is the general loop with an explicit before/after split.

  • ForOp is the counted loop whose induction value is the remaining count.

  • ConditionOp terminates the before region of a WhileOp.

  • YieldOp terminates ForOp, the after region of a WhileOp, and each region of an IfOp.

A condition carries a predicate and its register operands in the same shape as q1_cf. The Q1 ISA provides no instruction that reduces a comparison to a boolean, so a relational guard is represented as register operands paired with a predicate that lowering regenerates adjacent to the branch reading the ALU flags. Every predicate operand is a q1.reg and the dialect defines no i1 operands. A measurement outcome therefore reaches q1_scf only as a q1.reg dequeued through q1_linq, never through q1_trigger.

Reference: https://docs.qblox.com/en/main/products/qblox_instruments/q1/index.html

class ConditionOp(predicate, predicate_args, forward_args)

Bases: ConditionOp, IRDLOperation, Operation, _IRNode, ABC, object

Terminate the before region of a WhileOp.

The loop continues while predicate holds over its register operands, and the forward_args are threaded to the after region or, on exit, to the loop results.

q1_scf.condition slt %x : q1.reg, %n : q1.reg (%acc : q1.reg)
attributes: dict[str, Attribute]

The attributes attached to the operation.

forward_args

Access a variadic construct when there is a “segment size” attribute.

classmethod get_irdl_definition()

Get the IRDL operation definition.

irdl_options = (AttrSizedOperandSegments(as_property=False),)
location: LocationAttr

The source location attached to this operation.

name: ClassVar[str] = 'q1_scf.condition'

The operation name. Should be a static member of the class

classmethod parse(parser)
Return type:

Self

predicate

Accessor for an operation property.

predicate_args

Access a variadic construct when there is a “segment size” attribute.

print(printer)
Return type:

None

properties: dict[str, Attribute]

The properties attached to the operation. Properties are inherent to the definition of an operation’s semantics, and thus cannot be discarded by transformations.

traits: ClassVar[OpTraits] = <xdsl.ir.core.OpTraits object>

Traits attached to an operation definition. This is a static field, and is made empty by default by PyRDL if not set by the operation definition.

verify_()
class ForOp(iter_count, iter_args, body, iter_domain=None)

Bases: ForOp, IRDLOperation, RegisterAllocatableOperation, Operation, _IRNode, ABC, object

Counted loop whose induction value is the remaining count.

iter_count counts down to zero, mapping one-to-one onto the native Q1 decrement-and-branch loop and onto q1_cf.loop_branch. The body is a single block terminated by YieldOp, and its entry block arguments are the induction counter followed by the carried values. A ForOp is reducible to a WhileOp. The optional iter_domain records the linear iteration the counted loop realises.

q1_scf.for %n : q1.reg iter_args(%acc : q1.reg) { ... }
allocate_registers(allocator)

Entry point for structured register allocation over this loop.

This allocation is done under the following assumptions: :rtype: None

  • The iter_args that instantiate the loop-carried arguments are not consumed after initialising the loop. This is to prevent accidental reallocation due to the coalescing constraints between the iter_args and the block arguments.

  • The iter_count is not consumed after initialising the loop. This is to prevent accidental reallocation due to the coalescing constraints between the iter_count and the induction variable.

  • Relocations are applied to block arguments where required to allow for register allocation with the coalescing constraints.

Because of these assumptions, not every allocation is possible. It’s expected that legalisation via relocations happens prior to allocation. In particular, lowering from other dialects would enforce this through move operations on iter args, block arguments and the induction variable.

attributes: dict[str, Attribute]

The attributes attached to the operation.

body

Access a non-variadic construct which appears before any variadic arguments.

classmethod get_irdl_definition()

Get the IRDL operation definition.

iter_args

Access a variadic construct in the case where it is the only variadic.

iter_count

Access a non-variadic construct which appears before any variadic arguments.

iter_domain

Accessor for an optional operation property.

location: LocationAttr

The source location attached to this operation.

name: ClassVar[str] = 'q1_scf.for'

The operation name. Should be a static member of the class

classmethod parse(parser)
Return type:

Self

print(printer)
Return type:

None

properties: dict[str, Attribute]

The properties attached to the operation. Properties are inherent to the definition of an operation’s semantics, and thus cannot be discarded by transformations.

res

Access a variadic construct in the case where it is the only variadic.

traits: ClassVar[OpTraits] = <xdsl.ir.core.OpTraits object>

Traits attached to an operation definition. This is a static field, and is made empty by default by PyRDL if not set by the operation definition.

verify_()
class IfOp(predicate, predicate_args, result_types, then_region, else_region=None)

Bases: IfOp, IRDLOperation, RegisterAllocatableOperation, Operation, _IRNode, ABC, object

Structured conditional for single-sequencer feedforward.

Evaluates predicate over its register operands, runs the then region or the optional else region, and returns their yielded values as its results. Both regions are terminated by YieldOp. Feedforward here denotes intra-sequencer conditional execution, distinct from a loop or a cross-sequencer message.

q1_scf.if nez %flag : q1.reg -> (q1.reg) { ... } else { ... }
allocate_registers(allocator)

Entry point for structured register allocation over this conditional.

Ensures the yield arguments of the then and else regions are allocated to the same registers as the results of the IfOp, and that the predicate operands are allocated to registers. Allocates each region separately, allowing use of shared registers between the two regions.

Return type:

None

attributes: dict[str, Attribute]

The attributes attached to the operation.

else_region

Access a non-variadic construct which appears before any variadic arguments.

classmethod get_irdl_definition()

Get the IRDL operation definition.

location: LocationAttr

The source location attached to this operation.

name: ClassVar[str] = 'q1_scf.if'

The operation name. Should be a static member of the class

output

Access a variadic construct in the case where it is the only variadic.

classmethod parse(parser)
Return type:

Self

predicate

Accessor for an operation property.

predicate_args

Access a variadic construct in the case where it is the only variadic.

print(printer)
Return type:

None

properties: dict[str, Attribute]

The properties attached to the operation. Properties are inherent to the definition of an operation’s semantics, and thus cannot be discarded by transformations.

then_region

Access a non-variadic construct which appears before any variadic arguments.

traits: ClassVar[OpTraits] = <xdsl.ir.core.OpTraits object>

Traits attached to an operation definition. This is a static field, and is made empty by default by PyRDL if not set by the operation definition.

verify_()
class WhileOp(init_args, result_types, before_region, after_region)

Bases: WhileOp, IRDLOperation, RegisterAllocatableOperation, Operation, _IRNode, ABC, object

General structured loop with a before/after split.

The before region computes and tests the loop condition and is terminated by ConditionOp. The after region is the loop body, terminated by YieldOp, whose yielded values feed back to the before block arguments. Any structured loop is expressible in this form.

q1_scf.while (%acc : q1.reg) -> (q1.reg) { ... } do { ... }
after_region

Access a non-variadic construct which appears before any variadic arguments.

allocate_registers(allocator)

Entry point for structured register allocation over this loop.

Return type:

None

attributes: dict[str, Attribute]

The attributes attached to the operation.

before_region

Access a non-variadic construct which appears before any variadic arguments.

classmethod get_irdl_definition()

Get the IRDL operation definition.

init_args

Access a variadic construct in the case where it is the only variadic.

location: LocationAttr

The source location attached to this operation.

name: ClassVar[str] = 'q1_scf.while'

The operation name. Should be a static member of the class

classmethod parse(parser)
Return type:

Self

print(printer)
Return type:

None

properties: dict[str, Attribute]

The properties attached to the operation. Properties are inherent to the definition of an operation’s semantics, and thus cannot be discarded by transformations.

res

Access a variadic construct in the case where it is the only variadic.

traits: ClassVar[OpTraits] = <xdsl.ir.core.OpTraits object>

Traits attached to an operation definition. This is a static field, and is made empty by default by PyRDL if not set by the operation definition.

verify_()
class YieldOp(*arguments)

Bases: YieldOp, IRDLOperation, Operation, _IRNode, ABC, object

Terminate a structured region, forwarding register values to its parent.

Terminates the body of a ForOp, the after region of a WhileOp, and each region of an IfOp.

q1_scf.yield %a, %b : q1.reg, q1.reg
arguments

Access a variadic construct in the case where it is the only variadic.

assembly_format: ClassVar[str | None] = 'attr-dict ($arguments^ `:` type($arguments))?'
attributes: dict[str, Attribute]

The attributes attached to the operation.

classmethod get_irdl_definition()

Get the IRDL operation definition.

location: LocationAttr

The source location attached to this operation.

name: ClassVar[str] = 'q1_scf.yield'

The operation name. Should be a static member of the class

classmethod parse(parser: Parser) IRDLOperationInvT
Return type:

TypeVar(IRDLOperationInvT, bound= IRDLOperation)

print(printer: Printer)
properties: dict[str, Attribute]

The properties attached to the operation. Properties are inherent to the definition of an operation’s semantics, and thus cannot be discarded by transformations.

traits: ClassVar[OpTraits] = <xdsl.ir.core.OpTraits object>

Traits attached to an operation definition. This is a static field, and is made empty by default by PyRDL if not set by the operation definition.

verify_()