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 all 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
17 changes: 15 additions & 2 deletions cirq-core/cirq/ops/raw_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,8 @@ def with_probability(self, probability: 'cirq.TParamVal') -> 'cirq.Gate':
"""Creates a probabalistic channel with this gate.

Args:
probability: floating value between 0 and 1, giving the probability
this gate is applied.
probability: floating point value between 0 and 1, giving the
probability this gate is applied.

Returns:
`cirq.RandomGateChannel` that applies `self` with probability
Expand Down Expand Up @@ -579,6 +579,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 point value between 0 and 1, giving the
probability this gate 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