Skip to content
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

Light Cone Transpiler Pass #12814

Merged
merged 34 commits into from
Mar 4, 2025
Merged

Light Cone Transpiler Pass #12814

merged 34 commits into from
Mar 4, 2025

Conversation

MarcDrudis
Copy link
Contributor

@MarcDrudis MarcDrudis commented Jul 25, 2024

Summary

When measuring or sampling a subset of the qubits of our circuit there will be some gates in our circuit that will not affect the outcome of the measurement. One can thus compute the causal light cone of the circuit and measurement, i.e. the set of gates that does affect the measurement. This transpiler pass provides an easy tool to reduce the number of gates in our circuit provided a Pauli observable to be measured or a subset of measurements in the Z basis.
This PR adresses #12792

Details and comments

This code takes inspiration from an implementation done by @aeddins-ibm.
Before finishing the unit-tests for this PR it would be interesting to solve #12790 .

@MarcDrudis MarcDrudis requested a review from a team as a code owner July 25, 2024 13:29
@qiskit-bot qiskit-bot added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Jul 25, 2024
@qiskit-bot
Copy link
Collaborator

Thank you for opening a new pull request.

Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient.

While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone.

One or more of the following people are relevant to this code:

  • @Qiskit/terra-core

@coveralls
Copy link

coveralls commented Jul 25, 2024

Pull Request Test Coverage Report for Build 13636110765

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 78 of 80 (97.5%) changed or added relevant lines in 2 files are covered.
  • 5 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.03%) to 87.235%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/transpiler/passes/optimization/light_cone.py 58 60 96.67%
Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 5 91.98%
Totals Coverage Status
Change from base Build 13635545005: 0.03%
Covered Lines: 75616
Relevant Lines: 86681

💛 - Coveralls

@Cryoris Cryoris marked this pull request as draft July 25, 2024 14:00
Copy link
Contributor

@Cryoris Cryoris left a comment

Choose a reason for hiding this comment

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

Looks like a good start! Here's some initial comments 🙂

of qubits.
"""

def __init__(self, observable: Pauli | None = None):
Copy link
Contributor

Choose a reason for hiding this comment

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

This also takes a list of Paulis, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now only one Pauli. We could easily adapt it to a list of Paulis if we think that would make more sense.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm asking because in your code the default path for observable=None seems to use a list of Paulis already 🙂

Copy link
Contributor

Choose a reason for hiding this comment

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

A list of Pauli terms would, in general, lead to a collection of different circuits as each Pauli term may have its own independent causal structure. A one circuit in, many circuits out, is not currently supported in the transpiler interface. But perhaps should be as it is useful for twirling as well

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I meant that in this case the gates would have to commute with each of the Paulis in the list (how the measurements are treated as list of single-Z Paulis in the code right now). That would e.g. allow to decompose a larger observable into smaller (e.g. ZZZ... into Z0, Z1, ...) -- this would give a larger light cone since now things might not commute which would in the bigger observable, but it would make the commutation check faster (which I think would use a matrix multiplication check for non-standard gates).

But that's probably not required for the beginning and we could just issue a warning if the commutation check becomes problematic 🙂

@Cryoris Cryoris added the Changelog: New Feature Include in the "Added" section of the changelog label Jul 26, 2024

commutes_bool = True
for op in light_cone_ops:
commute_bool = commutator.commute(op[0], op[1], [], node.op, node.qargs, [])
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 handle the max_num_qubits arg, which currently defaults to 3. E.g. if a user would give a PauliGate("ZZZZ") I think the code would just forego the commutation check and return False for any commutation.

So we should probably set max_num_qubits=max(len(op[1]), len(node.qargs)) and add a warning if that number becomes too big.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. This is actually a very good point. I am working on fixing it right now , but it creates a bug for some reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This leads to a bug. I have created a unitest and opened an issue #13828 . Once this issue is solved, the test can be enabled and everything else should work well.

Light cone polishing, warnings and tests
@CLAassistant
Copy link

CLAassistant commented Dec 16, 2024

CLA assistant check
All committers have signed the CLA.

@Cryoris Cryoris added this to the 2.0.0 milestone Jan 22, 2025
@MarcDrudis
Copy link
Contributor Author

I created a test that creates the lightcone of a large Pauli string and it is not passing. This is linked to #13828. How should we proceed? Do we wait until the issue is fixed for merging this PR, or should we just throw a warning for now if the Pauli string gets too big?

@Cryoris
Copy link
Contributor

Cryoris commented Feb 18, 2025

You could comment out the test case saying that it requires #13828 to be fixed, but I wouldn't add a custom warning, since that's extra cleanup work once the bug has been fixed. The expected behavior is for this to work 🙂

@MarcDrudis MarcDrudis marked this pull request as ready for review February 19, 2025 08:35
@qiskit-bot
Copy link
Collaborator

Thank you for opening a new pull request.

Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient.

While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone.

One or more of the following people are relevant to this code:

  • @Qiskit/terra-core

Copy link
Contributor

@Cryoris Cryoris left a comment

Choose a reason for hiding this comment

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

Overall this LGTM, I left some comments below 🙂

Copy link
Contributor

@Cryoris Cryoris left a comment

Choose a reason for hiding this comment

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

Some tiny comments, then I think this is good to go!

Copy link
Contributor

@Cryoris Cryoris left a comment

Choose a reason for hiding this comment

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

LGTM thanks for all the work @MarcDrudis and @spiccinelli!

@Cryoris Cryoris added this pull request to the merge queue Mar 4, 2025
Merged via the queue into Qiskit:main with commit 47e8c98 Mar 4, 2025
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: New Feature Include in the "Added" section of the changelog Community PR PRs from contributors that are not 'members' of the Qiskit repo
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

8 participants