Qiskit-Extensions / qiskit-dynamics

Tools for building and solving models of quantum systems in Qiskit
https://qiskit-extensions.github.io/qiskit-dynamics/
Apache License 2.0
97 stars 60 forks source link

Ignore unknown options in `DynamicsBackend.run()` #356

Closed donsano33 closed 1 month ago

donsano33 commented 1 month ago

What is the expected behavior?

I want to 1-to-1 reuse code that runs QuantumCircuits on a DynamicsBackend as well as on a qiskit_ibm_runtime.IBMBackend via the run function. The problem is, that DynamicsBackend.run() does not allow options that are not explicitly mentioned in DynamicsBackend.set_options(), triggering a AttributeError implemented here: https://github.com/Qiskit-Extensions/qiskit-dynamics/blob/5d4f1b2b98a3adcef51b38238620e21d5e27f641/qiskit_dynamics/backend/dynamics_backend.py#L252

Taking for example the job_tags parameter, this forces me to workaround with something like this:

if isinstance(backend, DynamicsBackend):
    # Dynamics Backends can't handle the job_tags parameter
    job = backend.run(qcs, shots=shots)
else:
    job = backend.run(qcs, shots=shots, job_tags=job_tags)

In my ideal world I would be able to just use this line for both backends:

job = backend.run(qcs, shots=shots, job_tags=job_tags)

Would it be possible to change this behavior or was this an explicit design choice?

DanPuzzuoli commented 1 month ago

Closing based on discussion on slack. Summary is: gracefully handling the ignoring of certain arguments would require keeping track of what is okay and what is not, which would add too much maintenance complexity.