From f6b31795549216e46fe34fccf57a46207234eb0a Mon Sep 17 00:00:00 2001 From: Marquess Valdez Date: Tue, 26 Mar 2024 14:45:45 -0700 Subject: [PATCH 1/4] fix: Program#out(calibrations=False) will not expand matching calibrations --- pyquil/api/_wavefunction_simulator.py | 5 +++-- pyquil/quil.py | 2 +- test/unit/test_quil.py | 22 ++++++++++++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/pyquil/api/_wavefunction_simulator.py b/pyquil/api/_wavefunction_simulator.py index abca2db2c..60197de75 100644 --- a/pyquil/api/_wavefunction_simulator.py +++ b/pyquil/api/_wavefunction_simulator.py @@ -26,7 +26,7 @@ ) from pyquil.gates import MOVE from pyquil.paulis import PauliSum, PauliTerm -from pyquil.quil import Program, percolate_declares +from pyquil.quil import Program from pyquil.quilatom import MemoryReference from pyquil.wavefunction import Wavefunction @@ -93,6 +93,7 @@ def wavefunction(self, quil_program: Program, memory_map: Optional[MemoryMap] = if memory_map is not None: quil_program = self.augment_program_with_memory_values(quil_program, memory_map) + print(quil_program.out(calibrations=False)) request = qvm.api.WavefunctionRequest( quil_program.out(calibrations=False), self.measurement_noise, @@ -230,4 +231,4 @@ def augment_program_with_memory_values( p += quil_program - return percolate_declares(p) + return p diff --git a/pyquil/quil.py b/pyquil/quil.py index 9daae5b7c..68bfed3e6 100644 --- a/pyquil/quil.py +++ b/pyquil/quil.py @@ -832,7 +832,7 @@ def out(self, *, calibrations: Optional[bool] = True) -> str: if calibrations: return self._program.to_quil() else: - return self._program.into_simplified().to_quil() + return self.remove_quil_t_instructions().out() @deprecated( version="4.0", diff --git a/test/unit/test_quil.py b/test/unit/test_quil.py index 9487c9809..b815ea102 100644 --- a/test/unit/test_quil.py +++ b/test/unit/test_quil.py @@ -1163,3 +1163,25 @@ def test_cached_frames(): p.inst(frames[1]) program_frames = p.frames assert program_frames == {frames[0].frame: frames[0], frames[1].frame: frames[1]} + + +def test_out_without_calibrations(): + quilt_program = Program( + """ +DEFCAL J 0: + RX(1.5707963267948966) 0 +DEFCAL MEASURE 0 addr: + FENCE 0 +""" + ) + quil_program = Program( + """ +DECLARE ro BIT[1] +J 0 +MEASURE 0 ro +""" + ) + + combined_program = quilt_program + quil_program + + assert combined_program.out(calibrations=False) == quil_program.out() From 71aba846c9523064e6f66952d17a589d5a01ad75 Mon Sep 17 00:00:00 2001 From: Marquess Valdez Date: Tue, 26 Mar 2024 14:52:05 -0700 Subject: [PATCH 2/4] remove debug print --- pyquil/api/_wavefunction_simulator.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pyquil/api/_wavefunction_simulator.py b/pyquil/api/_wavefunction_simulator.py index 60197de75..45419f7aa 100644 --- a/pyquil/api/_wavefunction_simulator.py +++ b/pyquil/api/_wavefunction_simulator.py @@ -93,7 +93,6 @@ def wavefunction(self, quil_program: Program, memory_map: Optional[MemoryMap] = if memory_map is not None: quil_program = self.augment_program_with_memory_values(quil_program, memory_map) - print(quil_program.out(calibrations=False)) request = qvm.api.WavefunctionRequest( quil_program.out(calibrations=False), self.measurement_noise, From ccfeb1739e0fa3b22f8dbba0869e380271aa6cd9 Mon Sep 17 00:00:00 2001 From: Marquess Valdez Date: Mon, 1 Apr 2024 14:42:50 -0700 Subject: [PATCH 3/4] dont filter all quil-t instructions --- pyquil/quil.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pyquil/quil.py b/pyquil/quil.py index 68bfed3e6..ae41ce981 100644 --- a/pyquil/quil.py +++ b/pyquil/quil.py @@ -832,7 +832,9 @@ def out(self, *, calibrations: Optional[bool] = True) -> str: if calibrations: return self._program.to_quil() else: - return self.remove_quil_t_instructions().out() + return self.filter_instructions( + lambda inst: not isinstance(inst, (DefCalibration, DefMeasureCalibration)) + ).out() @deprecated( version="4.0", From f3731bde77c801d1242ec28481f5e6b28d73de3b Mon Sep 17 00:00:00 2001 From: Marquess Valdez Date: Wed, 10 Apr 2024 09:37:58 -0700 Subject: [PATCH 4/4] add more instructions to test --- test/unit/test_quil.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/unit/test_quil.py b/test/unit/test_quil.py index b815ea102..a4ae6c502 100644 --- a/test/unit/test_quil.py +++ b/test/unit/test_quil.py @@ -1176,9 +1176,18 @@ def test_out_without_calibrations(): ) quil_program = Program( """ +DEFFRAME 0 1 "cphase": + DIRECTION: "tx" + INITIAL-FREQUENCY: 458935243.82547355 + CENTER-FREQUENCY: 375000000.0 + HARDWARE-OBJECT: "q0_ff" + SAMPLE-RATE: 1000000000.0 +DEFWAVEFORM another1: + 4,5 DECLARE ro BIT[1] J 0 MEASURE 0 ro +DELAY 0 """ )