def run_calibration( self, job_id: Optional[str] = None, processor_ids: Sequence[str] = (), description: Optional[str] = None, labels: Optional[Dict[str, str]] = None, ) -> engine_job.EngineJob: """Runs layers of calibration routines on the Quantum Engine. This method should only be used if the Program object was created with a `FocusedCalibration`. This method does not block until a result is returned. However, no results will be available until all calibration routines complete. Args: job_id: Optional job id to use. If this is not provided, a random id of the format 'calibration-################YYMMDD' will be generated, where # is alphanumeric and YYMMDD is the current year, month, and day. processor_ids: The engine processors that should be candidates to run the program. Only one of these will be scheduled for execution. description: An optional description to set on the job. labels: Optional set of labels to set on the job. Returns: An EngineJob. Results can be accessed with calibration_results(). """ import cirq_google.engine.engine as engine_base if not job_id: job_id = engine_base._make_random_id('calibration-') if not processor_ids: raise ValueError('No processors specified') # Default run context # Note that Quantum Engine currently requires a valid type url # on a run context in order to succeed validation. any_context = qtypes.any_pb2.Any() any_context.Pack(v2.run_context_pb2.RunContext()) created_job_id, job = self.context.client.create_job( project_id=self.project_id, program_id=self.program_id, job_id=job_id, processor_ids=processor_ids, run_context=any_context, description=description, labels=labels, ) return engine_job.EngineJob( self.project_id, self.program_id, created_job_id, self.context, job, result_type=ResultType.Batch, )
def run_sweep( self, job_id: Optional[str] = None, params: cirq.Sweepable = None, repetitions: int = 1, processor_ids: Sequence[str] = ('xmonsim', ), description: Optional[str] = None, labels: Optional[Dict[str, str]] = None, ) -> engine_job.EngineJob: """Runs the program on the QuantumEngine. In contrast to run, this runs across multiple parameter sweeps, and does not block until a result is returned. Args: job_id: Optional job id to use. If this is not provided, a random id of the format 'job-################YYMMDD' will be generated, where # is alphanumeric and YYMMDD is the current year, month, and day. params: Parameters to run with the program. repetitions: The number of circuit repetitions to run. processor_ids: The engine processors that should be candidates to run the program. Only one of these will be scheduled for execution. description: An optional description to set on the job. labels: Optional set of labels to set on the job. Returns: An EngineJob. If this is iterated over it returns a list of TrialResults, one for each parameter sweep. Raises: ValueError: If called on a program that is a batch of programs. """ import cirq_google.engine.engine as engine_base if self.result_type != ResultType.Program: raise ValueError('Please use run_batch() for batch mode.') if not job_id: job_id = engine_base._make_random_id('job-') sweeps = cirq.to_sweeps(params or cirq.ParamResolver({})) run_context = self._serialize_run_context(sweeps, repetitions) created_job_id, job = self.context.client.create_job( project_id=self.project_id, program_id=self.program_id, job_id=job_id, processor_ids=processor_ids, run_context=run_context, description=description, labels=labels, ) return engine_job.EngineJob(self.project_id, self.program_id, created_job_id, self.context, job)
async def run_batch_async( self, job_id: Optional[str] = None, params_list: List[cirq.Sweepable] = None, repetitions: int = 1, processor_ids: Sequence[str] = (), description: Optional[str] = None, labels: Optional[Dict[str, str]] = None, ) -> engine_job.EngineJob: """Runs a batch of circuits on the QuantumEngine. This method should only be used if the Program object was created with a BatchProgram. The number of parameter sweeps should match the number of circuits within that BatchProgram. This method does not block until a result is returned. However, no results will be available until the entire batch is complete. Args: job_id: Optional job id to use. If this is not provided, a random id of the format 'job-################YYMMDD' will be generated, where # is alphanumeric and YYMMDD is the current year, month, and day. params_list: Parameter sweeps to run with the program. There must be one Sweepable object for each circuit in the batch. If this is None, it is assumed that the circuits are not parameterized and do not require sweeps. repetitions: The number of circuit repetitions to run. processor_ids: The engine processors that should be candidates to run the program. Only one of these will be scheduled for execution. description: An optional description to set on the job. labels: Optional set of labels to set on the job. Returns: An EngineJob. If this is iterated over it returns a list of TrialResults. All TrialResults for the first circuit are listed first, then the TrialResults for the second, etc. The TrialResults for a circuit are listed in the order imposed by the associated parameter sweep. Raises: ValueError: if the program was not a batch program or no processors were supplied. """ import cirq_google.engine.engine as engine_base if self.result_type != ResultType.Batch: raise ValueError('Can only use run_batch() in batch mode.') if params_list is None: params_list = [None] * self.batch_size() if not job_id: job_id = engine_base._make_random_id('job-') if not processor_ids: raise ValueError('No processors specified') # Pack the run contexts into batches batch_context = v2.batch_run_context_to_proto( (params, repetitions) for params in params_list) created_job_id, job = await self.context.client.create_job_async( project_id=self.project_id, program_id=self.program_id, job_id=job_id, processor_ids=processor_ids, run_context=util.pack_any(batch_context), description=description, labels=labels, ) return engine_job.EngineJob( self.project_id, self.program_id, created_job_id, self.context, job, result_type=ResultType.Batch, )