示例#1
0
    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 = _project_name(project_id)
        program_name = _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 _ids_from_program_name(program.name)[1], program
示例#2
0
 def _set_program_labels(self, project_id: str, program_id: str,
                         labels: Dict[str, str],
                         fingerprint: str) -> qtypes.QuantumProgram:
     program_resource_name = _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,
                                   labels=labels,
                                   label_fingerprint=fingerprint),
             qtypes.field_mask_pb2.FieldMask(paths=['labels']),
         ))
示例#3
0
    def set_program_description(self, project_id: str, program_id: str,
                                description: str) -> qtypes.QuantumProgram:
        """Sets the description for a previously created quantum program.

        Args:
            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 = _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']),
            ))