Skip to content

Commit 7fe9671

Browse files
authored
Add docstring for cirq.TRANSFORMER public object (#5149)
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.
1 parent ed56edc commit 7fe9671

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

cirq-core/cirq/transformers/transformer_api.py

+31
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,37 @@ class TransformerContext:
229229

230230

231231
class TRANSFORMER(Protocol):
232+
"""Protocol class defining the Transformer API for circuit transformers in Cirq.
233+
234+
Any callable that satisfies the `cirq.TRANSFORMER` contract, i.e. takes a `cirq.AbstractCircuit`
235+
and `cirq.TransformerContext` and returns a transformed `cirq.AbstractCircuit`, is a valid
236+
transformer in Cirq.
237+
238+
Note that transformers can also accept additional arguments as `**kwargs`, with default values
239+
specified for each keyword argument. A transformer could be a function, for example:
240+
241+
>>> def convert_to_cz(
242+
>>> circuit: cirq.AbstractCircuit,
243+
>>> *,
244+
>>> context: Optional[cirq.TransformerContext] = None,
245+
>>> atol: float = 1e-8,
246+
>>> ) -> cirq.Circuit:
247+
>>> ...
248+
249+
Or it could be a class that implements `__call__` with the same API, for example:
250+
251+
>>> class ConvertToSqrtISwaps:
252+
>>> def __init__(self):
253+
>>> ...
254+
>>> def __call__(
255+
>>> self,
256+
>>> circuit: cirq.AbstractCircuit,
257+
>>> *,
258+
>>> context: Optional[cirq.TransformerContext] = None,
259+
>>> ) -> cirq.AbstractCircuit:
260+
>>> ...
261+
"""
262+
232263
def __call__(
233264
self, circuit: 'cirq.AbstractCircuit', *, context: Optional[TransformerContext] = None
234265
) -> 'cirq.AbstractCircuit':

0 commit comments

Comments
 (0)