Transforms the given circuit into an equivalent circuit using gates accepted by gateset
.
cirq.optimize_for_target_gateset(
circuit: 'cirq.AbstractCircuit',
*,
context: Optional['cirq.TransformerContext'] = None,
gateset: Optional['cirq.CompilationTargetGateset'] = None,
ignore_failures: bool = True,
max_num_passes: Union[int, None] = 1
) -> 'cirq.Circuit'
Used in the notebooks
Repeat max_num_passes times or when max_num_passes=None
until no further changes can be done
- Run all
gateset.preprocess_transformers
- Convert operations using built-in cirq decompose +
gateset.decompose_to_target_gateset
.
- Run all
gateset.postprocess_transformers
Note |
The optimizer is a heuristic and may not produce optimal results even with
max_num_passes=None. The preprocessors and postprocessors of the gate set
as well as their order yield different results.
|
Args |
circuit
|
Input circuit to transform. It will not be modified.
|
context
|
cirq.TransformerContext storing common configurable options for transformers.
|
gateset
|
Target gateset, which should be an instance of cirq.CompilationTargetGateset .
|
ignore_failures
|
If set, operations that fail to convert are left unchanged. If not set,
conversion failures raise a ValueError.
|
max_num_passes
|
The maximum number of passes to do. A value of None means to keep
iterating until no more changes happen to the number of moments or operations.
|
Returns |
An equivalent circuit containing gates accepted by gateset .
|
Raises |
ValueError
|
If any input operation fails to convert and ignore_failures is False.
|