Qiskit / qiskit-ibm-runtime

IBM Client for Qiskit Runtime
https://docs.quantum.ibm.com/api/qiskit-ibm-runtime
Apache License 2.0
152 stars 154 forks source link

VQEProgram RuntimeJobFailureError when ansatz EfficientSU2() has no parameter specified #67

Closed patdenim closed 2 years ago

patdenim commented 2 years ago

Describe the bug VQEProgram fails when using ansatz = EfficientSU2() that does not have any parameter. This specific ansatz works well in classical VQE (i guess some parameter values are used by default when none is specified)

Error stack message:

Traceback (most recent call last):
  File "C:\Users\poc\Anaconda3\envs\qiskit\lib\site-packages\qiskit_nature\runtime\vqe_program.py", line 282, in compute_minimum_eigenvalue
    result = job.result()
  File "C:\Users\poc\Anaconda3\envs\qiskit\lib\site-packages\qiskit\providers\ibmq\runtime\runtime_job.py", line 151, in result
    raise RuntimeJobFailureError(f"Unable to retrieve job result. "
qiskit.providers.ibmq.runtime.exceptions.RuntimeJobFailureError: 'Unable to retrieve job result. Job c6kd626gkavn0ge25jng has failed:\n2021-12-02T14:08:52.305396155Z Traceback (most recent call last):\n2021-12-02T14:08:52.305396155Z   File "/code/program_starter.py", line 61, in <module>\n2021-12-02T14:08:52.305396155Z     user_params = json.loads(params, cls=RuntimeDecoder)\n2021-12-02T14:08:52.305396155Z   File "/usr/local/lib/python3.8/json/__init__.py", line 370, in loads\n2021-12-02T14:08:52.305396155Z     return cls(**kw).decode(s)\n2021-12-02T14:08:52.305396155Z   File "/usr/local/lib/python3.8/json/decoder.py", line 337, in decode\n2021-12-02T14:08:52.305396155Z     obj, end = self.raw_decode(s, idx=_w(s, 0).end())\n2021-12-02T14:08:52.305396155Z   File "/usr/local/lib/python3.8/json/decoder.py", line 353, in raw_decode\n2021-12-02T14:08:52.305396155Z     obj, end = self.scan_once(s, idx)\n2021-12-02T14:08:52.305396155Z   File "/usr/local/lib/python3.8/site-packages/qiskit/providers/ibmq/runtime/utils.py", line 229, in object_hook\n2021-12-02T14:08:52.305396155Z     return _decode_and_deserialize(obj_val, qpy_serialization.load)[0]\n2021-12-02T14:08:52.305396155Z   File "/usr/local/lib/python3.8/site-packages/qiskit/providers/ibmq/runtime/utils.py", line 87, in _decode_and_deserialize\n2021-12-02T14:08:52.305396155Z     orig = deserializer(buff)\n2021-12-02T14:08:52.305396155Z   File "/usr/local/lib/python3.8/site-packages/qiskit/circuit/qpy_serialization.py", line 1053, in load\n2021-12-02T14:08:52.305396155Z     circuits.append(_read_circuit(file_obj))\n2021-12-02T14:08:52.305396155Z   File "/usr/local/lib/python3.8/site-packages/qiskit/circuit/qpy_serialization.py", line 1154, in _read_circuit\n2021-12-02T14:08:52.305396155Z     circ = QuantumCircuit(\n2021-12-02T14:08:52.305396155Z   File "/usr/local/lib/python3.8/site-packages/qiskit/circuit/quantumcircuit.py", line 195, in __init__\n2021-12-02T14:08:52.305396155Z     self.add_register(*regs)\n2021-12-02T14:08:52.305396155Z   File "/usr/local/lib/python3.8/site-packages/qiskit/circuit/quantumcircuit.py", line 1167, in add_register\n2021-12-02T14:08:52.305396155Z     regs = (QuantumRegister(regs[0], "q"), ClassicalRegister(regs[1], "c"))\n2021-12-02T14:08:52.305396155Z   File "/usr/local/lib/python3.8/site-packages/qiskit/circuit/register.py", line 86, in __init__\n2021-12-02T14:08:52.305396155Z     raise CircuitError(\n2021-12-02T14:08:52.305396155Z qiskit.circuit.exceptions.CircuitError: "Register size must be positive (int \'0\' was provided)"\n'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File ".\minimal_example - vqeclient gss.py", line 64, in <module>
    result = ground_state_solver.solve(problem=problem)
  File "C:\Users\poc\Anaconda3\envs\qiskit\lib\site-packages\qiskit_nature\algorithms\ground_state_solvers\ground_state_eigensolver.py", line 111, in solve
    raw_mes_result = self._solver.compute_minimum_eigenvalue(main_operator, aux_ops)
  File "C:\Users\poc\Anaconda3\envs\qiskit\lib\site-packages\qiskit_nature\runtime\vqe_program.py", line 284, in compute_minimum_eigenvalue
    raise RuntimeError(f"The job {job.job_id()} failed unexpectedly.") from exc
RuntimeError: The job c6kd626gkavn0ge25jng failed unexpectedly.

Steps to reproduce ansatz = EfficientSU2() backend = provider.get_backend('ibmq_qasm_simulator') quantum_instance = QuantumInstance(backend=backend, optimization_level=3) optimizer = SPSA(maxiter=10) minimum_eigen_solver = VQEProgram( ansatz=ansatz, optimizer=optimizer, provider=provider, backend=backend ) result = ground_state_solver.solve(problem=problem)

Expected behavior

Suggested solutions Error message might be explicit or Runtime VQEProgram might use predefined default parameters

Additional Information

kt474 commented 2 years ago

VQEProgram has been deprecated and renamed to VQEClient link

Edit: When running VQE with no parameters (ansatz = EfficientSU2()) there is an error

ValueError: The dimension of the initial point (0) does not match the number of parameters in the circuit (32).

I'm getting the same error when running the real VQEProgram with no parameters

raise ValueError(\'Mismatching number of parameters and initial point dimension.\')\n2022-01-24T21:54:09.216710947Z ValueError: Mismatching number of parameters and initial point dimension.\n'

or depending on the other VQEProgram parameters

qiskit.algorithms.exceptions.AlgorithmError: \'The number of qubits of the ansatz does not match the operator, and the ansatz does not allow setting the number of qubits using `num_qubits`.\'\n'

kt474 commented 2 years ago

@patdenim I left some comments above - there should be a more detailed error message when ansatz = EfficientSU2() is used with no parameters