-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dialects: Add qssa dialect #2746
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2746 +/- ##
==========================================
- Coverage 89.87% 89.78% -0.10%
==========================================
Files 367 370 +3
Lines 47442 47617 +175
Branches 7228 7299 +71
==========================================
+ Hits 42638 42751 +113
- Misses 3694 3730 +36
- Partials 1110 1136 +26 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice stuff! 🦄
Am I good to merge or should I ask for more reviews? |
Maybe @n-io can give a thumbs up as well? Otherwise I don't know who'd care about a General rule of thumb is that you want to be somewhat sure that anyone interested or invested had the chance to say okay or no. If nobody said anything, that's not enough. Sasha goes along the lines of one check is enough, I usually try to get two or more. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, some minor comments (somehow didn't click submit review, apologies)
xdsl/dialects/qssa.py
Outdated
class QubitAllocOp(QubitBase): | ||
name = "qssa.alloc" | ||
|
||
qubits = prop_def(IntegerAttr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
num
, count
, num_qubits
or similar might be better for inferring the type from a point of readability, since the definition qubit = QubitAttr()
would suggest that qubits : Sequence[QubitAttr]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, looking at this again, I don't think we need this attribute at all. The number of qubits is simply the number of results. So the attribute can be dropped entirely
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. I'd generally encourage to print some type information in the mlir, though.
|
||
qubits = prop_def(IntegerAttr) | ||
|
||
res: VarOpResult = var_result_def(qubit) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the semantics, this reads like it allocates a series of single qubits, rather than an array of qubits as the op is described in the paper. You could consider parameterising QubitAttr
similar to IntegerAttr
, or maybe @AntonLydike could advise?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I was saying is that these two ops are both completely valid, just one has redundant information:
@irdl_op_definition
class QubitAllocOp(QubitBase):
name = "qssa.alloc"
qubits = prop_def(IntegerAttr)
res: VarOpResult = var_result_def(qubit)
and
@irdl_op_definition
class QubitAllocOp(QubitBase):
name = "qssa.alloc"
res: VarOpResult = var_result_def(qubit)
Simply because we know that qbits == len(res)
. Therefore we don't need to carry this additional information at all. The resulting IR would look like this:
%qbit1, %qbit2 = qssa.alloc
%qbit3 = qssa.alloc
So you just specify how many qbits you allocate by the number of results.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For reference: 3.3.1 Allocation. qssa.alloc
allocates an array of qubits of fixed or variable length. %q = qssa.alloc : qubit<10>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think @alexarice does not talk about qbit arrays, but models each qbit as a single SSA value. But that's for him to answer 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I seem to remember that semantically, an array of qubits may be understood to mean something different as compared to n single qubits, but I may be mistaken here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not directly based on the qssa dialect from the paper and is currently representing each individual qubit as a separate ssa value. I'd be open to renaming this dialect if this will cause confusion in the future
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rest of the discussion didn't load for me on github, but I believe dropping the parameter is not ideal as the parser does not have access to the number of results (at least from my testing)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestions on how to avoid storing the number of qubits explicitly, while still printing and parsing the number as before.
Is there a reason this is desirable? It feels strange to me to have a disconnect between the printed data and the data stored on the operation |
I would recommend to not print the count at all. Just rely on people being able to count the number of results? |
I generally agree, I think printing derived (redundant) data is not the best idea... I'd just not print the count at all |
you then can't parse the operation though |
I think you should be able to. I'll come over |
--------- Co-authored-by: Alex Rice <alexrice999@hotmail.co.uk>
@alexarice and I looked into the parser internals and spoke with Markus on how MLIR handles it, and sadly we have to print redundant information here (the number of results), as MLIR allows one to write |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good :)
Add a simple quantum ssa dialect and a simple roundtrip filecheck test. Thought it would be better to split the work I was doing into multiple pull requests to make it easier to review so this doesn't have any rewrites yet