Skip to content

Commit

Permalink
fix: The DefMeasureCalibration class returns pyQuil `AbstractInstru…
Browse files Browse the repository at this point in the history
…tcion`s instead of `quil` `Instruction`s
  • Loading branch information
MarquessV committed Aug 13, 2024
1 parent 94ab799 commit 6120f33
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
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

0 comments on commit 6120f33

Please sign in to comment.