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

fix: The DefMeasureCalibration instructions property returns pyQuil AbstractInstrctions instead of quil Instructions #1799

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 9 additions & 0 deletions pyquil/quilbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -2843,6 +2843,15 @@ def instrs(self) -> list[AbstractInstruction]:
def instrs(self, instrs: list[AbstractInstruction]) -> None:
quil_rs.MeasureCalibrationDefinition.instructions.__set__(self, _convert_to_rs_instructions(instrs)) # type: ignore[attr-defined] # noqa

@property # type: ignore[override]
def instructions(self) -> list[AbstractInstruction]:
"""The instructions in the calibration."""
return self.instrs

@instructions.setter
def instructions(self, instructions: list[AbstractInstruction]) -> None:
self.instrs = instructions

def out(self) -> str:
"""Return the instruction as a valid Quil string."""
return super().to_quil()
Expand Down
17 changes: 15 additions & 2 deletions test/unit/test_quilbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,21 @@ def test_memory_reference(self, measure_calibration: DefMeasureCalibration, memo

def test_instrs(self, measure_calibration: DefMeasureCalibration, instrs: List[AbstractInstruction]):
assert measure_calibration.instrs == instrs
measure_calibration.instrs = [Gate("SomeGate", [], [Qubit(0)], [])]
assert measure_calibration.instrs == [Gate("SomeGate", [], [Qubit(0)], [])]
measure_calibration.instrs = [Gate("SomeGate", [], [Qubit(0)], []), Fence([0])]
assert isinstance(measure_calibration.instrs[0], Gate)
assert not isinstance(measure_calibration.instrs[0], Fence)
assert isinstance(measure_calibration.instrs[1], Fence)
assert not isinstance(measure_calibration.instrs[1], Gate)
assert measure_calibration.instrs == [Gate("SomeGate", [], [Qubit(0)], []), Fence([0])]

def test_instructions(self, measure_calibration: DefMeasureCalibration, instrs: List[AbstractInstruction]):
assert measure_calibration.instructions == instrs
measure_calibration.instrs = [Gate("SomeGate", [], [Qubit(0)], []), Fence([0])]
assert isinstance(measure_calibration.instrs[0], Gate)
assert not isinstance(measure_calibration.instrs[0], Fence)
assert isinstance(measure_calibration.instrs[1], Fence)
assert not isinstance(measure_calibration.instrs[1], Gate)
assert measure_calibration.instrs == [Gate("SomeGate", [], [Qubit(0)], []), Fence([0])]

def test_copy(self, measure_calibration: DefMeasureCalibration):
assert isinstance(copy.copy(measure_calibration), DefMeasureCalibration)
Expand Down
Loading