qiskit-ibm-runtime
qiskit-ibm-runtime copied to clipboard
Stop allow setting flat option
What is the expected feature or enhancement?
The primitives today allow setting a nested option by itself. For example,
estimator.options.update(extrapolator="linear")
is allowed and would update the "correct" option in ZneOptions
. However, this only works if all options have unique names, which is no longer true in V2 primitives. So setting something like num_randomizations
could yield unexpected results.
Acceptance criteria
Only accept nested options in options.update()
.
Here is a pattern for BaseModel
def update(self, **fields):
"""Perform recursive update."""
for key, value in fields.items():
# Update nested field
if isinstance(getattr(self, key, None), BaseModel):
getattr(self, key).update(**value)
else:
setattr(self, key, value)
which could be adapted to our options with https://docs.pydantic.dev/latest/api/dataclasses/#pydantic.dataclasses.is_pydantic_dataclass
estimator.options.update(twirling={"enable_gates": True})