8000 Implemented a type check in copy method of QuantumCircuit class by Abhiraj-Shrotriya · Pull Request #10521 · Qiskit/qiskit · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Implemented a type check in copy method of QuantumCircuit class #10521

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 3, 2023

Conversation

Abhiraj-Shrotriya
Copy link
Contributor

Summary

Forces the arguments to be of string or None type for copy method of QuantumCircuit Class hence solving issues that may rise due to unsupported/unwanted types.

Details and comments

The code checks if the 'name' argument is of string or None type.
If 'name' is of string or None type, Then the following code creates a copy of the provided circuit.
Else, It raises a TypeError.

Closes #10487

@Abhiraj-Shrotriya Abhiraj-Shrotriya requested a review from a team as a code owner July 27, 2023 19:56
@qiskit-bot qiskit-bot added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Jul 27, 2023
@qiskit-bot
Copy link
Collaborator

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 every 8000 one.

One or more of the the following people are requested to review this:

  • @Qiskit/terra-core

Copy link
Member
@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

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

Thanks for looking at this.

In this case, it'd actually be a little better to put the test in QuantumCircuit.copy_empty_like, because then both QuantumCircuit.copy and copy_empty_like will both gain the new test.

Please could you also add a one-line test of each method in test/python/circuit/test_circuit_operations.py?

@jakelishman
Copy link
Member
jakelishman commented Jul 28, 2023

By the way, there's no need to close and open PRs if you're changing it - you can just push commits to the PR you've already got open.

You only need a new PR if you're starting a separate change.

@Abhiraj-Shrotriya
Copy link
Contributor Author

By the test do you mean adding the following?

self.assertRaises(TypeError, qc.copy, namearg) # where namearg is not an str or None type

@jakelishman
Copy link
Member

Sure, something like

class TestCircuitOperations(QiskitTestCase):
    def test_circuit_copy_rejects_bad_types(self):
        qc = ...
        with self.assertRaises(TypeError):
            qc.copy(name=...)

@jakelishman
Copy link
Member

Sorry, I realise I wasn't super clear: I didn't mean literally one line, I was being a bit imprecise and just meant that it only needs to be a very short test.

@Abhiraj-Shrotriya
Copy link
Contributor Author

I did take it literally. No problem :)

@Abhiraj-Shrotriya
Copy link
Contributor Author
Abhiraj-Shrotriya commented Jul 28, 2023

Should I write tests for both methods under just one function or two?

What I mean to say is:

Should I do this -

class TestCircuitOperations(QiskitTestCase):
    def test_circuit_copy_rejects_bad_types(self):
        ...

or

class TestCircuitOperations(QiskitTestCase):
    def test_circuit_copy_rejects_bad_types(self):
        ...
    def test_circuit_copy_empty_like_rejects_bad_types(self):
        ...

Sorry for so many questions.

Edit - right now doing it with two functions to ensure a clear documentation and testing.

@jakelishman
Copy link
Member

Don't worry it's ok - we all need to learn. Here, it's probably best for you to write two separate functions. It's ok in tests if the code is a little more duplicated, because test code should look really obviously correct to someone reading the test, as far as possible.

@Abhiraj-Shrotriya
Copy link
Contributor Author

@jakelishman
I know you are very busy right now (as I can see from the frequent pull requests). Can you please review the updates so that this issue can be closed?

Thank you

Copy link
Member
@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

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

Thanks for this!

@jakelishman jakelishman enabled auto-merge August 3, 2023 10:47
@jakelishman jakelishman added Changelog: Bugfix Include in the "Fixed" section of the changelog stable backport potential The bug might be minimal and/or import enough to be port to stable labels Aug 3, 2023
@jakelishman jakelishman added this to the 0.25.1 milestone Aug 3, 2023
@coveralls
Copy link

Pull Request Test Coverage Report for Build 5749765666

  • 2 of 2 (100.0%) changed or added relevant lines in 1 file are covered.
  • 11 unchanged lines in 3 files lost coverage.
  • Overall coverage increased (+0.01%) to 85.895%

Files with Coverage Reduction New Missed Lines %
crates/accelerate/src/sabre_swap/mod.rs 1 97.53%
crates/qasm2/src/lex.rs 4 90.63%
crates/qasm2/src/parse.rs 6 97.13%
Totals Coverage Status
Change from base Build 5684162640: 0.01%
Covered Lines: 73065
Relevant Lines: 85063

💛 - Coveralls

@jakelishman jakelishman added this pull request to the merge queue Aug 3, 2023
@jakelishman jakelishman removed the stable backport potential The bug might be minimal and/or import enough to be port to stable label Aug 3, 2023
@jakelishman jakelishman modified the milestones: 0.25.1, 0.45.0 Aug 3, 2023
Merged via the queue into Qiskit:main with commit 4372c6d Aug 3, 2023
@Abhiraj-Shrotriya Abhiraj-Shrotriya deleted the fixissue10487branch branch August 6, 2023 16:43
SameerD-phys pushed a commit to SameerD-phys/qiskit-terra that referenced this pull request Sep 7, 2023
…it#10521)

* Implemented a type check in copy method of QuantumCircuit class

* Made copy method code more efficient and added a circuit operation test

* Corrected and made clear documentation of copy method - QuantumCircuit

* Fix wording

---------

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: Bugfix Include in the "Fixed" section of the changelog Community PR PRs from contributors that are not 'members' of the Qiskit repo
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

QuantumCircuit.copy(name=?) allows for any object to be used as name
4 participants
0