-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Add qk_circuit_unitary
#14334
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
Add qk_circuit_unitary
#14334
Conversation
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 15296975102Warning: 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
💛 - Coveralls |
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 doing this it's a great start! I left a few inline comments to start. The other thing which will be important here is to add some unit tests to make sure we exercise the new code path. You can add the tests to this file: https://github.com/Qiskit/qiskit/blob/main/test/c/test_circuit.c
crates/cext/src/circuit.rs
Outdated
@@ -378,6 +381,59 @@ pub struct OpCounts { | |||
len: usize, | |||
} | |||
|
|||
/// @ingroup QkCircuit | |||
/// Append an arbitrary unitary matrix to the circuit. | |||
/// The user passes a row-major array of interleaved real-imaginary pairs #[ |
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.
Were you going to link to something here?
crates/cext/src/circuit.rs
Outdated
let raw = unsafe { std::slice::from_raw_parts(matrix, dim * dim * 2) }; | ||
let data: Vec<Complex64> = raw | ||
.chunks_exact(2) | ||
.map(|x| Complex64::new(x[0], x[1])) | ||
.collect(); | ||
|
||
// Build ndarray::Array2 | ||
let mat = Array2::from_shape_vec((dim, dim), data).expect("Invalid shape for unitary matrix"); |
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 wonder if using ArrayView::from_shape_ptr()
here to create a view of the C array and then doing to_owned()
to create a copy of it would be better. I guess the advantage of doing the ArrayView
path is that it lets you control the striding too and support various memory layouts. While doing it like this explicit memory layout for what we store in Rust for the UnitaryGate
. TBH, I'm fine either way as long as we document it, but I wanted to raise it as a question to discuss at least.
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Could u help me writing test codes? |
Sure, we can help push this over the finish line 👍🏻 I had one other question; is there a reason you picked pairs of |
No, it can be removed and it would be better to replace it with QkComplex64.. |
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 LGTM now, just some small nits inline. I'll apply the suggestions and then approve this.
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 all the work on this!
This reverts commit 25a34b0.
This broke the C API tests but somehow made it through CI. We need teh CI fix, and to send the PR back to review. This reverts commit 25a34b0.
This broke the C API tests but somehow made it through CI. We need teh CI fix, and to send the PR back to review. This reverts commit 25a34b0.
@maximizemaxwell: I had to temporarily revert this PR because it was incompatible with #14340 that happened to merge right before it, and our CI didn't stop it from merging to main. It wasn't your fault - you couldn't possibly have known (it wasn't even on Would you like to open a new PR from the same branch, and finalise the fixes that are needed to make it compatible? |
We originally merged this C API function in Qiskit#14334 but it had to be reverted in Qiskit#14492 because the C API tests conflicted with Qiskit#14340 and failed the tests. It was only able to merge because of a brief configuration issue with CI. This commit reapplies the originally PR and fixes the test conflict. This reverts commit 49874c6.
Sure I'll check and finish soooon |
|
Has this issue been resolved? |
You have to open a new PR and update the branch from |
We originally merged this C API function in Qiskit#14334 but it had to be reverted in Qiskit#14492 because the C API tests conflicted with Qiskit#14340 and failed the tests. It was only able to merge because of a brief configuration issue with CI. This commit reapplies the originally PR and fixes the test conflict. This reverts commit 49874c6.
* Reapply "Add ``qk_circuit_unitary`` (#14334)" (#14492) We originally merged this C API function in #14334 but it had to be reverted in #14492 because the C API tests conflicted with #14340 and failed the tests. It was only able to merge because of a brief configuration issue with CI. This commit reapplies the originally PR and fixes the test conflict. This reverts commit 49874c6. * Add tests for different sized matrices
* add initial qk_circuit_unitary * add dependencies * add dependencies in Cargo.toml * changed circuit pushing logic * fixed unsafe pointer * fixed compile error * Update circuit.rs Co-authored-by: Matthew Treinish <mtreinish@kortar.org> * Update circuit.rs Co-authored-by: Matthew Treinish <mtreinish@kortar.org> * Update crates/cext/src/circuit.rs Co-authored-by: Matthew Treinish <mtreinish@kortar.org> * initial version of test code * changed order, patterns * replaced double to QkComplex64 * accomodate windows and ubuntu nits * clippppppppppy * add check_input * Use nalgebra for 1/2q cases * fix docs * changed to iter * fixed docs * Apply suggestions from code review * Fix missing /// in docstring --------- Co-authored-by: Matthew Treinish <mtreinish@kortar.org> Co-authored-by: Julien Gacon <jules.gacon@googlemail.com>
This broke the C API tests but somehow made it through CI. We need teh CI fix, and to send the PR back to review. This reverts commit 25a34b0.
…iskit#14509) * Reapply "Add ``qk_circuit_unitary`` (Qiskit#14334)" (Qiskit#14492) We originally merged this C API function in Qiskit#14334 but it had to be reverted in Qiskit#14492 because the C API tests conflicted with Qiskit#14340 and failed the tests. It was only able to merge because of a brief configuration issue with CI. This commit reapplies the originally PR and fixes the test conflict. This reverts commit 49874c6. * Add tests for different sized matrices
Add C API for unitary gate
Part of issue 14238
#14238
What does this PR do?
Add new function of unitary gate in crates/cext/src/circuit.rs.
Who can review?
@mtreinish @eliarbel @Cryoris