Repository: rigetti/pyquil (Python)

Issue:
Support ENABLE-RAW-CAPTURE in DefFrames
Pre-Request Checklist
---------------------

- [ ] I am running the latest versions of pyQuil and the Forest SDK
- [ ] I checked to make sure that this feature has not already been requested

Issue Description
-----------------

If raw capture using Quil-T is going to require the inclusion of a new attribute `ENABLE-RAW-CAPTURE` inside of a frame definition, then pyquil should support that option.

Proposed Solution
-----------------

I propose to update the `DefFrame` class and the corresponding parsing and stringification logic so that

- A program text that includes the new attribute within a frame definition can be parsed and the attribute will appear in the resulting `DefFrame` value
- A `DefFrame` object can be constructed to include the new attribute
- A `DefFrame` object that includes the new attribute will be stringified accordingly.





Discussion:

Patch:
diff --git a/pyquil/_parser/grammar.lark b/pyquil/_parser/grammar.lark
index 9a5da3fff..56486041b 100644
--- a/pyquil/_parser/grammar.lark
+++ b/pyquil/_parser/grammar.lark
@@ -66,6 +66,7 @@ frame_spec : _NEWLINE_TAB frame_attr ":" ( expression | string )
             | "DIRECTION"
             | "HARDWARE-OBJECT"
             | "CENTER-FREQUENCY"
+            | "ENABLE-RAW-CAPTURE"
 
 def_waveform : "DEFWAVEFORM" waveform_name params ":" matrix
 
diff --git a/pyquil/_parser/parser.py b/pyquil/_parser/parser.py
index c8ebd28a8..e96d67df3 100644
--- a/pyquil/_parser/parser.py
+++ b/pyquil/_parser/parser.py
@@ -137,6 +137,7 @@ def def_frame(self, frame, *specs):
             "INITIAL-FREQUENCY": "initial_frequency",
             "SAMPLE-RATE": "sample_rate",
             "CENTER-FREQUENCY": "center_frequency",
+            "ENABLE-RAW-CAPTURE": "enable_raw_capture",
         }
         options = {}
 
diff --git a/pyquil/quilbase.py b/pyquil/quilbase.py
index 476602d8b..3fc4a6f01 100644
--- a/pyquil/quilbase.py
+++ b/pyquil/quilbase.py
@@ -1363,6 +1363,9 @@ class DefFrame(AbstractInstruction):
     center_frequency: Optional[float] = None
     """ The 'center' frequency of the frame, used for detuning arithmetic. """
 
+    enable_raw_capture: Optional[str] = None
+    """ A flag signalling that raw capture is enabled for this frame. """
+
     def out(self) -> str:
         r = f"DEFFRAME {self.frame.out()}"
         options = [
@@ -1371,6 +1374,7 @@ def out(self) -> str:
             (self.center_frequency, "CENTER-FREQUENCY"),
             (self.hardware_object, "HARDWARE-OBJECT"),
             (self.sample_rate, "SAMPLE-RATE"),
+            (self.enable_raw_capture, "ENABLE-RAW-CAPTURE"),
         ]
         if any(value for (value, name) in options):
             r += ":"


Test patch:
diff --git a/test/unit/test_parser.py b/test/unit/test_parser.py
index c0995c1fa..b4bf4a2fe 100644
--- a/test/unit/test_parser.py
+++ b/test/unit/test_parser.py
@@ -598,6 +598,22 @@ def test_parsing_defframe():
         "    INITIAL-FREQUENCY: 10\n",  # TODO: should this parse as a float?
         DefFrame(Frame([Qubit(0)], "rf"), sample_rate=2.0, initial_frequency=10),
     )
+    parse_equals(
+        'DEFFRAME 0 "rf":\n'
+        '    SAMPLE-RATE: 2.0\n'
+        '    INITIAL-FREQUENCY: 10\n'
+        '    ENABLE-RAW-CAPTURE: "true"',
+        DefFrame(
+            Frame([Qubit(0)], "rf"),
+            sample_rate=2.0,
+            initial_frequency=10,
+            enable_raw_capture="true",
+        ),
+    )
+    assert DefFrame(
+        Frame([Qubit(0)], "rf"), enable_raw_capture="true"
+    ).out() == 'DEFFRAME 0 "rf":\n    ENABLE-RAW-CAPTURE: "true"\n'
+
     with pytest.raises(UnexpectedToken) as excp:
         parse('DEFFRAME 0 "rf":\n' "    UNSUPPORTED: 2.0\n")