def create_program( self, project_id: str, program_id: Optional[str], code: qtypes.any_pb2.Any, description: Optional[str] = None, labels: Optional[Dict[str, str]] = None, ) -> Tuple[str, qtypes.QuantumProgram]: """Creates a Quantum Engine program. Args: project_id: A project_id of the parent Google Cloud Project. program_id: Unique ID of the program within the parent project. code: Properly serialized program code. description: An optional description to set on the program. labels: Optional set of labels to set on the program. Returns: Tuple of created program id and program """ parent_name = self._project_name(project_id) program_name = self._program_name_from_ids( project_id, program_id) if program_id else '' request = qtypes.QuantumProgram(name=program_name, code=code) if description: request.description = description if labels: request.labels.update(labels) program = self._make_request( lambda: self.grpc_client.create_quantum_program( parent_name, request, False)) return self._ids_from_program_name(program.name)[1], program
def create_program( self, program: 'cirq.Circuit', program_id: Optional[str] = None, gate_set: serializable_gate_set.SerializableGateSet = None ) -> engine_program.EngineProgram: """Wraps a Circuit for use with the Quantum Engine. Args: program: The Circuit to execute. program_id: A user-provided identifier for the program. This must be unique within the Google Cloud project being used. If this parameter is not provided, a random id of the format 'prog-################YYMMDD' will be generated, where # is alphanumeric and YYMMDD is the current year, month, and day. gate_set: The gate set used to serialize the circuit. The gate set must be supported by the selected processor """ gate_set = gate_set or gate_sets.XMON if not program_id: program_id = _make_random_id('prog-') parent_name = 'projects/%s' % self.project_id program_name = '%s/programs/%s' % (parent_name, program_id) # Create program. request = qtypes.QuantumProgram(name=program_name, code=self._serialize_program( program, gate_set)) result = self._make_request(lambda: self.client.create_quantum_program( parent_name, request, False)) return engine_program.EngineProgram(result.name, self)
def _set_program_labels(self, program_id: str, labels: Dict[str, str], fingerprint: str): program_resource_name = self._program_name_from_id(program_id) return self._make_request(lambda: self.client.update_quantum_program( program_resource_name, qtypes.QuantumProgram(name=program_resource_name, labels=labels, label_fingerprint=fingerprint), qtypes.field_mask_pb2.FieldMask(paths=['labels'])))
def set_program_description(self, project_id: str, program_id: str, description: str) -> qtypes.QuantumProgram: """Sets the description for a previously created quantum program. Params: project_id: A project_id of the parent Google Cloud Project. program_id: Unique ID of the program within the parent project. description: The new program description. Returns: The updated quantum program. """ program_resource_name = self._program_name_from_ids( project_id, program_id) return self._make_request( lambda: self.grpc_client.update_quantum_program( program_resource_name, qtypes.QuantumProgram(name=program_resource_name, description=description), qtypes.field_mask_pb2.FieldMask(paths=['description'])))