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) diff --git a/pyquil/api/_compiler.py b/pyquil/api/_compiler.py index ac623c6bb..bd8c3b776 100644 --- a/pyquil/api/_compiler.py +++ b/pyquil/api/_compiler.py @@ -340,29 +340,35 @@ 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]: - 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." - ) + """ + 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 + """ 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 ) response = cast( QuiltBinaryExecutableResponse, - self.qpu_compiler_client.call( + self.qpu_compiler_client.call( # type: ignore "native_quilt_to_binary", request, rpc_timeout=self.timeout ), ) + # 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 +431,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: """ 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)