Skip to content

Conversation

@Estebanrg21
Copy link

@Estebanrg21 Estebanrg21 commented Dec 17, 2025

Summary

This pull request implements the Suzuki-Trotter evolution within the C API.

Details and comments

1. New APIs:

  • The file with the implementation for the Suzuki-Trotter evolution at crates/circuit_library/src/suzuki_trotter.rs
  • The file with the implementation for the Suzuki-Trotter evolution at crates/synthesis/src/evolution/suzuki_trotter.rs
  • The file with the exposure of the Suzuki-Trotter evolution for the C API at crates/cext/src/synthesis/suzuki_trotter.rs

2. As part of the implementation, some APIs were made public:

  • modulesynthesis/evolution
  • Instruction struct from crates/circuit_library/src/pauli_evolution.rs
  • module crates/circuit_library/src/pauli_evolution.rs

3. The qiskit-synthesis and qiskit-quantum-info crates were added as dependencies for qiskit-circuit-library

@qiskit-bot qiskit-bot added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Dec 17, 2025
@CLAassistant
Copy link

CLAassistant commented Dec 17, 2025

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Esteban Ramirez seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@Estebanrg21 Estebanrg21 force-pushed the qamp2025-29-esteban branch 7 times, most recently from f810558 to 2bac78e Compare December 17, 2025 07:57
@Cryoris Cryoris added this to the 2.4.0 milestone Dec 17, 2025
@Cryoris Cryoris added the Changelog: New Feature Include in the "Added" section of the changelog label Dec 17, 2025
Copy link
Collaborator

@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.

Thanks for the PR @Estebanrg21, this already looks pretty good! I think we can improve the datastructures a bit and avoid some clones and collections.

This would also need a release note 🙂

}

pub fn reorder_terms<'a>(terms: &'a Vec<StrSparseTerm<'a>>) -> Vec<StrSparseTerm<'a>> {
let sorted: Vec<&StrSparseTerm> = terms
Copy link
Collaborator

Choose a reason for hiding this comment

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

You don't have to collect this into a vec if you're just iterating over it later, i.e, we can do

let mut graph = ..
for term in terms.iter().sorted_by_key(..) {
  graph.add_node(term);
}

Copy link
Author

@Estebanrg21 Estebanrg21 Dec 24, 2025

Choose a reason for hiding this comment

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

I did some changes in ba99114. Here this iteration cannot be done just once because sorted is used in other parts of the code. Should I still refactor it?

.sorted_by_key(|view| (view.indices, view.terms.clone()))
.collect();

let mut graph: Graph<&StrSparseTerm, Option<u8>, Undirected> = Graph::new_undirected();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a way to tell the graph what capacity we need, such that we can allocate the required memory only one?

Copy link
Author

Choose a reason for hiding this comment

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

On ba99114 I used the function like this:

Graph::with_capacity(sorted.len(), edges.len())

Would that be enough?

};
}

pub fn reorder_terms<'a>(terms: &'a Vec<StrSparseTerm<'a>>) -> Vec<StrSparseTerm<'a>> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This function does a lot of collecting and cloning, that we should try to avoid. We could change e.g. to return the indices in which the terms should be applied instead of cloning and collecting into a new container.

Copy link
Author

@Estebanrg21 Estebanrg21 Dec 24, 2025

Choose a reason for hiding this comment

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

I refactored the code in ba99114 to only have the collection of terms in the sorted variable. I believe now it's avoided most of the collecting and cloning present before. What do you think?

@Cryoris Cryoris self-assigned this Dec 19, 2025
@Estebanrg21 Estebanrg21 force-pushed the qamp2025-29-esteban branch 4 times, most recently from 440e955 to ab28872 Compare December 23, 2025 04:30
@Cryoris Cryoris changed the title [WIP] Add Suzuki-Trotter to C API Add Suzuki-Trotter to C API Dec 23, 2025
@Cryoris Cryoris marked this pull request as ready for review December 23, 2025 10:46
@Cryoris Cryoris requested a review from a team as a code owner December 23, 2025 10:46
@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

Pull Request Test Coverage Report for Build 20451425357

Details

  • 18 of 194 (9.28%) changed or added relevant lines in 3 files are covered.
  • 4 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.1%) to 88.191%

Changes Missing Coverage Covered Lines Changed/Added Lines %
crates/circuit_library/src/suzuki_trotter.rs 0 82 0.0%
crates/synthesis/src/evolution/suzuki_trotter.rs 0 94 0.0%
Files with Coverage Reduction New Missed Lines %
crates/circuit/src/parameter/parameter_expression.rs 1 82.3%
crates/qasm2/src/lex.rs 3 92.29%
Totals Coverage Status
Change from base Build 20366546417: -0.1%
Covered Lines: 96755
Relevant Lines: 109711

💛 - Coveralls

@Estebanrg21 Estebanrg21 force-pushed the qamp2025-29-esteban branch 3 times, most recently from beba845 to a792bbd Compare December 24, 2025 19:29
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: Ready

Development

Successfully merging this pull request may close these issues.

5 participants