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.04k stars 2.32k forks source link

Backend send options crash with None for tuple fields #9205

Open acastanedam opened 1 year ago

acastanedam commented 1 year ago

Environment

What is happening?

When passing a None tuple field the set_options routine crashes (and/or no raise an error)

How can we reproduce the issue?

Run:

from qiskit_ibm_runtime import QiskitRuntimeService                                                                                                                                                               

service = QiskitRuntimeService(channel="ibm_quantum")                                                                                                                                                             

backend = service.get_backend("ibm_lagos")                                                                                                                                                                        

_options = {'shots': 2000, 'memory': False, 'qubit_lo_freq': None, 'meas_lo_freq': None,                                                                                                                          
             'schedule_los': None, 'memory_slots': None, 'memory_slot_size': 100,                                                                                                                                  
             'rep_time': None, 'rep_delay': None, 'init_qubits': True}                                                                                                                                             

backend.set_options(**_options)

Get:

options.py", line 173, in update_options                                                              
    f"must be >={field_validator[0]} or <={field_validator[1]}"                                                                                                                                                    
TypeError: '>' not supported between instances of 'NoneType' and 'float'

What should happen?

The corresponding set option should be just skipped like the None's in other instance types of update_options

Any suggestions?

No response

ottoeretnaesehorn commented 1 year ago

I would like to work on this issue, if possible?

acastanedam commented 1 year ago

Hi @ottoeretnaesehorn, you can take a look in the PR #9204

jakelishman commented 1 year ago

It's not clear to me that this code snippet should be allowed. The backend you're using explicitly sets a validator on rep_delay that it must be a numeric type, but you're trying to set it to None. That should be an error.

That said, you're right that the error is not helpful (hence your not knowing what's happening) - the validation code in Options should probably check that the field is a number first before trying to do arithmetic on it.