Skip to content

SparseObservable evolution #13836

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

Merged
merged 11 commits into from
Mar 5, 2025
Merged

Conversation

Cryoris
Copy link
Contributor

@Cryoris Cryoris commented Feb 13, 2025

Summary

Add support for SparseObservable in PauliEvolution.

Details and comments

Evolution under projectors is implemented by controlling the target rotation with open controls (for +1 eigenstate projectors) or closed controls (for -1 eigenstate projectors). This is significantly more efficient than decomposing projectors into Paulis, shown here for the implementation of $exp(-i t Z \otimes |1\rangle\langle 1|^{\otimes n})$ for different numbers of projectors $n$.

image (1)

@Cryoris Cryoris added this to the 2.0.0 milestone Feb 13, 2025
@Cryoris Cryoris requested a review from a team as a code owner February 13, 2025 11:25
@qiskit-bot
Copy link
Collaborator

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

  • @Cryoris
  • @Qiskit/terra-core
  • @ajavadia

@1ucian0 1ucian0 linked an issue Feb 13, 2025 that may be closed by this pull request
Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

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

This is really cool, I've only skimmed the PR so far, but I had a couple small nits/comments.

Comment on lines 216 to 217
def _sparse_term_label(term):
return "".join(BIT_LABELS[bit] for bit in reversed(term.bit_terms))
Copy link
Member

Choose a reason for hiding this comment

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

I feel like we should do this in Rust as a pyfunction because it'd be faster and we could use the enum variants for BitTerm directly. Not that it really matters, but it feels more natural in rust.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking of adding a method to SparseTerm, maybe something like bit_labels() or so. But a standalone function would ofc also work

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a SparseTerm.bit_labels() method in 4881b5f that allows to get the labels Rust side. They're then ordered in the same fashion as SparseTerm.indices

Comment on lines 188 to 191
// .map(|(gate, params, qargs)| {
// (gate.into(), params, qargs.to_vec(), vec![] as Vec<Clbit>)
// })
// .collect::<Vec<Instruction>>();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// .map(|(gate, params, qargs)| {
// (gate.into(), params, qargs.to_vec(), vec![] as Vec<Clbit>)
// })
// .collect::<Vec<Instruction>>();

@mtreinish mtreinish added the Changelog: New Feature Include in the "Added" section of the changelog label Feb 13, 2025
@Cryoris Cryoris linked an issue Feb 18, 2025 that may be closed by this pull request
@coveralls
Copy link

coveralls commented Feb 24, 2025

Pull Request Test Coverage Report for Build 13659671616

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

  • 246 of 250 (98.4%) changed or added relevant lines in 6 files are covered.
  • 187 unchanged lines in 13 files lost coverage.
  • Overall coverage increased (+0.06%) to 87.12%

Changes Missing Coverage Covered Lines Changed/Added Lines %
crates/accelerate/src/circuit_library/pauli_evolution.rs 199 200 99.5%
crates/accelerate/src/sparse_observable/mod.rs 9 12 75.0%
Files with Coverage Reduction New Missed Lines %
crates/accelerate/src/circuit_library/pauli_evolution.rs 1 99.05%
crates/accelerate/src/unitary_synthesis.rs 1 94.39%
crates/circuit/src/operations.rs 1 90.03%
qiskit/synthesis/evolution/suzuki_trotter.py 1 90.2%
qiskit/transpiler/passes/synthesis/high_level_synthesis.py 2 96.81%
qiskit/transpiler/passes/synthesis/plugin.py 2 84.34%
crates/circuit/src/circuit_instruction.rs 4 90.16%
crates/qasm2/src/lex.rs 5 91.23%
crates/qasm2/src/parse.rs 6 96.22%
crates/circuit/src/dag_node.rs 9 74.55%
Totals Coverage Status
Change from base Build 13649569641: 0.06%
Covered Lines: 76554
Relevant Lines: 87872

💛 - Coveralls

Copy link
Member

@alexanderivrii alexanderivrii left a comment

Choose a reason for hiding this comment

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

This is a really cool PR indeed! I have left a few minor questions and comments.

Copy link
Member

@ShellyGarion ShellyGarion left a comment

Choose a reason for hiding this comment

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

LGTM. very nice improvement!
Perhaps you can add some more tests in the spirit of the graphs presented in the PR, showing that you get the same result, and providing some bounds on the CX cost or depth.
but anyway it's a great PR!

- more comments
- more tests
@alexanderivrii
Copy link
Member

LGTM on my side.

@ShellyGarion ShellyGarion added this pull request to the merge queue Mar 5, 2025
Merged via the queue into Qiskit:main with commit ab9e37a Mar 5, 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add SparseObservable support for PauliEvolutionGate Support SparseObservable in PauliEvolutionGate
6 participants