From 54a7e31dcf7c55bde6abbe4deb55e7aed00fe793 Mon Sep 17 00:00:00 2001 From: Mark Skilbeck Date: Tue, 15 Dec 2020 22:11:04 +0000 Subject: [PATCH 1/4] Remove some debug prints Oops --- pyquil/_parser/parser.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pyquil/_parser/parser.py b/pyquil/_parser/parser.py index 9fa1f7299..e1f11e432 100644 --- a/pyquil/_parser/parser.py +++ b/pyquil/_parser/parser.py @@ -94,8 +94,6 @@ def quil(self, instructions): @v_args(inline=True) def def_gate_matrix(self, name, variables, matrix): - print(name) - print(matrix) return DefGate(name, matrix=matrix, parameters=variables) @v_args(inline=True) From 4de0c208d7504c516eeaac40459cd0de5211d813 Mon Sep 17 00:00:00 2001 From: Mark Skilbeck Date: Wed, 16 Dec 2020 14:48:58 +0000 Subject: [PATCH 2/4] Perform calibration expansion locally in native_quil_to_executable --- pyquil/api/_compiler.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/pyquil/api/_compiler.py b/pyquil/api/_compiler.py index ac623c6bb..5640dde41 100644 --- a/pyquil/api/_compiler.py +++ b/pyquil/api/_compiler.py @@ -340,8 +340,17 @@ def quil_to_native_quil(self, program: Program, *, protoquil: Optional[bool] = N @_record_call def native_quil_to_executable( - self, nq_program: Program, *, debug: bool = False + self, nq_program: Program, *, debug: bool = False, expand_calibrations: bool = True, ) -> Optional[QuiltBinaryExecutableResponse]: + """ + Compile a native quil program to a binary executable. + + :param nq_program: Native quil to compile + :param debug: Include debug information in the response + :param expand_calibrations: Expand calibrations locally, + rather than expanding calibrations on the translation service + :return: An (opaque) binary executable + """ if not self.qpu_compiler_client: raise UserMessageError( "It looks like you're trying to compile to an executable, but " @@ -351,7 +360,10 @@ def native_quil_to_executable( self._connect_qpu_compiler() - arithmetic_response = rewrite_arithmetic(nq_program) + nq_program_calibrated = ( + self.expand_calibrations(nq_program) if expand_calibrations else nq_program + ) + arithmetic_response = rewrite_arithmetic(nq_program_calibrated) request = QuiltBinaryExecutableRequest( quilt=arithmetic_response.quil, num_shots=nq_program.num_shots @@ -363,6 +375,7 @@ def native_quil_to_executable( ), ) + # TODO(notmgsk): use nq_program_calibrated? response.recalculation_table = arithmetic_response.recalculation_table # type: ignore response.memory_descriptors = _collect_memory_descriptors(nq_program) @@ -425,6 +438,20 @@ def calibration_program(self) -> Program: else: return self._calibration_program + def expand_calibrations(self, program: Program, discard_defcals: bool = True) -> Program: + # Prepend the system's calibrations to the user's calibrations + calibrated_program = ( + self.calibration_program + program.copy_everything_except_instructions() + ) + for instruction in program: + calibrated_instruction = calibrated_program.calibrate(instruction) + calibrated_program.inst(calibrated_instruction) + + if discard_defcals: + calibrated_program._calibrations = [] + + return calibrated_program + @_record_call def reset(self) -> None: """ From 4a4b4a3b9571f358a69c47cb2aeb0887903728b0 Mon Sep 17 00:00:00 2001 From: Mark Skilbeck Date: Wed, 16 Dec 2020 14:56:07 +0000 Subject: [PATCH 3/4] Remove noisy warnings --- pyquil/api/_compiler.py | 7 ------- pyquil/api/_qpu.py | 6 ------ pyquil/tests/test_api.py | 2 +- 3 files changed, 1 insertion(+), 14 deletions(-) diff --git a/pyquil/api/_compiler.py b/pyquil/api/_compiler.py index 5640dde41..3b5487d05 100644 --- a/pyquil/api/_compiler.py +++ b/pyquil/api/_compiler.py @@ -351,13 +351,6 @@ def native_quil_to_executable( rather than expanding calibrations on the translation service :return: An (opaque) binary executable """ - if not self.qpu_compiler_client: - raise UserMessageError( - "It looks like you're trying to compile to an executable, but " - "do not have access to the QPU compiler endpoint. Make sure you " - "are engaged to the QPU before trying to do this." - ) - self._connect_qpu_compiler() nq_program_calibrated = ( diff --git a/pyquil/api/_qpu.py b/pyquil/api/_qpu.py index 1fdf90b58..4a323a35c 100644 --- a/pyquil/api/_qpu.py +++ b/pyquil/api/_qpu.py @@ -15,7 +15,6 @@ ############################################################################## from collections import defaultdict import uuid -import warnings from typing import Any, Dict, List, Optional, Tuple, Union, cast import numpy as np @@ -259,11 +258,6 @@ def run(self, run_priority: Optional[int] = None) -> "QPU": for name, array in extracted.items(): self._memory_results[name] = array elif not ro_sources: - warnings.warn( - "You are running a QPU program with no MEASURE instructions. " - "The result of this program will always be an empty array. Are " - "you sure you didn't mean to measure some of your qubits?" - ) self._memory_results["ro"] = np.zeros((0, 0), dtype=np.int64) self._last_results = results diff --git a/pyquil/tests/test_api.py b/pyquil/tests/test_api.py index beb7923e1..62838c86f 100644 --- a/pyquil/tests/test_api.py +++ b/pyquil/tests/test_api.py @@ -321,7 +321,7 @@ def test_quil_to_native_quil(compiler): @pytest.mark.skip(reason="Deprecated.") -def test_native_quil_to_binary(server, mock_qpu_compiler): +def test_native_quil_to_executable(server, mock_qpu_compiler): p = COMPILED_BELL_STATE.copy() p.wrap_in_numshots_loop(10) response = mock_qpu_compiler.native_quil_to_executable(p) From fb529b6ec422e77960a72803f93842cc7f24f966 Mon Sep 17 00:00:00 2001 From: Mark Skilbeck Date: Wed, 16 Dec 2020 20:01:30 +0000 Subject: [PATCH 4/4] Ignore type check --- pyquil/api/_compiler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyquil/api/_compiler.py b/pyquil/api/_compiler.py index 3b5487d05..bd8c3b776 100644 --- a/pyquil/api/_compiler.py +++ b/pyquil/api/_compiler.py @@ -363,7 +363,7 @@ def native_quil_to_executable( ) response = cast( QuiltBinaryExecutableResponse, - self.qpu_compiler_client.call( + self.qpu_compiler_client.call( # type: ignore "native_quilt_to_binary", request, rpc_timeout=self.timeout ), )