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
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions cirq-core/cirq/ops/common_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

from cirq.ops import raw_types, common_gates, pauli_gates, gate_features, identity


if TYPE_CHECKING:
import cirq

Expand Down Expand Up @@ -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.
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

#
# @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


@property
def error_probabilities(self) -> Dict[str, float]:
Expand All @@ -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()
Expand Down
4 changes: 3 additions & 1 deletion cirq-core/cirq/ops/common_channels_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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



def test_bad_error_probabilities_gate():
Expand Down