-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Add Suzuki-Trotter to C API #15459
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
base: main
Are you sure you want to change the base?
Add Suzuki-Trotter to C API #15459
Conversation
|
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. |
f810558 to
2bac78e
Compare
2bac78e to
35783dd
Compare
Cryoris
left a comment
There was a problem hiding this 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 |
There was a problem hiding this comment.
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);
}There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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>> { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
440e955 to
ab28872
Compare
|
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:
|
Pull Request Test Coverage Report for Build 20451425357Details
💛 - Coveralls |
beba845 to
a792bbd
Compare
ba99114 to
5457218
Compare
Summary
This pull request implements the Suzuki-Trotter evolution within the C API.
Details and comments
1. New APIs:
crates/circuit_library/src/suzuki_trotter.rscrates/synthesis/src/evolution/suzuki_trotter.rscrates/cext/src/synthesis/suzuki_trotter.rs2. As part of the implementation, some APIs were made public:
synthesis/evolutionInstructionstruct fromcrates/circuit_library/src/pauli_evolution.rscrates/circuit_library/src/pauli_evolution.rs3. The
qiskit-synthesisandqiskit-quantum-infocrates were added as dependencies forqiskit-circuit-library