Skip to content

Commit

Permalink
Add docstring for cirq.TRANSFORMER public object (#5149)
Browse files Browse the repository at this point in the history
Adds docstring for `cirq.TRANSFORMER` public object. The api reference automatically creates a reference page for the public object, and currently inherits the docstring from the `Protocol` base class, which is irrelevant and the PR fixes it.
  • Loading branch information
tanujkhattar authored Mar 28, 2022
1 parent ed56edc commit 7fe9671
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions cirq-core/cirq/transformers/transformer_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,37 @@ class TransformerContext:


class TRANSFORMER(Protocol):
"""Protocol class defining the Transformer API for circuit transformers in Cirq.
Any callable that satisfies the `cirq.TRANSFORMER` contract, i.e. takes a `cirq.AbstractCircuit`
and `cirq.TransformerContext` and returns a transformed `cirq.AbstractCircuit`, is a valid
transformer in Cirq.
Note that transformers can also accept additional arguments as `**kwargs`, with default values
specified for each keyword argument. A transformer could be a function, for example:
>>> def convert_to_cz(
>>> circuit: cirq.AbstractCircuit,
>>> *,
>>> context: Optional[cirq.TransformerContext] = None,
>>> atol: float = 1e-8,
>>> ) -> cirq.Circuit:
>>> ...
Or it could be a class that implements `__call__` with the same API, for example:
>>> class ConvertToSqrtISwaps:
>>> def __init__(self):
>>> ...
>>> def __call__(
>>> self,
>>> circuit: cirq.AbstractCircuit,
>>> *,
>>> context: Optional[cirq.TransformerContext] = None,
>>> ) -> cirq.AbstractCircuit:
>>> ...
"""

def __call__(
self, circuit: 'cirq.AbstractCircuit', *, context: Optional[TransformerContext] = None
) -> 'cirq.AbstractCircuit':
Expand Down

0 comments on commit 7fe9671

Please sign in to comment.