documentation icon indicating copy to clipboard operation
documentation copied to clipboard

Tutorials using experimental options unncessarily

Open jyu00 opened this issue 1 month ago • 3 comments

URL to the relevant tutorial

https://quantum.cloud.ibm.com/docs/en/tutorials/krylov-quantum-diagonalization https://quantum.cloud.ibm.com/docs/en/tutorials/projected-quantum-kernels https://quantum.cloud.ibm.com/docs/en/tutorials/long-range-entanglement#step-3-execute-using-qiskit-primitives

Select all that apply

  • [ ] new content request
  • [ ] typo
  • [ ] code bug
  • [x] out-of-date content
  • [ ] broken link
  • [ ] other

Describe the fix or the content request.

The first 2 tutorials specify a bunch of Estimator options as "experimental", even though none of them is. The DC one uses gen3-experimental, which is no longer needed.

For new content requests - if the request is accepted, do you want to write the content?

I can help the team by providing enough information or by referring them to a specific Subject Matter Expert to write the material

jyu00 avatar Nov 17 '25 16:11 jyu00

@jyu00 something has change drastically in the estimator option configuration since the writing of the tutorial on krylov-quantum-diagonalization. using the experimental path makes the tutorial work in the intended way, what is your recommendation on how to replace this in the new format? I see a bunch of different Options objects (TwirlingOptions, NoiseLearnerOptions, ZNEOptions, etc.) how do we use them in a way that is closest to the original implementation (use a single dictionary to specify all your options and pass them to the estimator)?

miamico avatar Nov 18 '25 02:11 miamico

@jyu00 something has change drastically in the estimator option configuration since the writing of the tutorial on krylov-quantum-diagonalization. using the experimental path makes the tutorial work in the intended way, what is your recommendation on how to replace this in the new format? I see a bunch of different Options objects (TwirlingOptions, NoiseLearnerOptions, ZNEOptions, etc.) how do we use them in a way that is closest to the original implementation (use a single dictionary to specify all your options and pass them to the estimator)?

The fix is actually really easy, just replace experimental_opts with a regular option, e.g.

options = {}
options["resilience"] = {
    "measure_mitigation": True,
    "measure_noise_learning": { ...
   }
}
options["twirling"] = {...}

estimator = Estimator(mode=backend, options=options)

jyu00 avatar Nov 21 '25 17:11 jyu00

The above raises a bunch of errors, does it mean that some of these options are still experimental?

---------------------------------------------------------------------------
ValidationError                           Traceback (most recent call last)
Cell In[3], line 37
     29 experimental_opts["twirling"] = {
     30     "num_randomizations": num_randomizations,
     31     "shots_per_randomization": shots_per_randomization,
     32     "strategy": "active-accum",
     33 }
     34 # options = EstimatorOptions(experimental=experimental_opts)
     35 
     36 # We define and run the estimator to obtain <X>, <Y> and <Z> on all qubits
---> 37 estimator = Estimator(mode=backend, options=experimental_opts)

File ~/Workspace/documentation/.venv/lib/python3.14/site-packages/qiskit_ibm_runtime/estimator.py:125, in EstimatorV2.__init__(self, mode, options)
    122 BaseEstimatorV2.__init__(self)
    123 Estimator.__init__(self)
--> 125 BasePrimitiveV2.__init__(self, mode=mode, options=options)

File ~/Workspace/documentation/.venv/lib/python3.14/site-packages/qiskit_ibm_runtime/base_primitive.py:124, in BasePrimitiveV2.__init__(self, mode, options)
    107 """Initializes the primitive.
    108 
    109 Args:
   (...)    121     ValueError: Invalid arguments are given.
    122 """
    123 self._mode, self._service, self._backend = _get_mode_service_backend(mode)
--> 124 self._set_options(options)

File ~/Workspace/documentation/.venv/lib/python3.14/site-packages/qiskit_ibm_runtime/base_primitive.py:220, in BasePrimitiveV2._set_options(self, options)
    218 elif isinstance(options, dict):
    219     default_options = self._options_class()
--> 220     self._options = self._options_class(**merge_options_v2(default_options, options))
    222 elif isinstance(options, self._options_class):
    223     self._options = replace(options)

File ~/Workspace/documentation/.venv/lib/python3.14/site-packages/pydantic/_internal/_dataclasses.py:121, in complete_dataclass.<locals>.__init__(__dataclass_self__, *args, **kwargs)
    119 __tracebackhide__ = True
    120 s = __dataclass_self__
--> 121 s.__pydantic_validator__.validate_python(ArgsKwargs(args, kwargs), self_instance=s)

ValidationError: 4 validation errors for EstimatorOptions
resilience.function-after[_validate_options(), ResilienceOptionsV2].zne.function-after[_validate_options(), ZneOptions].return_all_extrapolated
  Unexpected keyword argument [type=unexpected_keyword_argument, input_value=True, input_type=bool]
    For further information visit https://errors.pydantic.dev/2.12/v/unexpected_keyword_argument
resilience.function-after[_validate_options(), ResilienceOptionsV2].zne.function-after[_validate_options(), ZneOptions].return_unextrapolated
  Unexpected keyword argument [type=unexpected_keyword_argument, input_value=True, input_type=bool]
    For further information visit https://errors.pydantic.dev/2.12/v/unexpected_keyword_argument
resilience.function-after[_validate_options(), ResilienceOptionsV2].zne.is-instance[Dict]
  Input should be an instance of Dict [type=is_instance_of, input_value={'amplifier': 'gate_foldi...n_unextrapolated': True}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/is_instance_of
resilience.is-instance[Dict]
  Input should be an instance of Dict [type=is_instance_of, input_value={'measure_mitigation': Tr...yer_noise_model': Unset}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.12/v/is_instance_of

miamico avatar Nov 25 '25 17:11 miamico