Exemple #1
0
 def _set_job_labels(self, job_resource_name: str, labels: Dict[str, str],
                     fingerprint: str):
     return self._make_request(lambda: self.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'])))
Exemple #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 = self._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'])))
Exemple #3
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
        """
        # 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 = self._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=[
                        self._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(
            self._program_name_from_ids(project_id, program_id), request, False
        ))
        return self._ids_from_job_name(job.name)[2], job
Exemple #4
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.

        Params:
            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 = self._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'])))
Exemple #5
0
    def create_job(
            self,
            *,  # Force keyword args.
            program_name: str,
            job_config: Optional[JobConfig] = None,
            params: study.Sweepable = None,
            repetitions: int = 1,
            priority: int = 500,
            processor_ids: Sequence[str] = ('xmonsim',),
            gate_set: serializable_gate_set.SerializableGateSet = None
    ) -> engine_job.EngineJob:
        gate_set = gate_set or gate_sets.XMON

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

        job_config = self.implied_job_config(job_config)
        sweeps = study.to_sweeps(params or study.ParamResolver({}))
        run_context = self._serialize_run_context(sweeps, repetitions)

        # Create job.
        request = qtypes.QuantumJob(
            name='%s/jobs/%s' % (program_name, job_config.job_id),
            scheduling_config=qtypes.SchedulingConfig(
                priority=priority,
                processor_selector=qtypes.SchedulingConfig.ProcessorSelector(
                    processor_names=[
                        'projects/%s/processors/%s' %
                        (self.project_id, processor_id)
                        for processor_id in processor_ids
                    ])),
            run_context=run_context)
        response = self._make_request(lambda: self.client.create_quantum_job(
            program_name, request, False))

        return engine_job.EngineJob(job_config, response, self)