Skip to content
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

Fix num_qubits property on AsymetricDepolarizing Channel #4652

Merged
merged 4 commits into from
Nov 10, 2021

Conversation

dabacon
Copy link
Collaborator

@dabacon dabacon commented Nov 9, 2021

num_qubits was mistakenly added as a property to AsymetricDepolarizingChannel See #4185

I don't believe there is an easy way to deprecate this because one cannot have both a property and a method on the class, the last one define is called.

I propose that we just hard break this, but if someone has a better idea, I'm all ears. I kept the code commented out in case someone goes looking for this, and we can remove this after v0.15.

#4215 which also fixes this seems to have stalled.

@dabacon dabacon requested review from cduck, vtomole and a team as code owners November 9, 2021 22:59
@dabacon dabacon requested a review from mpharrigan November 9, 2021 22:59
@google-cla google-cla bot added the cla: yes Makes googlebot stop complaining. label Nov 9, 2021
@CirqBot CirqBot added the size: S 10< lines changed <50 label Nov 9, 2021
@dabacon dabacon changed the title Fix num_qubits property on AssymetricDepolarizing Channel Fix num_qubits property on AsymetricDepolarizing Channel Nov 9, 2021
@vtomole
Copy link
Collaborator

vtomole commented Nov 9, 2021

The reason the other PR stalled is because @viathor wanted to add a framework that makes sure this doesn't happen in the future: #4215 (review). We can merge this and create an issue for the creation of the testing framework.

Copy link
Collaborator

@vtomole vtomole left a comment

Choose a reason for hiding this comment

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

LGTM considering the nit.

def num_qubits(self) -> int:
"""The number of qubits"""
return self._num_qubits
# The following property was deprecated in Cirq v0.14. Please use the num_qubits methos instead.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# The following property was deprecated in Cirq v0.14. Please use the num_qubits methos instead.
# The following property was deprecated in Cirq v0.14. Please use the num_qubits method instead.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

removed to move comment

Copy link
Collaborator

@viathor viathor left a comment

Choose a reason for hiding this comment

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

LGTM

@vtomole I actually approved #4215 but @balopat correctly pointed out that we almost never accept PRs without unit tests, so I asked for changes on his behalf. I included a suggestion about a nice way to write such a unit test in a reusable way by adding a helper function.

It seems to me the PR stalled because the author is busy preparing for their finals, which is fair ;-)

@@ -729,7 +731,7 @@ def test_default_asymmetric_depolarizing_channel():
assert d.p_x == 0.0
assert d.p_y == 0.0
assert d.p_z == 0.0
assert d.num_qubits == 1
d.num_qubits() == 1
Copy link
Collaborator

@viathor viathor Nov 10, 2021

Choose a reason for hiding this comment

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

I think this should still assert.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

# @property
# def num_qubits(self) -> int:
# """"The number of qubits"""
# return self._num_qubits
Copy link
Collaborator

Choose a reason for hiding this comment

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

Optional: I'd remove the commented out code and just keep the comment (which you can also move to the top of the class). Folks affected by this will likely search for "num_qubits" so as long as the comment contains that string this remains discoverable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@@ -19,9 +19,10 @@

import numpy as np

from cirq import protocols, value
from cirq import protocols, value, _compat
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is _compat needed here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

pylint doesn't flag this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it did I just was an idiot and missed it.

@vtomole
Copy link
Collaborator

vtomole commented Nov 10, 2021

@viathor Ah thanks for clearing that up. I didn't read the following comments on that PR after yours.

@dabacon dabacon merged commit 2f123fb into quantumlib:master Nov 10, 2021
@dabacon dabacon deleted the propertyhell branch April 16, 2022 15:42
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
…4652)

This is a breaking change!

It removes the `num_qubits` property and instead one should use the `num_qubits` method.
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this pull request Oct 31, 2024
…4652)

This is a breaking change!

It removes the `num_qubits` property and instead one should use the `num_qubits` method.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Makes googlebot stop complaining. size: S 10< lines changed <50
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants