Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deprecated property to DefFrame for CHANNEL-DELAY attribute #1729

Merged
merged 4 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions pyquil/quilbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -2858,6 +2858,22 @@ def center_frequency(self) -> Frame:
def center_frequency(self, center_frequency: float) -> None:
self.set_attribute("CENTER-FREQUENCY", center_frequency)

@property
@deprecated(
version="4.0",
reason="Quil now supports generic key/value pairs in DEFFRAMEs. Use get_attribute('CHANNEL-DELAY') instead.",
)
def channel_delay(self) -> Frame:
return self.get_attribute("CHANNEL-DELAY") # type: ignore

@channel_delay.setter
@deprecated(
version="4.0",
reason="Quil now supports generic key/value pairs in DEFFRAMEs. Use set_attribute('CHANNEL-DELAY') instead.",
)
def channel_delay(self, channel_delay: float) -> None:
self.set_attribute("CHANNEL-DELAY", channel_delay)

def __copy__(self) -> Self:
return self

Expand Down
2 changes: 2 additions & 0 deletions test/unit/__snapshots__/test_quilbase.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@
# name: TestDefFrame.test_out[With-Optionals].1
set({
'\tCENTER-FREQUENCY: 440',
'\tCHANNEL-DELAY: 0',
'\tDIRECTION: "direction"',
'\tHARDWARE-OBJECT: "hardware_object"',
'\tINITIAL-FREQUENCY: 1.39',
Expand All @@ -215,6 +216,7 @@
# name: TestDefFrame.test_str[With-Optionals].1
set({
'\tCENTER-FREQUENCY: 440',
'\tCHANNEL-DELAY: 0',
'\tDIRECTION: "direction"',
'\tHARDWARE-OBJECT: "hardware_object"',
'\tINITIAL-FREQUENCY: 1.39',
Expand Down
63 changes: 31 additions & 32 deletions test/unit/test_quilbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,10 +474,10 @@ def test_copy(self, measurement: Measurement):


@pytest.mark.parametrize(
("frame", "direction", "initial_frequency", "hardware_object", "sample_rate", "center_frequency"),
("frame", "direction", "initial_frequency", "hardware_object", "sample_rate", "center_frequency", "channel_delay"),
[
(Frame([Qubit(0)], "frame"), None, None, None, None, None),
(Frame([Qubit(1)], "frame"), "direction", 1.39, "hardware_object", 44.1, 440.0),
(Frame([Qubit(0)], "frame"), None, None, None, None, None, None),
(Frame([Qubit(1)], "frame"), "direction", 1.39, "hardware_object", 44.1, 440.0, 0.0),
],
ids=("Frame-Only", "With-Optionals"),
)
Expand All @@ -491,13 +491,22 @@ def def_frame(
hardware_object: Optional[str],
sample_rate: Optional[float],
center_frequency: Optional[float],
):
optional_args = [
arg
for arg in [direction, initial_frequency, hardware_object, sample_rate, center_frequency]
if arg is not None
]
return DefFrame(frame, *optional_args)
channel_delay: Optional[float],
) -> DefFrame:
optional_args = {k: v
for k, v in locals().items()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is probably more python magic than we want or need

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disenchanted it.

if k not in["self", "frame"] and v is not None}
# optional_args = [
# arg
# for arg in [direction,
# initial_frequency,
# hardware_object,
# sample_rate,
# center_frequency,
# channel_delay]:
# if arg is not None
# ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need these comments?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed them!

return DefFrame(frame, **optional_args)

def test_out(self, def_frame: DefFrame, snapshot: SnapshotAssertion):
# The ordering of attributes isn't stable and can be printed in different orders across calls.
Expand All @@ -509,6 +518,7 @@ def test_out(self, def_frame: DefFrame, snapshot: SnapshotAssertion):

def test_str(self, def_frame: DefFrame, snapshot: SnapshotAssertion):
quil_lines = str(def_frame).splitlines()
print(quil_lines)
assert quil_lines[0] == snapshot
assert set(quil_lines[1:]) == snapshot

Expand All @@ -518,51 +528,40 @@ def test_frame(self, def_frame: DefFrame, frame: Frame):
assert def_frame.frame == Frame([Qubit(123)], "new_frame")

def test_direction(self, def_frame: DefFrame, direction: Optional[str]):
assert def_frame.direction == direction is None if not direction else def_frame["DIRECTION"]
assert def_frame.direction == direction
def_frame.direction = "tx"
assert def_frame.direction == "tx"

def test_initial_frequency(self, def_frame: DefFrame, initial_frequency: Optional[float]):
assert (
def_frame.initial_frequency == initial_frequency is None
if not initial_frequency
else def_frame["INITIAL-FREQUENCY"]
)
assert def_frame.initial_frequency == initial_frequency
def_frame.initial_frequency = 3.14
assert def_frame.initial_frequency == 3.14

def test_hardware_object(self, def_frame: DefFrame, hardware_object: Optional[str]):
assert (
def_frame.hardware_object == hardware_object is None
if not hardware_object
else def_frame["HARDWARE-OBJECT"]
)
assert def_frame.hardware_object == hardware_object
def_frame.hardware_object = "bfg"
assert def_frame.hardware_object == "bfg"

def test_hardware_object_json(self, def_frame: DefFrame, hardware_object: Optional[str]):
assert (
def_frame.hardware_object == hardware_object is None
if not hardware_object
else def_frame["HARDWARE-OBJECT"]
)
assert def_frame.hardware_object == hardware_object
def_frame.hardware_object = '{"string": "str", "int": 1, "float": 3.14}'
assert def_frame.hardware_object == '{"string": "str", "int": 1, "float": 3.14}'

def test_sample_rate(self, def_frame: DefFrame, sample_rate: Optional[float]):
assert def_frame.sample_rate == sample_rate is None if not sample_rate else def_frame["SAMPLE-RATE"]
assert def_frame.sample_rate == sample_rate
def_frame.sample_rate = 96.0
assert def_frame.sample_rate == 96.0

def test_center_frequency(self, def_frame: DefFrame, center_frequency: Optional[float]):
assert (
def_frame.center_frequency == center_frequency is None
if not center_frequency
else def_frame.center_frequency
)
assert def_frame.center_frequency == center_frequency
def_frame.center_frequency = 432.0
assert def_frame.center_frequency == 432.0

def test_channel_delay(self, def_frame: DefFrame, channel_delay: Optional[float]):
assert def_frame.channel_delay == channel_delay
def_frame.channel_delay = 571.0
assert def_frame.channel_delay == 571.0

def test_copy(self, def_frame: DefFrame):
assert isinstance(copy.copy(def_frame), DefFrame)
assert isinstance(copy.deepcopy(def_frame), DefFrame)
Expand Down
Loading