microsoft / microsoft/azure-quantum-python

JSONDecodeError when getting results via IonQ Backend if not measuring all qubits

Open
#227 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

azure-quantum bug help wanted python qiskit
Dominant language
Python
Stars
160
Forks
113
Avg merge
6d 23h
Merged PRs (30d)
1

Description

Sharing on behalf of @amirebrahimi:

I'm getting an error when calling job.result() from ionq.simulator. Details in thread.

---------------------------------------------------------------------------
JSONDecodeError                           Traceback (most recent call last)
/tmp/ipykernel_15433/1564545644.py in <module>
      1 # print(result)
----> 2 print(job.result())

/usr/local/lib/python3.7/site-packages/azure/quantum/qiskit/job.py in result(self, timeout)
     75 
     76         success = self._azure_job.details.status == "Succeeded"
---> 77         results = self._format_results()
     78 
     79         return Result.from_dict(

/usr/local/lib/python3.7/site-packages/azure/quantum/qiskit/job.py in _format_results(self)
    118 
    119             elif (self._azure_job.details.output_data_format == IONQ_OUTPUT_DATA_FORMAT):
--> 120                 job_result["data"] = self._format_ionq_results()
    121                 job_result["header"] = self._azure_job.details.metadata
    122 

/usr/local/lib/python3.7/site-packages/azure/quantum/qiskit/job.py in _format_ionq_results(self)
    140         if "meas_map" not in self._azure_job.details.metadata or "num_qubits" not in self._azure_job.details.metadata:
    141             raise ValueError(f"Job with ID {self.id()} does not have the required metadata to format IonQ results.")
--> 142         meas_map = json.loads(self._azure_job.details.metadata.get("meas_map"))
    143         num_qubits = self._azure_job.details.metadata.get("num_qubits")
    144 

/usr/local/lib/python3.7/json/__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    346             parse_int is None and parse_float is None and
    347             parse_constant is None and object_pairs_hook is None and not kw):
--> 348         return _default_decoder.decode(s)
    349     if cls is None:
    350         cls = JSONDecoder

/usr/local/lib/python3.7/json/decoder.py in decode(self, s, _w)
    335 
    336         """
--> 337         obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    338         end = _w(s, end).end()
    339         if end != len(s):

/usr/local/lib/python3.7/json/decoder.py in raw_decode(self, s, idx)
    353             obj, end = self.scan_once(s, idx)
    354         except StopIteration as err:
--> 355             raise JSONDecodeError("Expecting value", s, err.value) from None
    356         return obj, end

JSONDecodeError: Expecting value: line 1 column 14 (char 13)

A temporary fix: measure all your qubits
The problem is that meas_map may have None for any qubits you don't measure. which is breaking the parsing

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in azure/quantum/qiskit/job.py, especially _format_results and _format_ionq_results, and reproduce the failure with an IonQ job that does not measure every qubit. Check how meas_map is handled before JSON parsing. Done means job.result() formats results without JSONDecodeError for partially measured circuits.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.