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

Add docstring for cirq.TRANSFORMER public object #5149

Merged
merged 2 commits into from
Mar 28, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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