Skip to content

📝 Getting Started With MLIR#1555

Open
MatthiasReumann wants to merge 83 commits into
mainfrom
docs/getting_started_mlir
Open

📝 Getting Started With MLIR#1555
MatthiasReumann wants to merge 83 commits into
mainfrom
docs/getting_started_mlir

Conversation

@MatthiasReumann
Copy link
Copy Markdown
Collaborator

@MatthiasReumann MatthiasReumann commented Mar 12, 2026

Description

This pull request adds a "Getting Started with MLIR" tutorial to the ReadTheDocs documentation. Thus, resolves #1452.

Checklist:

  • The pull request only contains commits that are focused and relevant to this change.
  • I have added appropriate tests that cover the new/changed functionality.
  • I have updated the documentation to reflect these changes.
  • I have added entries to the changelog for any noteworthy additions, changes, fixes, or removals.
  • I have added migration instructions to the upgrade guide (if needed).
  • The changes follow the project's style guidelines and introduce no new warnings.
  • The changes are fully tested and pass the CI checks.
  • I have reviewed my own code changes.

@MatthiasReumann
Copy link
Copy Markdown
Collaborator Author

@burgholzer @denialhaag @DRovara
Hello everyone 👋🏻

I am pretty sure everyone of you has an opinion on how this getting started guide should look - and should not look. Hence, I kindly asked for a review from each one of you. I hope this is okay!

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 12, 2026

📝 Walkthrough

Walkthrough

Adds a new MLIR "Getting Started" guide at docs/mlir/GettingStarted.md and registers it in docs/mlir/index.md. The guide includes build/verification steps, MLIR fundamentals, QC vs QCO semantics with example MLIR snippets and diagrams, and end-to-end compilation/optimization/tooling examples. (39 words)

Changes

Cohort / File(s) Summary
New MLIR Documentation
docs/mlir/GettingStarted.md
Introduces an end-to-end getting started tutorial: installation/build verification (CMake with MLIR_DIR, LLVM_DIR, CMAKE_BUILD_TYPE=Release, BUILD_MQT_CORE_MLIR=ON), MLIR primer (dialects, SSA, types, ops, blocks/regions, control-flow), QC vs QCO comparison (reference vs value semantics, linear typing) with side-by-side MLIR examples and diagrams, compilation architecture (OpenQASM → QC → QCO → QC, optional QIR/LLVM lowering), and runnable examples (mqt-cc usage, --emit-qir, mlir-translate conversion).
Documentation Index
docs/mlir/index.md
Adds GettingStarted to the MLIR toctree navigation (single-line insertion).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Poem

🐇 I hopped through docs with circuits in tow,
Hadamards and Bell states painted in flow,
QC and QCO waltzed, snippets in sight,
Builds and translations gleamed soft and bright,
I twitched my nose—now go run that first flow!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title uses an emoji and refers specifically to 'Getting Started With MLIR', which directly matches the content added: a new getting started guide for MLIR.
Linked Issues check ✅ Passed The PR comprehensively addresses issue #1452 objectives: installation/build setup, Hello Quantum walkthrough with Bell state, QC vs QCO comparison with examples, advanced constructs discussion, and MLIR primer with diagrams.
Out of Scope Changes check ✅ Passed All changes are scoped to the MLIR getting started guide documentation. The two files modified (GettingStarted.md and index.md) are directly aligned with the linked issue requirements.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The PR description includes a clear summary of changes (adds Getting Started with MLIR tutorial), references the resolved issue (#1452), and provides a substantially completed checklist showing which PR quality standards were met.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch docs/getting_started_mlir

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@burgholzer burgholzer added documentation Improvements or additions to documentation MLIR Anything related to MLIR labels Mar 12, 2026
@burgholzer burgholzer added this to the MLIR Support milestone Mar 12, 2026
Copy link
Copy Markdown
Collaborator

@DRovara DRovara left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the work, @MatthiasReumann! All in all, it already looks pretty nice. I still tried to give some (maybe controversial) opinions, just to make sure everything is clear. None of them are really set in stone, just suggestions.

That being said though: I believe there is still some room for discussion when it comes to who the target audience should be for this "Getting Started Guide":

  • Probably it shouldn't be quantum algorithm engineers who just want to compile their code. They don't care what happens in the background.
  • Then, one would assume it's compiler developers. But why would compiler developers care about the qc dialect (which the majority of this tutorial is about).

All in all, this brings me to the big question: Is it really the "correct" approach to give the getting started guide in terms of the QC dialect? People are never supposed to write MLIR code anyways - we will likely have some other front-end or DSL for that. So the only time when the code will use QC is during the translation process (and for the output, if the user does not compile down to QIR). The only advantage that QC has over QCO is that it is simpler, but it is weird to argue, for a tutorial "we won't explain the important thing because that is too complicated, so instead we explain the less important thing".

What are everyone else's thoughts on that?

Comment thread docs/mlir/GettingStarted.md Outdated
Comment thread docs/mlir/GettingStarted.md Outdated
Comment thread docs/mlir/GettingStarted.md Outdated
Comment thread docs/mlir/GettingStarted.md Outdated
Comment thread docs/mlir/GettingStarted.md Outdated
Comment thread docs/mlir/GettingStarted.md Outdated
Comment thread docs/mlir/GettingStarted.md Outdated
Comment thread docs/mlir/GettingStarted.md
Comment thread docs/mlir/GettingStarted.md Outdated
Comment thread docs/mlir/GettingStarted.md Outdated
Copy link
Copy Markdown
Member

@burgholzer burgholzer left a comment

Choose a reason for hiding this comment

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

Thanks @MatthiasReumann for getting this started 😄
Great to see someone push this forward!

I now also gave this a thorough read.
I added some comments inline as well, but much more important than that, I would like to pick up on Damians points below.

That being said though: I believe there is still some room for discussion when it comes to who the target audience should be for this "Getting Started Guide":

Probably it shouldn't be quantum algorithm engineers who just want to compile their code. They don't care what happens in the background.
Then, one would assume it's compiler developers. But why would compiler developers care about the qc dialect (which the majority of this tutorial is about).
All in all, this brings me to the big question: Is it really the "correct" approach to give the getting started guide in terms of the QC dialect? People are never supposed to write MLIR code anyways - we will likely have some other front-end or DSL for that. So the only time when the code will use QC is during the translation process (and for the output, if the user does not compile down to QIR). The only advantage that QC has over QCO is that it is simpler, but it is weird to argue, for a tutorial "we won't explain the important thing because that is too complicated, so instead we explain the less important thing".

What are everyone else's thoughts on that?

Currently, the guide feels very compact. It touches on some topics, but mostly briefly, and for the most part probably not exhaustively.
I said in one of the comments that it is "nicht fisch, nicht fleisch", and I think this also is what Damian is highlighting above. At the moment the guide itself isn't sure who it is written for.

I think this could easily be split into three parts:

  • For the people knowing quantum that have never heard of MLIR; those should start with an MLIR section that explains the concepts; potentially referring back to concepts that people might know from SDKs like Qiskit or Pennylane, or from languages like OpenQASM. People knowing MLIR may skip this section.
  • For the people that know classical compilers (and MLIR), but that don't know quantum too well. Those should start at a section that step by step explains quantum concepts, but tries to refer back to classical compiler and MLIR terminology wherever suitable. People knowing quantum may skip this section.
  • For the people familiar with both (or that have read both previous sections). Those people, we should tell what exactly we are doing as part of the project here. This should explain the difference between the two dialects, the compilation flow, etc. This is the meat of the tutorial; the previous sections are kind of the background for the relevant crowd. Within this section, it may again be interesting to provide some anecdotes that people from one of the backgrounds would find helpful ("the program structure in QCO is very similar to DAG structures people may be familiar with from Qiskit" for example)

Overall, this should really have an educational character for people and leave as little up for imagination as possible (Damian already did a great job in the comments highlighting a couple of places where this might not yet be the case).

That's all I got for now. I hope this makes sense and helps to navigate this into the right direction. Despite the flood of comments, this is still a really great start! 🎉

Comment thread docs/_static/compilation-pipeline.svg Outdated
Comment thread docs/mlir/GettingStarted.md Outdated
Comment thread docs/mlir/GettingStarted.md Outdated
Comment thread docs/mlir/GettingStarted.md Outdated
Comment thread docs/mlir/GettingStarted.md Outdated
Comment thread docs/mlir/GettingStarted.md Outdated
Comment thread docs/mlir/GettingStarted.md Outdated
Comment thread docs/mlir/GettingStarted.md Outdated
Comment thread docs/mlir/GettingStarted.md Outdated
Comment thread docs/mlir/index.md Outdated
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (1)
docs/mlir/GettingStarted.md (1)

83-89: ⚠️ Potential issue | 🟠 Major

Fill in the core tutorial sections before merge.

The two key subsections are empty (The QC and QCO Dialects, Compilation Flow), so the guide currently misses the main learning path (QC vs QCO semantics and QC→QCO flow) promised by this PR and linked issue.

✍️ Minimal structure to add now
 ### The QC and QCO Dialects
+QC uses reference semantics and models qubits as references to allocated resources.
+QCO uses value semantics with linear types, where each qubit SSA value is consumed exactly once.
+Show one small side-by-side snippet (QC and QCO) for the same Bell-state step to make this concrete.

 ### Compilation Flow
+The typical flow is: OpenQASM -> QC -> QCO -> (optional) QIR.
+Add one command sequence with `mqt-cc` and briefly explain where optimizations happen.
+Include one short note about current limitations (e.g., unsupported patterns), if applicable.

Based on learnings from issue #1452 objectives, this guide is expected to explain QC vs QCO in detail and illustrate the QC → QCO transformation with a running example.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/mlir/GettingStarted.md` around lines 83 - 89, The two subsections "The
QC and QCO Dialects" and "Compilation Flow" in GettingStarted.md are empty; fill
them with content that (1) defines QC and QCO semantics (key differences,
example ops/constructs and when to use each) under the "The QC and QCO Dialects"
header and (2) describes the QC→QCO transformation pipeline with a small running
example showing input QC IR, the transformation steps (pass names or functions)
and resulting QCO IR under "Compilation Flow"; reference the section titles "The
QC and QCO Dialects" and "Compilation Flow" when adding content so the guide
explains QC vs QCO and demonstrates the QC→QCO flow end-to-end as requested by
the linked issue.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/mlir/GettingStarted.md`:
- Line 164: The "## Conclusion" heading in the GettingStarted.md document is
empty; either remove the heading or add a brief concluding paragraph summarizing
the guide. Locate the heading text "## Conclusion" and either delete that line
(and any trailing blank lines) or append 2–4 sentences that wrap up the
document’s key takeaways and next steps so the section is not left blank.
- Around line 30-33: Fix the wording in the MLIR intro: change "The core concept
in MLIR are _dialects_" to "The core concepts in MLIR are _dialects_"; change
"floating point" to "floating-point" (e.g., "integer and floating-point
operations"); and replace "which let's us define and call functions" with "which
lets us define and call functions" (remove the apostrophe). Keep references to
SCF, arith, and Func dialects intact.

---

Duplicate comments:
In `@docs/mlir/GettingStarted.md`:
- Around line 83-89: The two subsections "The QC and QCO Dialects" and
"Compilation Flow" in GettingStarted.md are empty; fill them with content that
(1) defines QC and QCO semantics (key differences, example ops/constructs and
when to use each) under the "The QC and QCO Dialects" header and (2) describes
the QC→QCO transformation pipeline with a small running example showing input QC
IR, the transformation steps (pass names or functions) and resulting QCO IR
under "Compilation Flow"; reference the section titles "The QC and QCO Dialects"
and "Compilation Flow" when adding content so the guide explains QC vs QCO and
demonstrates the QC→QCO flow end-to-end as requested by the linked issue.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 5455081e-a4a9-4d40-a96e-60c3468ccfde

📥 Commits

Reviewing files that changed from the base of the PR and between 7bb1caa and 4853bf9.

⛔ Files ignored due to path filters (1)
  • docs/_static/mlir-regions-blocks-ops.svg is excluded by !**/*.svg
📒 Files selected for processing (2)
  • docs/mlir/GettingStarted.md
  • docs/mlir/index.md

Comment thread docs/mlir/GettingStarted.md Outdated
@MatthiasReumann MatthiasReumann marked this pull request as ready for review May 13, 2026 14:09
@mergify mergify Bot added the conflict label May 18, 2026
@mergify mergify Bot removed the conflict label May 21, 2026
Copy link
Copy Markdown
Member

@denialhaag denialhaag left a comment

Choose a reason for hiding this comment

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

Thanks a lot for continued work on this, @MatthiasReumann! 🙂

I have finally gotten around to reading the page again. I personally like how this reads now!

I have left a comment whenever I stumbled while reading. Most of the comments should be very straightforward to address (or reject!).

Comment thread docs/mlir/GettingStarted.md Outdated
Comment thread docs/mlir/GettingStarted.md Outdated
Comment thread docs/mlir/GettingStarted.md Outdated
Comment thread docs/mlir/GettingStarted.md Outdated
Comment thread docs/mlir/GettingStarted.md Outdated
Comment thread docs/mlir/GettingStarted.md Outdated
Comment thread docs/mlir/GettingStarted.md Outdated
Comment thread docs/mlir/GettingStarted.md Outdated
Comment thread docs/mlir/GettingStarted.md Outdated
Comment on lines +1021 to +1023
rewriter.replaceAllUsesWith(
/*from= */nextOp.getOutputQubit(0),
/*to= */op.getInputQubit(0));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't know if this is more instructive (even though it might be less efficient). 🤔

Suggested change
rewriter.replaceAllUsesWith(
/*from= */nextOp.getOutputQubit(0),
/*to= */op.getInputQubit(0));
rewriter.replaceOp(op, op.getInputQubit(0));
rewriter.replaceOp(nextOp, nextOp.getInputQubit(0));

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I don't know which one is more pedantic. I will let @DRovara be the judge.

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.

I don't know if this is more instructive (even though it might be less efficient). 🤔

I'm not entirely convinced if this is more instructive. The reader basically has to understand what it means to replace an operation with its input - which is basically a short-hand way of saying we replace its output with its input and then delete it.

I feel like the original format makes this a bit clearer (although I'm afraid it will never be entirely obvious to a reader without background knowledge)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fair points!

I actually ran into a problem with the current implementation in #1751. I'll come back here once I know more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm already back! The implementation should reflect whatever we decide on in #1762.

@mergify mergify Bot added the conflict label Jun 2, 2026
Comment thread CHANGELOG.md
Comment on lines +14 to 17
- 📝 Add _Getting Started With MLIR_ guide ([#1555]) ([**@MatthiasReumann**])
- 🚸 Add a measurement instruction to the default SC QDMI device ([#1694]) ([**@burgholzer**])
- ✨ Add support for multi-controlled gates to the QDMI Qiskit backend converter ([#1694]) ([**@burgholzer**])
- ✨ Add a `hadamard-lifting` pass for lifting Hadamard gates above Pauli gates ([#1605]) ([**@lirem101**], [**@burgholzer**])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks like something went wrong during a rebase here. 🤔

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

That is odd, yes.

MatthiasReumann and others added 3 commits June 3, 2026 09:12
Co-authored-by: Daniel Haag <121057143+denialhaag@users.noreply.github.com>
Signed-off-by: matthias <matthias@bereumann.com>
@mergify mergify Bot removed the conflict label Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation MLIR Anything related to MLIR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

📝 MLIR - Getting Started Guide

5 participants