Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Commit

Permalink
Handled parameterized circuits (#586)
Browse files Browse the repository at this point in the history
After Qiskit/qiskit#3383 the conversion of types outside the
standard set of types understood by the standard json encoder is the
responsibility of the ibmq provider. However, there was one type missing
from the custom encoder class added to handle this, ParameterExpression.
For bound parameterized circuit the ParameterExpression class will be
castable to a float to get the bound numeric value that should be sent
on the wire with the job. However, the encoder doesn't have handling for
this. Qiskit/qiskit#3959 is adding conversion for the to_dict()
qobj method so that floats are output, but this a stop gap workaround
while a better solution is being developed. We should have handling
in qiskit-ibmq-provider if/when ParameterExpression objects get passed
in via qobj object.
  • Loading branch information
mtreinish authored Mar 12, 2020
1 parent f547d64 commit 2c4d04d
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions qiskit/providers/ibmq/utils/json_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import json
from typing import Any

from qiskit.circuit.parameterexpression import ParameterExpression


class IQXJsonEconder(json.JSONEncoder):
"""A json encoder for qobj"""
Expand All @@ -30,4 +32,6 @@ def default(self, o: Any) -> Any:
# Use Qobj complex json format:
if isinstance(o, complex):
return (o.real, o.imag)
if isinstance(o, ParameterExpression):
return float(o)
return json.JSONEncoder.default(self, o)

0 comments on commit 2c4d04d

Please sign in to comment.