def execute(self, executable: QuantumExecutable) -> QVMExecuteResponse: """ Synchronously execute the input program to completion. """ executable = executable.copy() if not isinstance(executable, Program): raise TypeError( f"`QVM#executable` argument must be a `Program`; got {type(executable)}" ) result_memory = {} for region in executable.declarations.keys(): result_memory[region] = np.ndarray((executable.num_shots, 0), dtype=np.int64) trials = executable.num_shots classical_addresses = get_classical_addresses_from_program(executable) if self.noise_model is not None: executable = apply_noise_model(executable, self.noise_model) executable._set_parameter_values_at_runtime() request = qvm_run_request( executable, classical_addresses, trials, self.measurement_noise, self.gate_noise, self.random_seed, ) response = self._qvm_client.run_program(request) ram = {key: np.array(val) for key, val in response.results.items()} result_memory.update(ram) return QVMExecuteResponse(executable=executable, memory=result_memory)
def execute(self, executable: QuantumExecutable) -> QPUExecuteResponse: """ Enqueue a job for execution on the QPU. Returns a ``QPUExecuteResponse``, a job descriptor which should be passed directly to ``QPU.get_result`` to retrieve results. """ executable = executable.copy() assert isinstance( executable, EncryptedProgram ), "QPU#execute requires an rpcq.EncryptedProgram. Create one with QuantumComputer#compile" assert ( executable.ro_sources is not None ), "To run on a QPU, a program must include ``MEASURE``, ``CAPTURE``, and/or ``RAW-CAPTURE`` instructions" request = RunProgramRequest( id=str(uuid.uuid4()), priority=self.priority, program=executable.program, patch_values=self._build_patch_values(executable), ) job_id = self._qpu_client.run_program(request).job_id return QPUExecuteResponse(_executable=executable, job_id=job_id)