cirq_google.serialization.GateOpSerializer

Describes how to serialize a GateOperation for a given Gate type.

Inherits From: OpSerializer

gate_type The type of the gate that is being serialized.
serialized_gate_id The string id of the gate when serialized.
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.
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.

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

View source

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

View source

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.