qiskit icon indicating copy to clipboard operation
qiskit copied to clipboard

Functionality to list operations in QuantumCircuit with associated Qubits

Open tonmoy-b opened this issue 1 year ago • 5 comments

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.

tonmoy-b avatar Aug 29 '24 09:08 tonmoy-b

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
  • @kevinhartman
  • @mtreinish

qiskit-bot avatar Aug 29 '24 09:08 qiskit-bot

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)"),
    ]

tonmoy-b avatar Aug 29 '24 09:08 tonmoy-b

Pull Request Test Coverage Report for Build 10612643610

Details

  • 14 of 14 (100.0%) changed or added relevant lines in 2 files are covered.
  • 18 unchanged lines in 3 files lost coverage.
  • Overall coverage increased (+0.008%) to 89.204%

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

coveralls avatar Aug 29 '24 16:08 coveralls

Hi @mtreinish ,

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

Thanks and Regards, Tonmoy

tonmoy-b avatar Sep 25 '24 10:09 tonmoy-b

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

tonmoy-b avatar Oct 10 '24 05:10 tonmoy-b

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

tonmoy-b avatar Oct 29 '24 09:10 tonmoy-b