From 4bdcc20f530ea3e2d0061da3701eaaf5a84e618b Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Thu, 16 Nov 2023 17:47:30 -0500 Subject: [PATCH] Fix use_symengine ScheduleBlock --- qiskit/qpy/binary_io/schedules.py | 7 ++++--- releasenotes/notes/platform-support-f7f693aaf5dec044.yaml | 6 ++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/qiskit/qpy/binary_io/schedules.py b/qiskit/qpy/binary_io/schedules.py index b0615a3ce966..ce22702c89da 100644 --- a/qiskit/qpy/binary_io/schedules.py +++ b/qiskit/qpy/binary_io/schedules.py @@ -104,12 +104,13 @@ def _read_discriminator(file_obj, version): def _loads_symbolic_expr(expr_bytes, use_symengine=False): if expr_bytes == b"": return None + expr_bytes = zlib.decompress(expr_bytes) if use_symengine: - return load_basic(zlib.decompress(expr_bytes)) + return load_basic(expr_bytes) else: from sympy import parse_expr - expr_txt = zlib.decompress(expr_bytes).decode(common.ENCODE) + expr_txt = expr_bytes.decode(common.ENCODE) expr = parse_expr(expr_txt) return sym.sympify(expr) @@ -472,7 +473,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) diff --git a/releasenotes/notes/platform-support-f7f693aaf5dec044.yaml b/releasenotes/notes/platform-support-f7f693aaf5dec044.yaml index 2f31d26035a4..9894895e8467 100644 --- a/releasenotes/notes/platform-support-f7f693aaf5dec044.yaml +++ b/releasenotes/notes/platform-support-f7f693aaf5dec044.yaml @@ -26,3 +26,9 @@ upgrade: build Qiskit from source while the Qiskit MSRV (minimum supported Rust version) is < 1.74, but the precompiled binaries published to PyPI will only be compatible with macOS >= 10.12. + +fixes: + - | + Fixed an issue with :class:`.qpy.dump` which would cause the function to + potentially ignore the value of ``use_symengine`` when serializing a + :class:`.ScheduleBlock` object.