Skip to content

[WIP] OpenPulse dialect - #116

Draft
braised-babbage wants to merge 3 commits into
xdslproject:mainfrom
braised-babbage:pulse-dialect
Draft

[WIP] OpenPulse dialect#116
braised-babbage wants to merge 3 commits into
xdslproject:mainfrom
braised-babbage:pulse-dialect

Conversation

@braised-babbage

@braised-babbage braised-babbage commented Sep 11, 2025

Copy link
Copy Markdown

This is a very rough and incomplete start at what could eventually be an OpenPulse dialect. Mostly I wrote this to improve my own understanding of xDSL, though I am opening a draft MR to share with others at the MLIR (Un)School.

OpenPulse introduces a few new types to OpenQASM

In this PR I also add a duration type, though this might naturally get shared with an OpenQASM dialect.

The OpenPulse spec allows for several operations which have an effect on frame state (phase, frequency, etc). For now I've only considered a hyper-minimalist subset with two timing related ops

  • delay on a frame
  • barrier on some sequence of frames

I sketched out an (incomplete) pass to do easy timing calculations on straight line programs and attach this information as attributes.

Design Notes

  • For frames, I am taking some inspiration from what I have seen in the RISC-V dialect for how registers are handled. In this case, the frame type carries an attribute identifying the actual frame.
  • OpenPulse operations which "mutate" a frame are modeled here as consume an SSA value and returning a new one, with the same type (i.e. the same frame).
  • Durations are basically just typed integers, and I added ops to convert to and from builtin integers.
  • I added an explicit pulse.const_duration op since it seemed convenient to be able to have a canonical way to carry constant values here (rather than trying to work this out indirectly).

@alexarice alexarice left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool, I've left a few minor comments.

I understand this is a draft PR, but if you'd like to get things merged it would be great to split this into separate PRs, one which adds the dialect, and one which adds the transformation.



@irdl_attr_definition
class DurationType(ParametrizedAttribute, TypeAttribute):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the motivation to have a different type for durations which you then cast to from int types, instead of just using index to begin with?

# inspired by builtin's `index`
name = "pulse.duration"

# todo: make this parametric by underlying value type?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unlikely this needs to be parametric unless the openpulse durations are also parametric over their type.

"""

name = "pulse.frame"
frame_name: builtin.StringAttr

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
frame_name: builtin.StringAttr
frame_name: StringAttr

Nit: lets just import things directly?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
frame_name: builtin.StringAttr
frame_name: StringAttr = param_def(converter = StringAttr.get)

Could even do this, which would generate an __init__ of which takes a StringAttr | str as a parameter.

return cls(builtin.StringAttr(frame_name))


FrameT = TypeVar("FrameT", bound=FrameType)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks unused?

class AllocFrame(IRDLOperation):
name = "pulse.alloc_frame"
result = result_def(FrameType)
traits = traits_def()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need to add an empty traits field.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants