![]() |
Describes how to serialize a GateOperation for a given Gate type.
Inherits From: OpSerializer
cirq_google.serialization.GateOpSerializer(
*,
gate_type: Type[cirq_google.serialization.op_serializer.Gate
],
serialized_gate_id: str,
args: List[cirq_google.serialization.SerializingArg
],
can_serialize_predicate: Callable[[cirq.Operation], bool] = (lambda x: True),
serialize_tokens: Optional[bool] = True
)
Args | |
---|---|
gate_type
|
The type of the gate that is being serialized. |
serialized_gate_id
|
The string id of the gate when serialized. |
args
|
A list of specification of the arguments to the gate when serializing, including how to get this information from the gate of the given gate type. |
can_serialize_predicate
|
Sometimes an Operation can only be serialized for particular parameters. This predicate will be checked before attempting to serialize the Operation. If the predicate is False, serialization will result in a None value. Default value is a lambda that always returns True. |
serialize_tokens
|
Whether to convert calibration tags into tokens on the Operation proto. |
Attributes | |
---|---|
gate_type
|
The type of the gate that can be serialized. |
serialized_gate_id
|
The id used when serializing the gate. |
serialize_tokens
|
Whether to convert CalibrationTags into tokens on the Operation proto. Defaults to True. |
args
|
|
can_serialize_predicate
|
The method used to determine if this can serialize an operation.
Depending on the serializer, additional checks may be required. |
internal_type
|
Returns the type that the operation contains.
For GateOperations, this is the gate type. For CircuitOperations, this is FrozenCircuit. |
serialized_id
|
Returns the string identifier for the resulting serialized object.
This ID denotes the serialization format this serializer produces. For example, one of the common serializers assigns the id 'xy' to XPowGates, as they serialize into a format also used by YPowGates. |
Methods
can_serialize_operation
can_serialize_operation(
op: cirq.Operation
) -> bool
Whether the given operation can be serialized by this serializer.
This checks that the gate is a subclass of the gate type for this
serializer, and that the gate returns true for
can_serializer_predicate
called on the gate.
to_proto
to_proto(
op: cirq.Operation,
msg: Optional[cirq_google.api.v2.program_pb2.Operation
] = None,
*,
arg_function_language: Optional[str] = '',
constants: List[cirq_google.api.v2.program_pb2.Constant
] = None,
raw_constants: Dict[Any, int] = None
) -> Optional[cirq_google.api.v2.program_pb2.Operation
]
Returns the cirq_google.api.v2.Operation message as a proto dict.
Note that this function may modify the constant list if it adds tokens to the circuit's constant table.