-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -19,9 +19,10 @@ | |||||
|
||||||
import numpy as np | ||||||
|
||||||
from cirq import protocols, value | ||||||
from cirq import protocols, value, _compat | ||||||
from cirq.ops import raw_types, common_gates, pauli_gates, gate_features, identity | ||||||
|
||||||
|
||||||
if TYPE_CHECKING: | ||||||
import cirq | ||||||
|
||||||
|
@@ -178,10 +179,12 @@ def p_z(self) -> float: | |||||
raise ValueError('num_qubits should be 1') | ||||||
return self._error_probabilities.get('Z', 0.0) | ||||||
|
||||||
@property | ||||||
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. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed to move comment |
||||||
# | ||||||
# @property | ||||||
# def num_qubits(self) -> int: | ||||||
# """"The number of qubits""" | ||||||
# return self._num_qubits | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||||||
|
||||||
@property | ||||||
def error_probabilities(self) -> Dict[str, float]: | ||||||
|
@@ -193,7 +196,7 @@ def _json_dict_(self) -> Dict[str, Any]: | |||||
|
||||||
def _approx_eq_(self, other: Any, atol: float) -> bool: | ||||||
return ( | ||||||
self.num_qubits == other.num_qubits | ||||||
self._num_qubits == other._num_qubits | ||||||
and np.isclose(self.p_i, other.p_i, atol=atol).item() | ||||||
and np.isclose(self.p_x, other.p_x, atol=atol).item() | ||||||
and np.isclose(self.p_y, other.p_y, atol=atol).item() | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,8 @@ def test_asymmetric_depolarizing_channel(): | |
) | ||
assert cirq.has_kraus(d) | ||
|
||
assert cirq.AsymmetricDepolarizingChannel(p_x=0, p_y=0.1, p_z=0).num_qubits() == 1 | ||
|
||
|
||
def test_asymmetric_depolarizing_mixture(): | ||
d = cirq.asymmetric_depolarize(0.1, 0.2, 0.3) | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should still assert. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
|
||
def test_bad_error_probabilities_gate(): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
_compat
needed here?There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.