Skip to content

Fix count_ops memory cleanup and expose QuantumCircuit.count_ops#33

Merged
garrison merged 7 commits intoQiskit:mainfrom
arnavk23:fix-issue-21-count-ops
Apr 26, 2026
Merged

Fix count_ops memory cleanup and expose QuantumCircuit.count_ops#33
garrison merged 7 commits intoQiskit:mainfrom
arnavk23:fix-issue-21-count-ops

Conversation

@arnavk23
Copy link
Copy Markdown
Contributor

Summary

This change fixes the qk_circuit_count_ops wrapper so it always releases the allocated QkOpCounts buffer returned by the C API, preventing a memory leak. It also exposes count_ops as a QuantumCircuit property for parity with the existing circuit API.

Changes

  • Updated c_circuit.jl to wrap qk_circuit_count_ops in a try/finally block and call qk_opcounts_clear after converting the result.
  • Added count_ops to QuantumCircuit property dispatch in circuit.jl.
  • Added tests in test_circuit.jl covering both qk_circuit_count_ops(qc) and qc.count_ops.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 15, 2026

CLA assistant check
All committers have signed the CLA.

@arnavk23
Copy link
Copy Markdown
Contributor Author

@garrison whenever you are free, please take a look. Thanks!

@coveralls
Copy link
Copy Markdown

coveralls commented Apr 19, 2026

Coverage Status

coverage: 72.956% (+0.5%) from 72.495% — arnavk23:fix-issue-21-count-ops into Qiskit:main

@arnavk23
Copy link
Copy Markdown
Contributor Author

@garrison all checks pass

Copy link
Copy Markdown
Member

@garrison garrison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for making this contribution 🚀

Comment thread src/circuit.jl Outdated
Comment thread src/c_circuit.jl
Comment thread src/circuit.jl
Comment thread test/test_circuit.jl Outdated
Comment thread src/circuit.jl
Comment thread src/circuit.jl Outdated
Co-authored-by: Jim Garrison <jim@garrison.cc>
Comment thread test/test_circuit.jl Outdated
Copy link
Copy Markdown
Member

@garrison garrison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, now the only thing left is getting coveralls CI to pass.

Comment thread src/circuit.jl Outdated
@garrison
Copy link
Copy Markdown
Member

Could you please try the following?

git fetch origin main:main
git merge main
git push

@garrison garrison merged commit 0e525c6 into Qiskit:main Apr 26, 2026
9 checks passed
@arnavk23 arnavk23 deleted the fix-issue-21-count-ops branch April 26, 2026 03:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants