![]() |
Wrapper around gate instances/types describing a set of accepted gates.
cirq.GateFamily(
gate: Union[Type[raw_types.Gate], raw_types.Gate],
*,
name: Optional[str] = None,
description: Optional[str] = None,
ignore_global_phase: bool = True
) -> None
GateFamily supports initialization via
a) Non-parameterized instances of cirq.Gate
(Instance Family).
b) Python types inheriting from cirq.Gate
(Type Family).
By default, the containment checks depend on the initialization type:
a) Instance Family: Containment check is done via cirq.equal_up_to_global_phase
.
b) Type Family: Containment check is done by type comparison.
For example:
a) Instance Family:
```
>>> gate_family = cirq.GateFamily(cirq.X)
>>> assert cirq.X in gate_family
>>> assert cirq.Rx(rads=np.pi) in gate_family
>>> assert cirq.X ** sympy.Symbol("theta") not in gate_family
```
b) Type Family:
```
>>> gate_family = cirq.GateFamily(cirq.XPowGate)
>>> assert cirq.X in gate_family
>>> assert cirq.Rx(rads=np.pi) in gate_family
>>> assert cirq.X ** sympy.Symbol("theta") in gate_family
```
In order to create gate families with constraints on parameters of a gate
type, users should derive from the cirq.GateFamily
class and override the
_predicate
method used to check for gate containment.
Args | |
---|---|
gate
|
A python type inheriting from cirq.Gate for type based membership checks, or
a non-parameterized instance of a cirq.Gate for equality based membership checks.
|
name
|
The name of the gate family. |
description
|
Human readable description of the gate family. |
ignore_global_phase
|
If True, value equality is checked via
cirq.equal_up_to_global_phase .
|
Raises | |
---|---|
ValueError
|
if gate is not a cirq.Gate instance or subclass.
|
ValueError
|
if gate is a parameterized instance of cirq.Gate .
|
Attributes | |
---|---|
description
|
|
gate
|
|
name
|
Methods
__contains__
__contains__(
item: Union[cirq.Gate
, cirq.Operation
]
) -> bool
__eq__
__eq__(
other: _SupportsValueEquality
) -> bool