Track graph operation IDs in decomposition resource analysis - #3102
Track graph operation IDs in decomposition resource analysis#3102sengthai wants to merge 34 commits into
Conversation
Co-authored-by: David Ittah <dime10@users.noreply.github.com>
Co-authored-by: Hong-Sheng Zheng <mathan0203@gmail.com>
This reverts commit f11271a.
| collectOperation(&op, result, isAdjoint); | ||
| if (collectDetailedOperations) { | ||
| collectDetailOperation(&op, result, isAdjoint); | ||
| } |
There was a problem hiding this comment.
In ADR, we stated the mechanism that allow us to toggle between quantum_operation and quantum_operation_detailed, but in actual implementation, we still need to perform for quantum_operation by the way, because it needs to collect the function name for handling function call. Also, since buildResourceDict() serializes only detailOperations into MLIR attribute, we here just toggle only quantum_operation_detailed.
There was a problem hiding this comment.
If we needed to we could probably collect the function names using CollectDetailedOperation, but I think the current solution is fine, it shouldn't be much more expensive and saves us having 2 implementations.
jzaia18
left a comment
There was a problem hiding this comment.
Looks good so far, just a few comments
| collectOperation(&op, result, isAdjoint); | ||
| if (collectDetailedOperations) { | ||
| collectDetailOperation(&op, result, isAdjoint); | ||
| } |
There was a problem hiding this comment.
If we needed to we could probably collect the function names using CollectDetailedOperation, but I think the current solution is fine, it shouldn't be much more expensive and saves us having 2 implementations.
| * @return DictionaryAttr representing the resource counts | ||
| * | ||
| */ | ||
| DictionaryAttr buildResourceDict(MLIRContext *ctx, const ResourceResult &result) { |
There was a problem hiding this comment.
Doesn't this method only work if we collect detailed operations now? What if the user didn't select this setting?
There was a problem hiding this comment.
If the user didn't enable collectDetailedOperaitons here.
then, this return empty operations.
There was a problem hiding this comment.
But that's a bug, isn't it? If we leave collectDetailedOperations as false then the output JSON will be completely missing all operations data
There was a problem hiding this comment.
i can see that. Being empty when collectDetailedOperations is false seems incorrect interpretation. Okay, i will add an assert if in that function then.
There was a problem hiding this comment.
This seems like we're replacing the existing unit tests with ones that check the detailed ops. I think we should instead add new unit tests -- we still want to test that the old pathway works as well
There was a problem hiding this comment.
what the old pathway you mention here? We actually replace the existing detailed ops fetching, completely.
| // Rule with measure | ||
|
|
||
| // CHECK: resources = {measurements = {}, num_alloc_qubits = 1 : i64, num_arg_qubits = 0 : i64, num_qubits = 1 : i64, operations = {"Hadamard(1,0)" = 1 : i64, "MidCircuitMeasure(1,0)" = 1 : i64}}, target_gate = "gate" | ||
| // CHECK: resources = {measurements = {}, num_alloc_qubits = 1 : i64, num_arg_qubits = 0 : i64, num_qubits = 1 : i64, operations = {"Hadamard[][1]{}" = 1 : i64}}, target_gate = "gate" |
There was a problem hiding this comment.
Why do we no longer expect the MCM to show?
Co-authored-by: Jake Zaia <23638795+jzaia18@users.noreply.github.com>
Fix missing adjoint in detailedOperaiton
| std::string opId = inst.getGraphOpId(); | ||
| if (auto resourceOp = dyn_cast<ResourceQuantumOpInterface>(op)) { | ||
| if (isAdjoint ^ resourceOp.getResourceAdjointFlag()) { | ||
| opId += "[adj]"; |
There was a problem hiding this comment.
Will this break anything for the actual decomposition graph IDs?
CC @kipawaa
There was a problem hiding this comment.
FYI, it should be like Rot[f64,f64,f64][2]{}[adj]
| } | ||
| } | ||
| result.detailedOperations[opId] += 1; | ||
| } |
There was a problem hiding this comment.
Don't forget to add an else-branch to catch cases when we don't have a graph operator ID
There was a problem hiding this comment.
I added another if-branch for handling the ResourceAnlaysis op type. 0a277f1
I'm sure how we handle unknown quantum ops here. So, i would leave that alone for unknown op as it can be classical ops as well.
Context:
Previously,
ResourceAnalysisgrouped quantum operations using only their name, wire(qubit) count, and parameter count, producing identifiers. Meanwhile graph-decompositions usesgraphOpId, which also captures parameter types, wire structure, static data, and operator UIDs (some of these are part of Operator2).This PR aligns resource generation with
graphOpIdby adding an optional detailed operation count used specifically by decomposition passes.To use that, developer can toggle
collectDetailedOperationwhen construct the analysis.[sc-125008]