cirq.TransformerLogger

Base Class for transformer logging infrastructure. Defaults to text-based logging.

Used in the notebooks

Used in the tutorials

The logger implementation should be stateful, s.t.:

- Each call to `register_initial` registers a new transformer stage and initial circuit.
- Each subsequent call to `log` should store additional logs corresponding to the stage.
- Each call to `register_final` should register the end of the currently active stage.

The logger assumes that

- Transformers are run sequentially.
- Nested transformers are allowed, in which case the behavior would be similar to a
  doing a depth first search on the graph of transformers -- i.e. the top level transformer
  would end (i.e. receive a `register_final` call) once all nested transformers (i.e. all
  `register_initial` calls received while the top level transformer was active) have
  finished (i.e. corresponding `register_final` calls have also been received).
- This behavior can be simulated by maintaining a stack of currently active stages and
  adding data from `log` calls to the stage at the top of the stack.

The LogLevels can be used to control the input processing and output resolution of the logs.

Methods

log

View source

Log additional metadata corresponding to the currently active transformer stage.

Args
*args The additional metadata to log.
level Logging level to control the amount of metadata that gets put into the context.

Raises
ValueError If there's no active transformer on the stack.

register_final

View source

Register the end of the currently active transformer stage.

Args
circuit Final transformed output circuit from the transformer stage.
transformer_name Name of the (currently active) transformer stage which ends.

Raises
ValueError If transformer_name is different from currently active transformer name.

register_initial

View source

Register the beginning of a new transformer stage.

Args
circuit Input circuit to the new transformer stage.
transformer_name Name of the new transformer stage.

show

View source

Show the stored logs >= level in the desired format.

Args
level The logging level to filter the logs with. The method shows all logs with a LogLevel >= level.