cirq_google.serialization.op_serializer.OpSerializer

Generic supertype for operation serializers.

Each operation serializer describes how to serialize a specific type of Cirq operation to its corresponding proto format. Multiple operation types may serialize to the same format.

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.

to_proto

View source

Converts op to proto using this serializer.

If self.can_serialize_operation(op) == false, this should return None.

Args
op The Cirq operation to be serialized.
msg An optional proto object to populate with the serialization results.
arg_function_language The arg_function_language field from Program.Language.
constants The list of previously-serialized Constant protos.
raw_constants A map raw objects to their respective indices in constants.

Returns
The proto-serialized version of op. If msg was provided, it is the returned object.