From 09f6ef499f514c796bd3ba2c5f9daa58c1c47289 Mon Sep 17 00:00:00 2001 From: Marquess Valdez Date: Fri, 8 Mar 2024 09:52:57 -0800 Subject: [PATCH] bubble up the API to QuantumComputer --- docs/source/programs_and_gates.rst | 9 +++------ pyquil/api/_qam.py | 3 +-- pyquil/api/_quantum_computer.py | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/docs/source/programs_and_gates.rst b/docs/source/programs_and_gates.rst index 76cf1f47f..e4a15b503 100644 --- a/docs/source/programs_and_gates.rst +++ b/docs/source/programs_and_gates.rst @@ -364,13 +364,10 @@ filled in for, say, 200 values between :math:`0` and :math:`2\pi`. We demonstrat # Generate a memory map for each set of parameters we want to execute with memory_maps = [{"theta": [theta] for theta in np.linspace(0, 2 * np.pi, 200)}] - # Begin batch execution of the program using each set of parameters. - # This returns a list of references to each job, the length and order of which correspond to the memory maps we + # Batch execute of the program using each set of parameters. + # This returns a list of results for each execution, the length and order of which correspond to the memory maps we # pass in. - handles = qc.execute_with_memory_map_batch(executable, memory_maps) - - # Use the handles to gather the results - parametric_measurements = [qc.get_result(handles) for handle in handles] + parametric_measurements = qc.run_with_memory_map_batch(executable, memory_maps) .. note:: diff --git a/pyquil/api/_qam.py b/pyquil/api/_qam.py index 74c346ebc..51974839c 100644 --- a/pyquil/api/_qam.py +++ b/pyquil/api/_qam.py @@ -157,8 +157,7 @@ def execute_with_memory_map_batch( How these programs are batched and executed is determined by the executor. See their respective documentation for details. - Returns a list of ``QAMExecutionResult``, which can be used to fetch - results in ``QAM#get_result``. + Returns a list of handles that can be used to fetch results with ``QAM#get_result``. """ @abstractmethod diff --git a/pyquil/api/_quantum_computer.py b/pyquil/api/_quantum_computer.py index 7a9be95c7..bf52ed1c8 100644 --- a/pyquil/api/_quantum_computer.py +++ b/pyquil/api/_quantum_computer.py @@ -24,6 +24,7 @@ Any, Tuple, Iterator, + Iterable, Optional, Set, Union, @@ -141,6 +142,22 @@ def run( """ return self.qam.run(executable, memory_map, **kwargs) + def run_with_memory_map_batch( + self, executable: QuantumExecutable, memory_maps: Iterable[MemoryMap], **kwargs: Any + ) -> List[QAMExecutionResult]: + """ + Run a QuantumExecutable with one or more memory_maps, returning a list of results corresponding to the length + and order of the given MemoryMaps. + + How these programs are batched and executed is determined by the executor. See their respective documentation + for details. + + Returns a list of ``QAMExecutionResult``, which can be used to fetch + results in ``QAM#get_result``. + """ + handles = self.qam.execute_with_memory_map_batch(executable, memory_maps, **kwargs) + return [self.qam.get_result(handle) for handle in handles] + def calibrate(self, experiment: Experiment) -> List[ExperimentResult]: """ Perform readout calibration on the various multi-qubit observables involved in the provided