-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Add initial C API for circuit construction #14006
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
Conversation
One or more of the following people are relevant to this code:
|
d3d226a
to
590e7a8
Compare
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 looks really cool! I left some comments below 🙂
2e02dc1
to
bbde5e5
Compare
Pull Request Test Coverage Report for Build 14519935511Details
💛 - Coveralls |
Building off the infrastructure for the sparse observable added in PR Qiskit#13445 this commit adds a C FFI for building Quantum Circuits. Right now there is a function to create an empty circuit with n qubits and m clbits and then a function to add standard gates to a circuit and then also get the op counts out of a circuit. This is a start of the functionality for a C API around interacting with circuits, later PRs will expand this so we can have a more fully featured C API in the future. Part of Qiskit#13276
Co-authored-by: Julien Gacon <gaconju@gmail.com>
This also updates the test logic to make sure we always free even in case of a failure.
3e62ec6
to
669695a
Compare
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 didn't actually review the implementations, I just joined in with the bikeshedding.
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.
LGTM! (except for the minor dates detail)
QkCircuit *qc = qk_circuit_new(1000, 1000); | ||
uint32_t num_qubits = qk_circuit_num_qubits(qc); | ||
uint32_t num_clbits = qk_circuit_num_clbits(qc); | ||
size_t num_instructions = qk_circuit_num_instructions(qc); | ||
qk_circuit_free(qc); | ||
|
||
return (num_qubits != 1000 || num_clbits != 1000 || num_instructions != 0) ? EqualityError : Ok; | ||
if (num_qubits != 1000) { | ||
printf("The number of qubits %d is not 1000", num_qubits); |
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.
It would be nice to standardize this in the future. I'm wondering if this is printed somehow in order with CTest's output or if it is shown at another point and the origin is hard to pin down.
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.
IIRC, I used print debugging for developing the tests in the first place and ctest put the output somewhere I could find. But if we need to make improvements here we can definitely do it in a follow up.
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.
Two small comments (that can be skipped) -- LGTM!
The C api's build.rs was generating a config file that pointed to where the Python that pyo3 links against was located. This was previously used by the c test's cmake file to add to the search path on windows to enable the windows ctest runner to find the python lib it needs to load to run the tests. However, in practice this wasn't pointing to the correct location to point windows at libpython and PR Qiskit#14006 stopped using this file when it updated the path set to be found using cmake's FindPython module. This commit is just a follow up to remove this part of the build.rs as it's not longer actively used for anything.
The C api's build.rs was generating a config file that pointed to where the Python that pyo3 links against was located. This was previously used by the c test's cmake file to add to the search path on windows to enable the windows ctest runner to find the python lib it needs to load to run the tests. However, in practice this wasn't pointing to the correct location to point windows at libpython and PR #14006 stopped using this file when it updated the path set to be found using cmake's FindPython module. This commit is just a follow up to remove this part of the build.rs as it's not longer actively used for anything.
This commit adds some more details to the C API docs for the new QkCircuit struct which was added in Qiskit#14006.
* Improve QkCircuit C API docs This commit adds some more details to the C API docs for the new QkCircuit struct which was added in #14006. * Apply suggestions from code review Co-authored-by: Julien Gacon <gaconju@gmail.com> * Update docs/cdoc/qk-circuit.rst Co-authored-by: Julien Gacon <gaconju@gmail.com> * Add members option to doxygen group * Split out data structs in docs * Expand on current limitations of API in docs * Other docstring fixes * C docs don't have cross refs --------- Co-authored-by: Julien Gacon <gaconju@gmail.com>
* Improve QkCircuit C API docs This commit adds some more details to the C API docs for the new QkCircuit struct which was added in Qiskit#14006. * Apply suggestions from code review Co-authored-by: Julien Gacon <gaconju@gmail.com> * Update docs/cdoc/qk-circuit.rst Co-authored-by: Julien Gacon <gaconju@gmail.com> * Add members option to doxygen group * Split out data structs in docs * Expand on current limitations of API in docs * Other docstring fixes * C docs don't have cross refs --------- Co-authored-by: Julien Gacon <gaconju@gmail.com>
Summary
Building off the infrastructure for the sparse observable added in
PR #13445 this commit adds a C FFI for building Quantum Circuits. Right
now there is a function to create an empty circuit with n qubits and m
clbits and then a function to add standard gates to a circuit and then
also get the op counts out of a circuit. This is a start of the
functionality for a C API around interacting with circuits, later PRs
will expand this so we can have a more fully featured C API in the
future.
Details and comments
Part of #13276
This PR is based on top of #13986 and will need to rebased after that merges. To see the contents of just this PR you can look at: mtreinish/qiskit-core@no-py-token-constructor-path...mtreinish:qiskit-core:c-api-circuit-rebasedTODO: