def serialize(self, program: 'cirq.Circuit', msg: Optional[v2.program_pb2.Program] = None, *, arg_function_language: Optional[str] = None ) -> v2.program_pb2.Program: """Serialize a Circuit to cirq.google.api.v2.Program proto. Args: program: The Circuit to serialize. """ if msg is None: msg = v2.program_pb2.Program() msg.language.gate_set = self.gate_set_name if isinstance(program, circuits.Circuit): self._serialize_circuit(program, msg.circuit, arg_function_language=arg_function_language) if arg_function_language is None: arg_function_language = ( arg_func_langs._infer_function_language_from_circuit( msg.circuit)) else: raise NotImplementedError( f'Unrecognized program type: {type(program)}') msg.language.arg_function_language = arg_function_language return msg
def serialize( self, program: 'cirq.Circuit', msg: Optional[v2.program_pb2.Program] = None, *, arg_function_language: Optional[str] = None, use_constants_table_for_tokens: Optional[bool] = True, ) -> v2.program_pb2.Program: """Serialize a Circuit to cirq.google.api.v2.Program proto. Args: program: The Circuit to serialize. """ if msg is None: msg = v2.program_pb2.Program() msg.language.gate_set = self.gate_set_name if isinstance(program, circuits.Circuit): constants: Optional[List[v2.program_pb2.Constant]] = ( [] if use_constants_table_for_tokens else None) self._serialize_circuit(program, msg.circuit, arg_function_language=arg_function_language, constants=constants) if constants is not None: msg.constants.extend(constants) if arg_function_language is None: arg_function_language = ( arg_func_langs._infer_function_language_from_circuit( msg.circuit)) else: raise NotImplementedError( f'Unrecognized program type: {type(program)}') msg.language.arg_function_language = arg_function_language return msg