qiskit-ibm-runtime icon indicating copy to clipboard operation
qiskit-ibm-runtime copied to clipboard

Stop allow setting flat option

Open jyu00 opened this issue 11 months ago • 1 comments

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().

jyu00 avatar Mar 06 '24 20:03 jyu00

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})

ihincks avatar Mar 06 '24 23:03 ihincks