![]() |
Gatesets represent a collection of cirq.GateFamily
objects.
cirq.Gateset(
*gates,
name: Optional[str] = None,
unroll_circuit_op: bool = True,
accept_global_phase_op: bool = True
) -> None
Used in the notebooks
Used in the tutorials |
---|
Gatesets are useful for a) Describing the set of allowed gates in a human readable format b) Validating a given gate / optree against the set of allowed gates
Gatesets rely on the underlying cirq.GateFamily
for both description and
validation purposes.
Args | |
---|---|
*gates
|
A list of cirq.Gate subclasses / cirq.Gate instances /
cirq.GateFamily instances to initialize the Gateset.
|
name
|
(Optional) Name for the Gateset. Useful for description. |
unroll_circuit_op
|
If True, cirq.CircuitOperation is recursively
validated by validating the underlying cirq.Circuit .
|
accept_global_phase_op
|
If True, cirq.GlobalPhaseOperation is accepted.
|
Attributes | |
---|---|
gates
|
|
name
|
Methods
validate
validate(
circuit_or_optree: Union['cirq.AbstractCircuit', op_tree.OP_TREE]
) -> bool
Validates gates forming circuit_or_optree
should be contained in Gateset.
Args | |
---|---|
circuit_or_optree
|
The cirq.Circuit or cirq.OP_TREE to validate.
|
with_params
with_params(
*,
name: Optional[str] = None,
unroll_circuit_op: Optional[bool] = None,
accept_global_phase_op: Optional[bool] = None
) -> 'Gateset'
Returns a copy of this Gateset with identical gates and new values for named arguments.
If a named argument is None then corresponding value of this Gateset is used instead.
Args | |
---|---|
name
|
New name for the Gateset. |
unroll_circuit_op
|
If True, new Gateset will recursively validate
cirq.CircuitOperation by validating the underlying cirq.Circuit .
|
accept_global_phase_op
|
If True, new Gateset will accept cirq.GlobalPhaseOperation .
|
Returns | |
---|---|
self if all new values are None or identical to the values of current Gateset.
else a new Gateset with identical gates and new values for named arguments.
|
__contains__
__contains__(
item: Union[cirq.Gate
, cirq.Operation
]
) -> bool
Check for containment of a given Gate/Operation in this Gateset.
Containment checks are handled as follows: a) For Gates or Operations that have an underlying gate (i.e. op.gate is not None):
- Forwards the containment check to the underlying <a href="../cirq/GateFamily"><code>cirq.GateFamily</code></a> objects.
- Examples of such operations include `cirq.GateOperations` and their controlled
and tagged variants (i.e. instances of <a href="../cirq/TaggedOperation"><code>cirq.TaggedOperation</code></a>,
<a href="../cirq/ControlledOperation"><code>cirq.ControlledOperation</code></a> where `op.gate` is not None) etc.
b) For Operations that do not have an underlying gate:
- Forwards the containment check to `self._validate_operation(item)`.
- Examples of such operations include `cirq.CircuitOperations` and their controlled
and tagged variants (i.e. instances of <a href="../cirq/TaggedOperation"><code>cirq.TaggedOperation</code></a>,
<a href="../cirq/ControlledOperation"><code>cirq.ControlledOperation</code></a> where `op.gate` is None) etc.
The complexity of the method in terms of the number of gates
, n, is
a) O(1) when any default cirq.GateFamily
instance accepts the given item, except
for an Instance GateFamily trying to match an item with a different global phase.
b) O(n) for all other cases: matching against custom gate families, matching across
global phase for the default Instance GateFamily, no match against any underlying
gate family.
Args | |
---|---|
item
|
The cirq.Gate or cirq.Operation instance to check containment for.
|
__eq__
__eq__(
other: _SupportsValueEquality
) -> bool