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.28k stars 2.37k forks source link

Functionality to list operations in QuantumCircuit with associated Qubits #13055

Open tonmoy-b opened 2 months ago

tonmoy-b commented 2 months ago

fixes #12972

Summary

Added function to tally operations in circuit with associated qubits fixes #12972

Details and comments

-Added function count_ops_with_qubits() in quantumcircuit.py, this returns the operations in the QuantumCircuit along with the qubits associated with those operations. -The abovementioned function uses the Rust function fn operations_with_qubits in circuit_data.rs -A test (test_count_ops_with_qubits()) has been added to file test/python/circuit/test_circuit_data.py -tox has been run -- no test failures reported -tox -eblack run to reformat files

[Yes ] I have added the tests to cover my changes. [Yes ] I have updated the documentation accordingly. [Yes ] I have read the CONTRIBUTING document.

qiskit-bot commented 2 months 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:

tonmoy-b commented 2 months ago

Hi @mtreinish ,

 I have made this PR to fix issue 12972: Add a method to compute gate counts per qubit 

 Kindly take a look and let me know if any changes should be made.

 For a quick look, the new code works as below:
 a = QuantumCircuit(3, 3)
    a.h(0)
    a.x(1)
    a.h(1)
    a.cx(1, 0)
    b = a.count_ops_with_qubits()
    assert b == [
        ("h", "Qubit(QuantumRegister(3, 'q'), 0)"),
        ("x", "Qubit(QuantumRegister(3, 'q'), 1)"),
        ("h", "Qubit(QuantumRegister(3, 'q'), 1)"),
        ("cx", "Qubit(QuantumRegister(3, 'q'), 1)"),
        ("cx", "Qubit(QuantumRegister(3, 'q'), 0)"),
    ]
coveralls commented 2 months ago

Pull Request Test Coverage Report for Build 10612643610

Details


Files with Coverage Reduction New Missed Lines %
crates/accelerate/src/two_qubit_decompose.rs 1 90.82%
crates/qasm2/src/lex.rs 5 92.23%
crates/qasm2/src/parse.rs 12 97.15%
<!-- Total: 18 -->
Totals Coverage Status
Change from base Build 10598013395: 0.008%
Covered Lines: 71661
Relevant Lines: 80334

💛 - Coveralls
tonmoy-b commented 1 month ago

Hi @mtreinish ,

I have made the changes as recommended, kindly take a look.

Thanks and Regards, Tonmoy

tonmoy-b commented 1 month ago

Hi, I don't mean to be a nuisance but I would appreciate a review and suggestions for updates if needed. Thanks

tonmoy-b commented 3 weeks ago

Hi, I'd appreciate a review of this PR. I believe it is probably close to what's required at this point.