示例#1
0
    def create_job(
        self,
        project_id: str,
        program_id: str,
        job_id: Optional[str],
        processor_ids: Sequence[str],
        run_context: qtypes.any_pb2.Any,
        priority: Optional[int] = None,
        description: Optional[str] = None,
        labels: Optional[Dict[str, str]] = None,
    ) -> Tuple[str, qtypes.QuantumJob]:
        """Creates and runs a job on Quantum Engine.

        Args:
            project_id: A project_id of the parent Google Cloud Project.
            program_id: Unique ID of the program within the parent project.
            job_id: Unique ID of the job within the parent program.
            run_context: Properly serialized run context.
            processor_ids: List of processor id for running the program.
            priority: Optional priority to run at, 0-1000.
            description: Optional description to set on the job.
            labels: Optional set of labels to set on the job.

        Returns:
            Tuple of created job id and job.

        Raises:
            ValueError: If the priority is not betwen 0 and 1000.
        """
        # Check program to run and program parameters.
        if priority and not 0 <= priority < 1000:
            raise ValueError('priority must be between 0 and 1000')

        # Create job.
        job_name = _job_name_from_ids(project_id, program_id,
                                      job_id) if job_id else ''
        request = qtypes.QuantumJob(
            name=job_name,
            scheduling_config=qtypes.SchedulingConfig(
                processor_selector=qtypes.SchedulingConfig.ProcessorSelector(
                    processor_names=[
                        _processor_name_from_ids(project_id, processor_id)
                        for processor_id in processor_ids
                    ])),
            run_context=run_context,
        )
        if priority:
            request.scheduling_config.priority = priority
        if description:
            request.description = description
        if labels:
            request.labels.update(labels)
        job = self._make_request(lambda: self.grpc_client.create_quantum_job(
            _program_name_from_ids(project_id, program_id), request, False))
        return _ids_from_job_name(job.name)[2], job
示例#2
0
 def _set_job_labels(
     self,
     project_id: str,
     program_id: str,
     job_id: str,
     labels: Dict[str, str],
     fingerprint: str,
 ) -> qtypes.QuantumJob:
     job_resource_name = _job_name_from_ids(project_id, program_id, job_id)
     return self._make_request(lambda: self.grpc_client.update_quantum_job(
         job_resource_name,
         qtypes.QuantumJob(name=job_resource_name,
                           labels=labels,
                           label_fingerprint=fingerprint),
         qtypes.field_mask_pb2.FieldMask(paths=['labels']),
     ))
示例#3
0
    def set_job_description(self, project_id: str, program_id: str,
                            job_id: str,
                            description: str) -> qtypes.QuantumJob:
        """Sets the description for a previously created quantum job.

        Args:
            project_id: A project_id of the parent Google Cloud Project.
            program_id: Unique ID of the program within the parent project.
            job_id: Unique ID of the job within the parent program.
            description: The new job description.

        Returns:
            The updated quantum job.
        """
        job_resource_name = _job_name_from_ids(project_id, program_id, job_id)
        return self._make_request(lambda: self.grpc_client.update_quantum_job(
            job_resource_name,
            qtypes.QuantumJob(name=job_resource_name, description=description),
            qtypes.field_mask_pb2.FieldMask(paths=['description']),
        ))