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 encoding ParameterExpression #1536

Merged
merged 6 commits into from
Mar 28, 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
12 changes: 4 additions & 8 deletions qiskit_ibm_runtime/utils/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
from qiskit.utils import optionals
from qiskit.qpy import (
_write_parameter_expression,
_read_parameter_expression,
_read_parameter_expression_v3,
load,
dump,
Expand Down Expand Up @@ -331,13 +330,10 @@ class RuntimeDecoder(json.JSONDecoder):
def __init__(self, *args: Any, **kwargs: Any):
super().__init__(object_hook=self.object_hook, *args, **kwargs)
self.__parameter_vectors: Dict[str, Tuple[ParameterVector, set]] = {}
self.__read_parameter_expression = (
functools.partial(
_read_parameter_expression_v3,
vectors=self.__parameter_vectors,
)
if _TERRA_VERSION >= (0, 19, 1)
else _read_parameter_expression
self.__read_parameter_expression = functools.partial(
_read_parameter_expression_v3,
vectors=self.__parameter_vectors,
use_symengine=bool(optionals.HAS_SYMENGINE),
)

def object_hook(self, obj: Any) -> Any:
Expand Down
1 change: 1 addition & 0 deletions release-notes/unreleased/1521.bug.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed a bug with encoding/decoding ``ParameterExpression``
9 changes: 3 additions & 6 deletions test/unit/test_data_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import subprocess
import tempfile
import warnings
from unittest import skip
from datetime import datetime

import numpy as np
Expand Down Expand Up @@ -110,13 +109,12 @@ def test_coder_qc(self):
def test_coder_operators(self):
"""Test runtime encoder and decoder for operators."""

# TODO: Re-enable use of Parameter when #1521 is fixed.
# coeff_x = Parameter("x")
# coeff_y = coeff_x + 1
coeff_x = Parameter("x")
coeff_y = coeff_x + 1

subtests = (
SparsePauliOp(Pauli("XYZX"), coeffs=[2]),
# SparsePauliOp(Pauli("XYZX"), coeffs=[coeff_y]),
SparsePauliOp(Pauli("XYZX"), coeffs=[coeff_y]),
SparsePauliOp(Pauli("XYZX"), coeffs=[1 + 2j]),
Pauli("XYZ"),
)
Expand Down Expand Up @@ -178,7 +176,6 @@ def test_encoder_ndarray(self):
decoded = json.loads(encoded, cls=RuntimeDecoder)
self.assertTrue(np.array_equal(decoded["ndarray"], obj["ndarray"]))

@skip("Skip until qiskit-ibm-provider/736 is merged")
def test_encoder_instruction(self):
"""Test encoding and decoding instructions"""
subtests = (
Expand Down