Skip to content

Commit

Permalink
with_probability docstring (quantumlib#5697)
Browse files Browse the repository at this point in the history
Adds a docstring for `Operation.with_probability`.
  • Loading branch information
95-martin-orion authored and rht committed May 1, 2023
1 parent 42dacc0 commit e57b949
Showing 1 changed file with 15 additions and 2 deletions.
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

0 comments on commit e57b949

Please sign in to comment.