Skip to content

Commit

Permalink
fix: Compatibility layer will prefer to return DelayFrames, then Dela…
Browse files Browse the repository at this point in the history
…yQubits, then Delay. (#1731)

Co-authored-by: Matthew Coolbeth <mcoolbeth@rigetti.com>
  • Loading branch information
mac01021 and Matthew Coolbeth authored Feb 5, 2024
1 parent 3f93e46 commit 813a067
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
8 changes: 3 additions & 5 deletions pyquil/quilbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,11 @@ def _convert_to_py_instruction(instr: Any) -> AbstractInstruction:
if isinstance(instr, quil_rs.Declaration):
return Declare._from_rs_declaration(instr)
if isinstance(instr, quil_rs.Delay):
print("len(instr.qubits):", len(instr.qubits))
print("len(instr.frame_names):", len(instr.frame_names))
if len(instr.qubits) > 0 and len(instr.frame_names) > 0:
return Delay._from_rs_delay(instr)
if len(instr.frame_names) > 0:
return DelayFrames._from_rs_delay(instr)
if len(instr.qubits) > 0:
return DelayQubits._from_rs_delay(instr)
return DelayFrames._from_rs_delay(instr)
return Delay._from_rs_delay(instr)
if isinstance(instr, quil_rs.Fence):
if len(instr.qubits) == 0:
return FenceAll()
Expand Down
33 changes: 27 additions & 6 deletions test/unit/test_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@

from pyquil import Program
from pyquil.quil import AbstractInstruction, Declare, Measurement
from pyquil.quilbase import Reset, ResetQubit, Delay, DelayFrames, DelayQubits, Frame
from pyquil.quilatom import Label, MemoryReference
from pyquil.quilbase import Reset, ResetQubit, Delay, DelayFrames, DelayQubits, Frame, \
DefMeasureCalibration
from pyquil.quilatom import Label, MemoryReference, Qubit
from pyquil.experiment._program import (
measure_qubits,
parameterized_single_qubit_measurement_basis,
parameterized_single_qubit_state_preparation,
parameterized_readout_symmetrization,
)
from pyquil.gates import MEASURE, RX, RZ, H
from pyquil.gates import MEASURE, RX, RZ, H, DELAY


def test_measure_qubits():
Expand Down Expand Up @@ -180,13 +181,33 @@ def test_compatibility_layer():
ResetQubit(0),
Reset(),
Delay([Frame([0], "frame")], [0], 0.01),
DelayFrames([Frame([], "frame")], 0.01),
DelayFrames([Frame([0], "frame")], 0.01),
DelayQubits([0, 1], 0.01),
]
program = Program(instructions)
for (original, transformed) in zip(instructions, program):
assert isinstance(transformed, AbstractInstruction)
print("type(transformed):", type(transformed))
print("type(original):", type(original))
assert isinstance(transformed, type(original))
assert transformed == original

defmeascal = DefMeasureCalibration(
Qubit(0),
MemoryReference("foo"),
instructions
)
for original, transformed in zip(instructions, defmeascal.instrs):
assert isinstance(transformed, AbstractInstruction)
assert isinstance(transformed, type(original))
assert transformed == original


def test_delay_conversions():
f = Frame([Qubit(0)], "hi")

i = DELAY(f, 7)
assert isinstance(i, DelayFrames)
p = Program()
p += i
p += DelayFrames([f], 8)
for x in p:
assert isinstance(x, DelayFrames), type(x)

0 comments on commit 813a067

Please sign in to comment.