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

TypeError: JSONDecoder.__init__() got an unexpected keyword argument 'encoding' #647

Closed
antalszava opened this issue May 31, 2023 · 4 comments
Assignees
Labels
type: bug Something isn't working
Milestone

Comments

@antalszava
Copy link

Information

  • qiskit-ibm-provider version: 0.6.0
  • Python version: 3.10
  • Operating system: Ubuntu

What is the current behavior?

Multiple remote simulators raise a json error: TypeError: JSONDecoder.__init__() got an unexpected keyword argument 'encoding'

This error comes up for "ibmq_qasm_simulator", "simulator_statevector" and maybe more.

Steps to reproduce the problem

from qiskit import QuantumCircuit, execute
from qiskit_ibm_provider import IBMProvider

circuit = QuantumCircuit(2)
circuit.h(0)
circuit.cx(0, 1)

provider = IBMProvider()
backend = provider.get_backend("simulator_statevector")

job = execute(circuit, backend)
result = job.result()
print(result.get_counts())

What is the expected behavior?

No error.

Suggested solutions

N/A

@antalszava antalszava added the type: bug Something isn't working label May 31, 2023
@kt474 kt474 self-assigned this May 31, 2023
@kt474
Copy link
Member

kt474 commented May 31, 2023

I believe this is the same issue as #528

@antalszava I was unable to replicate the issue with your code snippet - can you post the full error message with a job id?
Thanks!

@antalszava
Copy link
Author

Sure!

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[1], line 12
      9 backend = provider.get_backend("simulator_statevector")
     11 job = execute(circuit, backend)
---> 12 result = job.result()
     13 print(result.get_counts())

File ~/anaconda3/lib/python3.10/site-packages/qiskit_ibm_provider/job/ibm_circuit_job.py:242, in IBMCircuitJob.result(self, timeout, refresh)
    240 # pylint: disable=arguments-differ
    241 if self._result is None or refresh:
--> 242     self.wait_for_final_state(timeout=timeout)
    243     if self._status is JobStatus.CANCELLED:
    244         raise IBMJobInvalidStateError(
    245             "Unable to retrieve result for job {}. "
    246             "Job was cancelled.".format(self.job_id())
    247         )

File ~/anaconda3/lib/python3.10/site-packages/qiskit_ibm_provider/job/ibm_circuit_job.py:627, in IBMCircuitJob.wait_for_final_state(self, timeout)
    624     self._ws_client_future.result(timeout)
    625 # poll for status after stream has closed until status is final
    626 # because status doesn't become final as soon as stream closes
--> 627 status = self.status()
    628 while status not in JOB_FINAL_STATES:
    629     elapsed_time = time.time() - start_time

File ~/anaconda3/lib/python3.10/site-packages/qiskit_ibm_provider/job/ibm_circuit_job.py:350, in IBMCircuitJob.status(self)
    347     return self._status
    349 with api_to_job_error():
--> 350     api_response = self._runtime_client.job_get(self.job_id())["state"]
    351     # response state possibly has two values: status and reason
    352     # reason is not used in the current interface
    353     self._api_status = api_response["status"]

File ~/anaconda3/lib/python3.10/site-packages/qiskit_ibm_provider/api/clients/runtime.py:159, in RuntimeClient.job_get(self, job_id)
    150 def job_get(self, job_id: str) -> Dict:
    151     """Get job data.
    152 
    153     Args:
   (...)
    157         JSON response.
    158     """
--> 159     response = self._api.program_job(job_id).get()
    160     logger.debug("Runtime job get response: %s", response)
    161     return response

File ~/anaconda3/lib/python3.10/site-packages/qiskit_ibm_provider/api/rest/program_job.py:56, in ProgramJob.get(self)
     50 def get(self) -> Dict:
     51     """Return program job information.
     52 
     53     Returns:
     54         JSON response.
     55     """
---> 56     return self.session.get(self.get_url("self")).json(cls=RuntimeDecoder)

File ~/anaconda3/lib/python3.10/site-packages/requests/models.py:971, in Response.json(self, **kwargs)
    968             raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
    970 try:
--> 971     return complexjson.loads(self.text, **kwargs)
    972 except JSONDecodeError as e:
    973     # Catch JSON-related errors and raise as requests.JSONDecodeError
    974     # This aliases json.JSONDecodeError and simplejson.JSONDecodeError
    975     raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)

File ~/anaconda3/lib/python3.10/site-packages/simplejson/__init__.py:542, in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, use_decimal, **kw)
    540         raise TypeError("use_decimal=True implies parse_float=Decimal")
    541     kw['parse_float'] = Decimal
--> 542 return cls(encoding=encoding, **kw).decode(s)

File ~/anaconda3/lib/python3.10/site-packages/qiskit_ibm_provider/utils/json.py:264, in RuntimeDecoder.__init__(self, *args, **kwargs)
    263 def __init__(self, *args: Any, **kwargs: Any):
--> 264     super().__init__(object_hook=self.object_hook, *args, **kwargs)
    265     self.__parameter_vectors: Dict[str, Tuple[ParameterVector, set]] = {}
    266     self.__read_parameter_expression = (
    267         functools.partial(
    268             _read_parameter_expression_v3,
   (...)
    272         else _read_parameter_expression
    273     )

TypeError: JSONDecoder.__init__() got an unexpected keyword argument 'encoding'

@kt474
Copy link
Member

kt474 commented Jun 1, 2023

I explained in this comment #649 (comment) but I believe the issue is that you have the simplejson package installed in your environment. Uninstalling this package should resolve the issue.

@kt474
Copy link
Member

kt474 commented Jun 5, 2023

fixed by #649

@kt474 kt474 closed this as completed Jun 5, 2023
@kt474 kt474 added this to the 0.6.1 milestone Jun 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants