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

RuntimeJobFailureError when using Sampler primitives with Grover's Algo + AmplificationProblem #688

Closed
svijaymurugan opened this issue Jan 29, 2023 · 4 comments
Labels
bug Something isn't working priority: high High priority issue (must have for current release)

Comments

@svijaymurugan
Copy link

Environment

  • Qiskit Terra version: 0.23.0
  • Python version: 3.8.10
  • Operating system: Windows 10

What is happening?

When using primitives to run Grover's Algorithm with AmplificationProblem and 6 or more qubits, a RuntimeJobFailureError within qiskit_ibm_runtime. The error refers to "ERROR Failed to execute program: init() missing 1 required positional argument: 'num_ctrl_qubits" which I believe to be the source of the issue.

After posting this on the Qiskit Slack, I came to know that there was an identical issue in the version prior to Qiskit Terra 0.23.0. (Here is the link: Qiskit/qiskit#9384).

There are no issues when using up to 5 qubits.

Here is the full error: "RuntimeJobFailureError: 'Unable to retrieve job result. Job cfbekknp2bp10gcfm4rg has failed:\n2023-01-29T21:49:06.663349527Z Setting up watches.\n2023-01-29T21:49:06.663401212Z Watches established.\n2023-01-29T21:49:08.604731099Z INFO: Started server process [7]\n2023-01-29T21:49:08.604771632Z INFO: Waiting for application startup.\n2023-01-29T21:49:08.604779753Z INFO: Application startup complete.\n2023-01-29T21:49:08.630436854Z INFO: Uvicorn running on http://127.0.0.1:8081/ (Press CTRL+C to quit)\n2023-01-29T21:51:14.353659088Z INFO: 127.0.0.1:40146 - "POST /run HTTP/1.1" 202 Accepted\n2023-01-29T21:51:14.416559828Z /opt/app-root/lib64/python3.9/site-packages/qiskit_ibm_runtime/qpy/interface.py:255: UserWarning: The qiskit version used to generate the provided QPY file, 0.23.0, is newer than the current qiskit version 0.22.4. This may result in an error if the QPY file uses instructions not present in this current qiskit version\n2023-01-29T21:51:14.416605057Z warnings.warn(\n2023-01-29T21:51:14.421473169Z webserver-starter - ERROR Failed to execute program: init() missing 1 required positional argument: 'num_ctrl_qubits'\n2023-01-29T21:51:14.421514588Z Traceback (most recent call last):\n2023-01-29T21:51:14.421524175Z File "/provider/server/main.py", line 60, in execute_program\n2023-01-29T21:51:14.421544270Z user_params=load_user_params(body.program_input_parameters_file, logger),\n2023-01-29T21:51:14.421555534Z File "/provider/programruntime/utils.py", line 49, in load_user_params\n2023-01-29T21:51:14.421565367Z user_params = json.loads(params, cls=ProgramRuntimeDecoder)\n2023-01-29T21:51:14.421575405Z File "/usr/lib64/python3.9/json/init.py", line 359, in loads\n2023-01-29T21:51:14.421584994Z return cls(**kw).decode(s)\n2023-01-29T21:51:14.421596182Z File "/usr/lib64/python3.9/json/decoder.py", line 337, in decode\n2023-01-29T21:51:14.421605648Z obj, end = self.raw_decode(s, idx=_w(s, 0).end())\n2023-01-29T21:51:14.421615083Z File "/usr/lib64/python3.9/json/decoder.py", line 353, in raw_decode\n2023-01-29T21:51:14.421626281Z obj, end = self.scan_once(s, idx)\n2023-01-29T21:51:14.421636027Z File "/provider/programruntime/utils.py", line 221, in object_hook\n2023-01-29T21:51:14.421645947Z return super().object_hook(obj)\n2023-01-29T21:51:14.421655067Z File "/opt/app-root/lib64/python3.9/site-packages/qiskit_ibm_runtime/utils/json.py", line 308, in object_hook\n2023-01-29T21:51:14.421664887Z return _decode_and_deserialize(obj_val, load)[0]\n2023-01-29T21:51:14.421674514Z File "/opt/app-root/lib64/python3.9/site-packages/qiskit_ibm_runtime/utils/json.py", line 134, in _decode_and_deserialize\n2023-01-29T21:51:14.421683715Z return deserializer(buff)\n2023-01-29T21:51:14.421494634Z /pod-data/ CLOSE_WRITE,CLOSE terminated\n2023-01-29T21:51:14.421693215Z File "/opt/app-root/lib64/python3.9/site-packages/qiskit_ibm_runtime/qpy/interface.py", line 278, in load\n2023-01-29T21:51:14.421725359Z loader( # type: ignore[no-untyped-call]\n2023-01-29T21:51:14.422198799Z File "/opt/app-root/lib64/python3.9/site-packages/qiskit_ibm_runtime/qpy/binary_io/circuits.py", line 1020, in read_circuit\n2023-01-29T21:51:14.422217879Z custom_operations = _read_custom_operations(file_obj, version, vectors)\n2023-01-29T21:51:14.422227202Z File "/opt/app-root/lib64/python3.9/site-packages/qiskit_ibm_runtime/qpy/binary_io/circuits.py", line 429, in _read_custom_operations\n2023-01-29T21:51:14.422237610Z definition_circuit = common.data_from_binary(\n2023-01-29T21:51:14.422247312Z File "/opt/app-root/lib64/python3.9/site-packages/qiskit_ibm_runtime/qpy/common.py", line 269, in data_from_binary\n2023-01-29T21:51:14.422256268Z obj = deserializer(container, **kwargs)\n2023-01-29T21:51:14.422265970Z File "/opt/app-root/lib64/python3.9/site-packages/qiskit_ibm_runtime/qpy/binary_io/circuits.py", line 1020, in read_circuit\n2023-01-29T21:51:14.422304557Z custom_operations = _read_custom_operations(file_obj, version, vectors)\n2023-01-29T21:51:14.422312045Z File "/opt/app-root/lib64/python3.9/site-packages/qiskit_ibm_runtime/qpy/binary_io/circuits.py", line 429, in _read_custom_operations\n2023-01-29T21:51:14.422320424Z definition_circuit = common.data_from_binary(\n2023-01-29T21:51:14.422328869Z File "/opt/app-root/lib64/python3.9/site-packages/qiskit_ibm_runtime/qpy/common.py", line 269, in data_from_binary\n2023-01-29T21:51:14.422336372Z obj = deserializer(container, **kwargs)\n2023-01-29T21:51:14.422344082Z File "/opt/app-root/lib64/python3.9/site-packages/qiskit_ibm_runtime/qpy/binary_io/circuits.py", line 1022, in read_circuit\n2023-01-29T21:51:14.422351224Z _read_instruction(\n2023-01-29T21:51:14.422359832Z File "/opt/app-root/lib64/python3.9/site-packages/qiskit_ibm_runtime/qpy/binary_io/circuits.py", line 281, in _read_instruction\n2023-01-29T21:51:14.422367789Z gate = gate_class(*params)\n2023-01-29T21:51:14.422375925Z TypeError: init() missing 1 required positional argument: 'num_ctrl_qubits'\n2023-01-29T21:51:14.424997165Z Termination marker file found. Kill process (7).\n2023-01-29T21:51:14.440811484Z Termination signal received, exited.\n2023-01-29T21:51:14.440851788Z /bin/bash: line 3: 7 Killed python -m uvicorn server.main:app --port 8081\n'"

How can we reproduce the issue?

from qiskit.quantum_info import Statevector
from qiskit.algorithms import AmplificationProblem
from qiskit.algorithms import Grover
from qiskit_ibm_runtime import QiskitRuntimeService, Sampler, Session, Options
from qiskit import IBMQ

service = QiskitRuntimeService()
my_token = [API Token]
provider = IBMQ.enable_account(my_token)
QiskitRuntimeService.save_account(channel='ibm_quantum', token=my_token, overwrite=True)

simulator_backend = service.backends(simulator=True)[0]

options = Options(resilience_level=0, optimization_level=0)

secret = 6 
secret_string = format(secret, f'0{secret}b')
oracle = Statevector.from_label(secret_string)

problem = AmplificationProblem(oracle, is_good_state=secret_string, objective_qubits=[i - 1])
iterations = Grover.optimal_num_iterations(1, i)

grover = Grover(iterations=iterations)

circuit = grover.construct_circuit(problem)
circuit.measure_all()

with Session(service=service, backend=simulator_backend) as session:
    sampler = Sampler(session=session, options=options)
    job = sampler.run(circuits=circuit, shots=1000)
    result = job.result()

What should happen?

This should run Grover's Algorithm on a database of 64 elements, searching for the "6" (or 000110) with no Error Mitigation or Optimization.

The end result should be a SamplerResult() object.

Any suggestions?

My only guess for where a num_ctrl_qubits parameter could not have been passed is somewhere within the MCXGate Class (as that's where I seemed to find reference to that parameter after some searching).

@svijaymurugan svijaymurugan added the bug Something isn't working label Jan 29, 2023
@Cryoris
Copy link
Contributor

Cryoris commented Jan 30, 2023

Since this occurs only with the runtime Sampler and not the reference Sampler running locally (qiskit.primitives.Sampler) I would assume that the fix for Qiskit/qiskit#9384 is not uploaded on the server side yet. For that fix to be effective it needs to be installed both locally, where the circuit is constructed and serialized, and on the server side, where the circuit is deserialized.

@jyu00 do you know if the server for runtime is running Terra 0.23 already? 🙂

@jakelishman
Copy link
Member

Runtime has a vendored version of QPY that's currently a bit out-of-date (see #577). The likely fix is for Runtime to pull Terra's updates in this case - @1ucian0, if you could transfer this issue over to Runtime that'd be great thanks.

@1ucian0 1ucian0 transferred this issue from Qiskit/qiskit Jan 30, 2023
@jyu00
Copy link
Collaborator

jyu00 commented Jan 30, 2023

fyi @ChitsimranGill Not pulse gate but another issue with downlevel qpy

@jyu00 jyu00 added the priority: high High priority issue (must have for current release) label Feb 3, 2023
@kt474
Copy link
Member

kt474 commented Feb 7, 2023

The server side qpy has been updated - tested the code snippet above and it's working now

@kt474 kt474 closed this as completed Feb 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority: high High priority issue (must have for current release)
Projects
None yet
Development

No branches or pull requests

5 participants