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

with_probability docstring #5697

Merged
merged 5 commits into from
Jul 9, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions cirq-core/cirq/ops/raw_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,19 @@ def controlled_by(
return ops.controlled_operation.ControlledOperation(control_qubits, self, control_values)

def with_probability(self, probability: 'cirq.TParamVal') -> 'cirq.Operation':
"""Creates a probabalistic channel with this operation.

Args:
probability: floating value between 0 and 1, giving the probability
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: floating value -> floating point value

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, also for Gate.with_probability.

this operation is applied.

Returns:
`cirq.RandomGateChannel` that applies `self` with probability
`probability` and the identity with probability `1-p`.

Raises:
NotImplementedError: if called on an operation that lacks a gate.
"""
gate = self.gate
if gate is None:
raise NotImplementedError("with_probability on gateless operation.")
Expand Down