Qiskit / qiskit

Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.
https://www.ibm.com/quantum/qiskit
Apache License 2.0
5.11k stars 2.34k forks source link

Port the count_ops method in QuantumCircuit to Rust #13050

Closed melechlapson closed 1 month ago

melechlapson commented 1 month ago

Summary

This PR is to address issue 12971 to port the count_ops method into Rust to improve performance.

Details and comments

I added a count_ops method to the CircuitData class in qiskit/crates/circuit/src/circuit_data.rs and updated the count_ops method in qiskit/circuit/quantumcircuit.py to call CircuitData's count_ops method.

coveralls commented 1 month ago

Pull Request Test Coverage Report for Build 10636776886

Details


Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 4 92.48%
crates/qasm2/src/parse.rs 12 97.15%
<!-- Total: 16 -->
Totals Coverage Status
Change from base Build 10636396685: -0.01%
Covered Lines: 71827
Relevant Lines: 80571

💛 - Coveralls
melechlapson commented 1 month ago

For a simple 2 qubit system in superposition, benchmarking shows ~3x improvement in performance on average. For a much larger, more complex circuit the improvement was ~9x.

Name (time in us)                                   Min                   Max                Mean              StdDev              Median                IQR            Outliers  OPS (Kops/s)            Rounds  Iterations
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_new_count_ops_benchmark                     3.4159 (1.0)         21.2500 (1.0)        3.6377 (1.0)        0.6866 (1.0)        3.6249 (1.0)       0.0421 (1.0)         4;187      274.9019 (1.0)        1000           1
test_old_count_ops_benchmark                    10.0830 (2.95)       150.8750 (7.10)      11.2112 (3.08)       6.2859 (9.16)      10.7500 (2.97)      0.4580 (10.87)        7;27       89.1962 (0.32)       1000           1
test_new_count_ops_benchmark_large_circuit      59.9581 (17.55)      147.6670 (6.95)      65.9430 (18.13)      7.9297 (11.55)     64.3330 (17.75)     3.7500 (88.98)       62;73       15.1646 (0.06)       1000           1
test_old_count_ops_benchmark_large_circuit     529.9998 (155.16)   5,656.8750 (266.21)   593.9564 (163.28)   317.4110 (462.32)   567.1044 (156.45)   29.7080 (704.94)       8;59        1.6836 (0.01)       1000           1
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
qiskit-bot commented 1 month ago

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: