Qiskit / qiskit

Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.
https://www.ibm.com/quantum/qiskit
Apache License 2.0
5.1k stars 2.34k forks source link

Transpile error with dynamic circuit on backend #12642

Closed dhhoe closed 1 month ago

dhhoe commented 3 months ago

Environment

What is happening?

I get the following error: TranspilerError: "The control-flow construct 'if_else' is not supported by the backend." when running backend = service.get_backend(backend_name). This is from the code in cell [5] given at: https://github.com/derek-wang-ibm/coding-with-qiskit/blob/main/episode-5-dynamic-circuits.ipynb

How can we reproduce the issue?

Try running the code as noted above. The only thing I changed in the code was: backend_name = "ibm_sherbrooke" (since "ibm_cusco" as given in the original code is locked for me).

What should happen?

It should work as in Derek Wang's video: https://www.youtube.com/watch?v=QDPtcwhpQkE

Any suggestions?

I noticed a similar error was reported before but it said it was fixed: https://github.com/Qiskit/qiskit-ibm-runtime/issues/1253

chrisamirani commented 3 months ago

Hey @dhhoe I ran this fine on ibm_sherbrooke. Did you only try once?

dhhoe commented 3 months ago

@chrisamirani, I just tried it again and still get the error. Are you using Qiskit 1.1.0? I noticed in the video where it works, Derek is using v. 1.0.

chrisamirani commented 3 months ago

@chrisamirani, I just tried it again and still get the error. Are you using Qiskit 1.1.0? I noticed in the video where it works, Derek is using v. 1.0.

Yes I am on 1.1.0. hmm strange. can you post the full error log?

Correction: Actually while the job itself seemed to have been successful and the final cell ran without errors for me, I just checked the IBM jobs console for that job and saw this error Qpy to QASM conversion failed: OpenQASM 2 cannot represent 'if_else', which acts on 2 classical bits.

which is similar to the issue you're having. Could be a bug.

dhhoe commented 3 months ago

@chrisamirani, Here's the full error log:

TranspilerError Traceback (most recent call last) File c:\Users\dhhoe\Miniconda3\envs\qk-py312\Lib\site-packages\qiskit\transpiler\passmanager.py:463, in _replace_error..wrapper(*meth_args, *meth_kwargs) 462 try: --> 463 return meth(meth_args, **meth_kwargs) 464 except PassManagerError as ex:

File c:\Users\dhhoe\Miniconda3\envs\qk-py312\Lib\site-packages\qiskit\transpiler\passmanager.py:225, in PassManager.run(self, circuits, output_name, callback, num_processes) 223 callback = _legacy_style_callback(callback) --> 225 return super().run( 226 in_programs=circuits, 227 callback=callback, 228 output_name=output_name, 229 num_processes=num_processes, 230 )

File c:\Users\dhhoe\Miniconda3\envs\qk-py312\Lib\site-packages\qiskit\passmanager\passmanager.py:232, in BasePassManager.run(self, in_programs, callback, num_processes, kwargs) 230 if len(in_programs) == 1 or not should_run_in_parallel(num_processes): 231 out = [ --> 232 _run_workflow(program=program, pass_manager=self, callback=callback, kwargs) 233 for program in in_programs 234 ] 235 if len(in_programs) == 1 and not is_list:

File c:\Users\dhhoe\Miniconda3\envs\qk-py312\Lib\site-packages\qiskit\passmanager\passmanager.py:292, in _run_workflow(program, pass_manager, *kwargs) ... 463 return meth(meth_args, **meth_kwargs) 464 except PassManagerError as ex: --> 465 raise TranspilerError(ex.message) from ex

TranspilerError: "The control-flow construct 'if_else' is not supported by the backend."

chrisamirani commented 3 months ago

@dhhoe Thx. Now circling back to your original issue description when you say "The only thing I changed in the code was: backend_name = "ibm_sherbrooke"" , did you also happen to change the job_id later on to match the job_id produced in step 3?

dhhoe commented 3 months ago

@chrisamirani the error occurs in 'Step 2' in the code, so I don't get to 'Step 4' where I need to update the job_id. Thx for the help.

chrisamirani commented 3 months ago

@chrisamirani the error occurs in 'Step 2' in the code, so I don't get to 'Step 4' where I need to update the job_id. Thx for the help.

Yeah unfortunately I can't reproduce. Maybe other folks can help here. Good luck!

yaelbh commented 3 months ago

It sounds like a version mismatch. I'd update to the latest versions of qiskit-aer and qiskit-ibm-runtime.

dhhoe commented 3 months ago

@yaelbh okay, I updated qiskit from v. 1.1.0 to 1.1.1 and updated qiskit-ibm-runtime from v. 0.24.0 to v. 0.24.1 and it runs without errors now.

jsaroni commented 3 months ago

Just an additional comment that backend.operation_names lists the instruction names that the backend supports.

1ucian0 commented 1 month ago

Can we consider this issue fixed in 1.1.1?

dhhoe commented 1 month ago

Yes, the problem was solved once I upgraded from 1.1.0 to 1.1.1. Thanks. - DH

Loyola University Maryland Internal Use Only From: Luciano Bello @.> Sent: Wednesday, August 7, 2024 6:38 AM To: Qiskit/qiskit @.> Cc: David Hoe @.>; Mention @.> Subject: [EXTERNAL] Re: [Qiskit/qiskit] Transpile error with dynamic circuit on backend (Issue #12642)

EXTERNAL SENDER

Can we consider this issue fixed in 1.1.1?

- Reply to this email directly, view it on GitHubhttps://github.com/Qiskit/qiskit/issues/12642#issuecomment-2273161670, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ASIGRLRB75WYJ6FM7TM5SI3ZQH2IFAVCNFSM6AAAAABJWZ3F3GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENZTGE3DCNRXGA. You are receiving this because you were mentioned.Message ID: @.***>