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 issue with ScheduleBlock qpy serialization and use_symengine #11261

Merged
merged 5 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion qiskit/qpy/binary_io/schedules.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ def _dumps_operand(operand, use_symengine):
def _write_element(file_obj, element, metadata_serializer, use_symengine):
if isinstance(element, ScheduleBlock):
common.write_type_key(file_obj, type_keys.Program.SCHEDULE_BLOCK)
write_schedule_block(file_obj, element, metadata_serializer)
write_schedule_block(file_obj, element, metadata_serializer, use_symengine)
else:
type_key = type_keys.ScheduleInstruction.assign(element)
common.write_type_key(file_obj, type_key)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
fixes:
- |
Fixed an issue with :class:`.qpy.dump` which would cause the function to
mtreinish marked this conversation as resolved.
Show resolved Hide resolved
potentially ignore the value of ``use_symengine`` when serializing a
:class:`.ScheduleBlock` object.
29 changes: 27 additions & 2 deletions test/python/qpy/test_block_load_from_qpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@
class QpyScheduleTestCase(QiskitTestCase):
"""QPY schedule testing platform."""

def assert_roundtrip_equal(self, block):
def assert_roundtrip_equal(self, block, use_symengine=False):
"""QPY roundtrip equal test."""
qpy_file = io.BytesIO()
dump(block, qpy_file)
dump(block, qpy_file, use_symengine=use_symengine)
qpy_file.seek(0)
new_block = load(qpy_file)[0]

Expand Down Expand Up @@ -278,6 +278,31 @@ def test_bell_schedule(self):

self.assert_roundtrip_equal(test_sched)

@unittest.skipUnless(_optional.HAS_SYMENGINE, "Symengine required for this test")
def test_bell_schedule_use_symengine(self):
"""Test complex schedule to create a Bell state."""
with builder.build() as test_sched:
with builder.align_sequential():
# H
builder.shift_phase(-1.57, DriveChannel(0))
builder.play(Drag(160, 0.05, 40, 1.3), DriveChannel(0))
builder.shift_phase(-1.57, DriveChannel(0))
# ECR
with builder.align_left():
builder.play(GaussianSquare(800, 0.05, 64, 544), DriveChannel(1))
builder.play(GaussianSquare(800, 0.22, 64, 544, 2), ControlChannel(0))
builder.play(Drag(160, 0.1, 40, 1.5), DriveChannel(0))
with builder.align_left():
builder.play(GaussianSquare(800, -0.05, 64, 544), DriveChannel(1))
builder.play(GaussianSquare(800, -0.22, 64, 544, 2), ControlChannel(0))
builder.play(Drag(160, 0.1, 40, 1.5), DriveChannel(0))
# Measure
with builder.align_left():
builder.play(GaussianSquare(8000, 0.2, 64, 7744), MeasureChannel(0))
builder.acquire(8000, AcquireChannel(0), MemorySlot(0))

self.assert_roundtrip_equal(test_sched, True)

def test_with_acquire_instruction_with_kernel(self):
"""Test a schedblk with acquire instruction with kernel."""
kernel = Kernel(
Expand Down