qiskit icon indicating copy to clipboard operation
qiskit copied to clipboard

QAMP - Expose IQP circuit generator via C bindings

Open Ameya28Bhave opened this issue 1 month ago • 3 comments

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
      pub fn iqp(interactions: ArrayView2<'_, i64>) -> impl Iterator<...>
      
      public so it can be reused by other crates without duplicating the instruction construction logic.
  • crates/cext/src/circuit_library/iqp.rs

    • Add
      QkCircuit *qk_circuit_library_iqp_(uint32_t num_qubits, const int64_t *interactions);
      
      • Interprets interactions as an n × n row-major int64_t matrix.
      • Checks for NULL pointer, num_qubits > 0, and enforces symmetry on the upper triangle.
      • Wraps the buffer in an ArrayView2 and builds CircuitData using the shared iqp helper.
      • Returns NULL for invalid input (null pointer, zero qubits, or non-symmetric matrix).
    • 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 seed to indicate “draw from OS entropy”, mirroring existing C bindings.
  • 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 return NULL.
      • Generate a random IQP circuit and assert it is non-empty and contains only 1- and 2-qubit gates.

Ameya28Bhave avatar Nov 29 '25 18:11 Ameya28Bhave

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

qiskit-bot avatar Nov 29 '25 18:11 qiskit-bot

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 Coverage Status
Change from base Build 20225348384: 0.005%
Covered Lines: 96666
Relevant Lines: 109472

💛 - Coveralls

coveralls avatar Nov 29 '25 19:11 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) 🙂

Cryoris avatar Nov 30 '25 21:11 Cryoris

Great, thanks for the updates! This now only needs a release note and we're good to go 🙂

Cryoris avatar Dec 16 '25 08:12 Cryoris