Skip to content

Conversation

rniczh
Copy link
Contributor

@rniczh rniczh commented Sep 30, 2025

Context:

Description of the Change:
Added traversal logic of mcm. For an example, finding the qreg and index of qb3 in the following case, it needs to traverse the def-use chain through the ops.

qb0 = extract(...)
...
meas_result, qb2 = qml.measure(qb1, 0)
...
qb4 = op(qb3, ...) 

Refactoring

  1. Use QuantumGate to traverse the gates instead of CustomOp
  2. Collect qreg and qubit index with only one walk

Benefits:

Possible Drawbacks:

Related GitHub Issues:
[sc-100311]

@rniczh rniczh requested a review from maliasadi September 30, 2025 13:41
Copy link
Contributor

Hello. You may have forgotten to update the changelog!
Please edit doc/releases/changelog-dev.md on your branch with:

  • A one-to-two sentence description of the change. You may include a small working example for new features.
  • A link back to this PR.
  • Your name (or GitHub username) in the contributors section.

Copy link

codecov bot commented Sep 30, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.48%. Comparing base (12038b7) to head (9aa4697).
⚠️ Report is 7 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2068   +/-   ##
=======================================
  Coverage   97.48%   97.48%           
=======================================
  Files          91       91           
  Lines       10594    10594           
  Branches      990      990           
=======================================
  Hits        10328    10328           
  Misses        211      211           
  Partials       55       55           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rniczh rniczh requested a review from a team October 2, 2025 19:54
}
qubit = customOp.getQubitOperands()[0];
}
else if (auto measureOp = dyn_cast_or_null<quantum::MeasureOp>(qubit.getDefiningOp())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should use interfaces whenever we can, which might save you from having to add all these instructions one by one :) Unfortunately, measure doesn't seem to implement any of our interfaces, but the CustomOp above may be better served with the QuantumOperation or QuantumGate interface.

Although I'm a little confused why we just get the 0th qubit operand, are we guaranteed to only deal with single-qubit operations here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, why not get the index and register together in one walk, rather than in separate functions? 🤔

Copy link
Contributor Author

@rniczh rniczh Oct 3, 2025

Choose a reason for hiding this comment

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

Also, why not get the index and register together in one walk, rather than in separate functions?

Yes, I agreed, I updated this in another PR #2074, but it might take more time to handle that one, so I can move that change to this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Although I'm a little confused why we just get the 0th qubit operand, are we guaranteed to only deal with single-qubit operations here?

It's because this function here is used to get the source qreg, at the point, only one qreg, the global one exists. So traverse different qubit operands would still reach the same qreg. But now we have dynamic qreg! So this method will need to be changed and follow the solution from #2074

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dime10 Thanks for the suggestions, I changed to use the QuantumGate to traverse the gates instead of CustomOp and also use only one walk to collect the qreg and qubit index in the latest change.d01ef10

@rniczh rniczh changed the title Add support of MCM for decompose pass Add support of MCM for decompose pass and some refactoring Oct 3, 2025
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