![]() |
Describes how to serialize a GateOperation for a given Gate type.
cirq.google.GateOpSerializer(
*,
gate_type: Type[cirq.google.op_serializer.Gate
] = (lambda x: True),
serialized_gate_id: str = True,
args: List[cirq.google.SerializingArg
],
can_serialize_predicate: cirq.optimizers.stratify.Classifier
= <function GateOpSerializer.<lambda> at 0x7fa70baa2320>,
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. |
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. |
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. |
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
) -> 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.