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

Rename _channel_ to _kraus_ #4139

Merged
merged 9 commits into from
Jun 1, 2021
Merged

Rename _channel_ to _kraus_ #4139

merged 9 commits into from
Jun 1, 2021

Conversation

viathor
Copy link
Collaborator

@viathor viathor commented May 26, 2021

This renames magic methods _channel_ to _kraus_ and _has_channel_ to _has_kraus_. Follow-up renames the protocols cirq.channel to cirq.kraus and cirq.has_channel to cirq.has_kraus.

Context: #4138.

@viathor viathor requested review from cduck, vtomole and a team as code owners May 26, 2021 23:50
@viathor viathor requested a review from dstrain115 May 26, 2021 23:50
@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@google-cla google-cla bot added the cla: yes Makes googlebot stop complaining. label May 26, 2021
@viathor viathor changed the title Rename _channel_ to _kraus_ Rename _channel_ to _kraus_ May 26, 2021
Copy link
Collaborator

@mpharrigan mpharrigan left a comment

Choose a reason for hiding this comment

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

Do we consider _channel_ to be part of our API? I know the preceeding underscore means "private" in Python, but in Cirq (and IPython, numpy(?), maybe others) flanking underscores means magic method that 3rd party classes can implement.

I can certainly see a situation where someone has their own gate or channel that defines _channel_ and this would break them. Would it be worth the effort to go through a deprecation cycle? I don't think it would be too hard to fall back to _channel_ (and emit a warning) if it exists and _kraus_ doesn't.

def _channel_(self) -> Union[Sequence[np.ndarray], NotImplementedType]:
r"""A list of matrices describing the quantum channel.
def _kraus_(self) -> Union[Sequence[np.ndarray], NotImplementedType]:
r"""A list of Kraus operators describing the quantum channel.
Copy link
Collaborator

Choose a reason for hiding this comment

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

kraus matrices?

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.

@@ -266,7 +266,7 @@ def err_str(buf_num_str):
return default
raise TypeError(
"object of type '{}' has no _apply_channel_, _apply_unitary_, "
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we also rename _apply_channel_, or is that method more generally applicable to other channel representations?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think we should make sure that apply_channel protocol works with all channel representations. It's more user-friendly than having an apply* protocol for each representation and forcing the user to check which representation they have at their disposal.

cirq-core/cirq/sim/density_matrix_simulator.py Outdated Show resolved Hide resolved
cirq-core/cirq/protocols/channel.py Outdated Show resolved Hide resolved
cirq-core/cirq/protocols/channel.py Outdated Show resolved Hide resolved
cirq-core/cirq/protocols/channel_test.py Show resolved Hide resolved
@viathor
Copy link
Collaborator Author

viathor commented May 27, 2021

PTAL

Copy link
Collaborator

@95-martin-orion 95-martin-orion left a comment

Choose a reason for hiding this comment

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

Looks good to me - I think adding _channel_ back into the interface resolves both Matt's comment and mine.

@viathor viathor merged commit bc4123e into quantumlib:master Jun 1, 2021
@viathor viathor deleted the _kraus_ branch June 1, 2021 23:54
CirqBot pushed a commit that referenced this pull request Jun 15, 2021
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants