QAMP - Expose IQP circuit generator via C bindings
Title: Expose IQP circuit generator via C bindings
Summary
This PR exposes the IQP circuit generator from qiskit-circuit-library through the C API and adds C tests for the new entry points.
Changes
-
crates/circuit_library/src/iqp.rs- Make the internal helper
public so it can be reused by other crates without duplicating the instruction construction logic.pub fn iqp(interactions: ArrayView2<'_, i64>) -> impl Iterator<...>
- Make the internal helper
-
crates/cext/src/circuit_library/iqp.rs- Add
QkCircuit *qk_circuit_library_iqp_(uint32_t num_qubits, const int64_t *interactions);- Interprets
interactionsas ann × nrow-majorint64_tmatrix. - Checks for
NULLpointer,num_qubits > 0, and enforces symmetry on the upper triangle. - Wraps the buffer in an
ArrayView2and buildsCircuitDatausing the sharediqphelper. - Returns
NULLfor invalid input (null pointer, zero qubits, or non-symmetric matrix).
- Interprets
- Add
QkCircuit *qk_circuit_library_random_iqp_(uint32_t num_qubits, int64_t seed);- Wraps
py_random_iqp(num_qubits, Option<u64>)to generate a random IQP circuit. - Uses a negative
seedto indicate “draw from OS entropy”, mirroring existing C bindings.
- Wraps
- Add
-
test/c/test_iqp.c- Add C-level tests for the new bindings:
- Build an IQP circuit from a small symmetric interaction matrix and check:
- total instruction count,
- that all gates are 1- or 2-qubit,
- that exactly one 2-qubit gate appears for the chosen matrix.
- Verify that a non-symmetric interaction matrix causes
qk_circuit_library_iqp_to returnNULL. - Generate a random IQP circuit and assert it is non-empty and contains only 1- and 2-qubit gates.
- Build an IQP circuit from a small symmetric interaction matrix and check:
- Add C-level tests for the new bindings:
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
Pull Request Test Coverage Report for Build 20303461709
Details
- 30 of 36 (83.33%) changed or added relevant lines in 2 files are covered.
- 8 unchanged lines in 3 files lost coverage.
- Overall coverage increased (+0.005%) to 88.302%
| Changes Missing Coverage | Covered Lines | Changed/Added Lines | % |
|---|---|---|---|
| crates/cext/src/circuit_library/iqp.rs | 28 | 34 | 82.35% |
| <!-- | Total: | 30 | 36 |
| Files with Coverage Reduction | New Missed Lines | % |
|---|---|---|
| crates/circuit/src/parameter/parameter_expression.rs | 1 | 82.3% |
| crates/qasm2/src/lex.rs | 1 | 93.57% |
| crates/qasm2/src/parse.rs | 6 | 97.56% |
| <!-- | Total: | 8 |
| Totals | |
|---|---|
| Change from base Build 20225348384: | 0.005% |
| Covered Lines: | 96666 |
| Relevant Lines: | 109472 |
💛 - Coveralls
Thanks for opening the PR, Ameya! Just FYI, you don't need to add a detailed changelog like that usually. It's nice to summarize the PR if it is a complicated change, but here it would've been fine without (or much shorter) 🙂
Great, thanks for the updates! This now only needs a release note and we're good to go 🙂