Repository: rigetti/pyquil

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:
kalzoo: IIRC, this should target `rc` instead
mac01021: I changed the target branch to `rc`.  Note that the PR description template contains a checklist that instructs you to target `master`.
kalzoo: > I changed the target branch to `rc`. Note that the PR description template contains a checklist that instructs you to target `master`.

Ah. Sorry @mac01021 - I was behind the times on this. We used to do it that way.
notmgsk: @mac01021 What _is_ missing from the PR template is that commits should use the [angular commit syntax](https://github.com/angular/angular/blob/22b96b9/CONTRIBUTING.md#-commit-message-guidelines). So your commit would be named some like `feat: add ENABLE-RAW-CAPTURE ...`.

Once that is fixed, good to merge.

Patch:
diff --git a/pyquil/_parser/grammar.lark b/pyquil/_parser/grammar.lark
index 9a5da3f..5648604 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 c8ebd28..e96d67d 100644
--- a/pyquil/_parser/parser.py
+++ b/pyquil/_parser/parser.py
@@ -137,6 +137,7 @@ class QuilTransformer(Transformer):  # type: ignore
             "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 476602d..3fc4a6f 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 @@ class DefFrame(AbstractInstruction):
             (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 c0995c1..b4bf4a2 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")