Specify Estimator options
Package versions
The code on this page was developed using the following requirements. We recommend using these versions or newer.
qiskit[all]~=2.3.0
qiskit-ibm-runtime~=0.43.1
You can use options to customize the Estimator primitive. While the interface of the primitives' run() method is common across all implementations, their options are not. Consult the API references for information about the qiskit.primitives.BaseEstimatorV2 and qiskit_aer.BaseEstimatorV2 options.
Notes :
- You can see the available options and update option values during or after Estimator initialization.
- Use the
update()method to apply changes to theoptionsattribute. - If you do not specify a value for an option, it is given a special value of
Unsetand the server defaults are used. - The
optionsattribute is thedataclassPython type. You can use the built-inasdictmethod to convert it to a dictionary.
Set Estimator options
You can set options when initializing Estimator, after initializing Estimator, or (for precision only), in the run() method.
Primitive initialization
You can pass in an instance of the options class or a dictionary when initializing Estimator, which then makes a copy of those options. Thus, changing the original dictionary or options instance doesn't affect the options owned by the primitive.
Options class
When creating an instance of the EstimatorV2 class, you can pass in an instance of the options class. Those options will then be applied when you use run() to perform the calculation. Specify the options in this format: options.option.sub-option.sub-sub-option = choice. For example: options.dynamical_decoupling.enable = True
Example:
from qiskit_ibm_runtime import QiskitRuntimeService
from qiskit_ibm_runtime import EstimatorV2 as Estimator
from qiskit_ibm_runtime.options import EstimatorOptions
service = QiskitRuntimeService()
backend = service.least_busy(operational=True, simulator=False)
options = EstimatorOptions(
resilience_level=2,
resilience={"zne_mitigation": True, "zne": {"noise_factors": [1, 3, 5]}},
)
# or...
options = EstimatorOptions()
options.resilience_level = 2
options.resilience.zne_mitigation = True
options.resilience.zne.noise_factors = [1, 3, 5]
estimator = Estimator(mode=backend, options=options)Dictionary
You can specify options as a dictionary when initializing Estimator.
from qiskit_ibm_runtime import QiskitRuntimeService
from qiskit_ibm_runtime import EstimatorV2 as Estimator
service = QiskitRuntimeService()
backend = service.least_busy(operational=True, simulator=False)
# Setting options during initialization
estimator = Estimator(
backend,
options={
"resilience_level": 2,
"resilience": {
"zne_mitigation": True,
"zne": {"noise_factors": [1, 3, 5]},
},
},
)Update options after initialization
You can specify the options in this format: estimator.options.option.sub-option.sub-sub-option = choice to take advantage of auto-complete, or use the update() method to make bulk updates.
The EstimatorV2 options class (EstimatorOptions) does not need to be instantiated if you are setting options after initializing the primitive.
from qiskit_ibm_runtime import QiskitRuntimeService
from qiskit_ibm_runtime import EstimatorV2 as Estimator
service = QiskitRuntimeService()
backend = service.least_busy(operational=True, simulator=False)
estimator = Estimator(mode=backend)
# Setting options after initialization
# This uses auto-complete.
estimator.options.default_precision = 0.01
# This does bulk update.
estimator.options.update(
default_precision=0.02, resilience={"zne_mitigation": True}
)Run() method
The only values you can pass to run() are those defined in the interface. That is, precision for Estimator. This overwrites any value set for default_precision for the current run.
from qiskit_ibm_runtime import QiskitRuntimeService
from qiskit_ibm_runtime import EstimatorV2 as Estimator
from qiskit.circuit.library import random_iqp
from qiskit.transpiler import generate_preset_pass_manager
from qiskit.quantum_info import SparsePauliOp
service = QiskitRuntimeService()
backend = service.least_busy(operational=True, simulator=False)
circuit1 = random_iqp(3)
circuit1.measure_all()
circuit2 = random_iqp(3)
circuit2.measure_all()
observable = SparsePauliOp("Z" * 3)
pass_manager = generate_preset_pass_manager(
optimization_level=3, backend=backend
)
transpiled1 = pass_manager.run(circuit1)
transpiled2 = pass_manager.run(circuit2)
isa_observable1 = observable.apply_layout(transpiled1.layout)
isa_observable2 = observable.apply_layout(transpiled2.layout)
estimator = Estimator(mode=backend)
# Default precision to use if not specified in run()
estimator.options.default_precision = 0.01
# Run two circuits, requiring a precision of .02 for both.
estimator.run(
[(transpiled1, isa_observable1), (transpiled2, isa_observable2)],
precision=0.02,
)Output:
<RuntimeJobV2('d7amh42k86tc73a1sa20', 'estimator')>
Special case: precision
The EstimatorV2.run method accepts two arguments: a list of PUBs, each of which can specify a PUB-specific value for precision, and a precision keyword argument. These precision values are a part of the Estimator execution interface, and are independent of the Runtime Estimator's options. They take precedence over any values specified as options in order to comply with the Estimator abstraction.
However, if precision is not specified by any PUB or in the run keyword argument (or if they are all None), then the precision value from the options is used, most notably default_precision.
Note that Estimator options contain both default_shots and default_precision. However, because gate-twirling is enabled by default, the product of num_randomizations and shots_per_randomization takes precedence over those two options.
Specifically, for any Estimator PUB:
- If the PUB specifies precision, use that value.
- If the precision keyword argument is specified in
run, use that value. - If
twirlingis enabled (True by default), then the product ofnum_randomizationsandshots_per_randomization, as specified astwirlingoptions, is used. - If
estimator.options.default_shotsis specified, use that value to control the amount of data. - If
estimator.options.default_precisionis specified, use that value.
For example, if precision is specified in all four places, the one with highest precedence (precision specified in the PUB) is used.
Precision scales inversely with usage. That is, the lower the precision, the more QPU time it takes to run.
from qiskit_ibm_runtime import QiskitRuntimeService
from qiskit_ibm_runtime import EstimatorV2 as Estimator
from qiskit.circuit.library import random_iqp
from qiskit.transpiler import generate_preset_pass_manager
from qiskit.quantum_info import SparsePauliOp
service = QiskitRuntimeService()
backend = service.least_busy(operational=True, simulator=False)
observable = SparsePauliOp("Z" * 3)
circuit = random_iqp(3)
circuit.measure_all()
pass_manager = generate_preset_pass_manager(
optimization_level=3, backend=backend
)
isa_circuit = pass_manager.run(circuit)
isa_observable = observable.apply_layout(isa_circuit.layout)
# Setting precision during primitive initialization
estimator = Estimator(mode=backend, options={"default_precision": 0.05})
# Run with precision=0.02, overwriting the default.
estimator.run(
[(isa_circuit, isa_observable1)],
precision=0.02,
)Turn off all error mitigation and error suppression
You can turn off all error mitigation and suppression if you are, for example, doing research on your own mitigation techniques. To accomplish this, set resilience_level = 0.
Example:
from qiskit_ibm_runtime import EstimatorV2 as Estimator, QiskitRuntimeService
# Define the service. This allows you to access an IBM QPU.
service = QiskitRuntimeService()
# Get a backend
backend = service.least_busy(operational=True, simulator=False)
# Define Estimator
estimator = Estimator(backend)
options = estimator.options
# Turn off all error mitigation and suppression
options.resilience_level = 0Available options
The following table documents options from the latest version of qiskit-ibm-runtime. To see older option versions, visit the qiskit-ibm-runtime API reference and select a previous version.
The total number of shots to use per circuit per configuration.
Choices: Integer >= 0
Default: None
The default precision to use for any PUB or
run()call that does not specify one.Choices: Float > 0
Default: 0.015625 (1 / sqrt(4096))
Control dynamical decoupling error mitigation settings.
dynamical_decouplingAPI documentationChoices:
True,FalseDefault:
FalseChoices:
middle,edgesDefault:
middleChoices:
asap,alapDefault:alapChoices:
XX,XpXm,XY4Default:XXChoices:
True,FalseDefault:False
Callable function that receives the
Job IDandJob result.Choices: None
Default: None
List of tags.
Choices: None
Default: None
Choices: DEBUG, INFO, WARNING, ERROR, CRITICAL
Default: WARNING
Choices:
True,FalseDefault:
False
Whether to reset the qubits to the ground state for each shot.
Choices:
True,FalseDefault:
TrueThe delay between a measurement and the subsequent quantum circuit.
Choices: Value in the range supplied by
backend.rep_delay_rangeDefault: Given by
backend.default_rep_delay
Limits how long a job can run, in seconds. See the maximum execution time guide for details.
Choices: Integer number of seconds in the range [1, 10800]
Default: 10800 (3 hours)
Advanced resilience options to fine tune the resilience strategy.
Options for learning layer noise.
Choices: list[int] of 2-10 values in the range [0, 200]
Default:
(0, 1, 2, 4, 16, 32)Choices: None, Integer >= 1
Default:
4Choices: Integer >= 1
Default:
32Choices: Integer >= 1
Default:
128Choices:
NoiseLearnerResult,Sequence[LayerError]Default: None
Choices:
True,FalseDefault:
TrueOptions for measurement noise learning.
Choices: Integer >= 1
Default:
32Choices: Integer,
autoDefault:
autoChoices:
True,FalseDefault:
FalseProbabilistic error cancellation mitigation options.
Choices:
None, Integer >= 1Default:
100Choices:
auto, float in the range [0, 1]Default:
autoChoices:
True,FalseDefault:
FalseChoices:
gate_folding,gate_folding_front,gate_folding_back,peaDefault:
gate_foldingChoices: List of floats
Default:
[0, *noise_factors]Choices: One or more of:
exponential,linear,double_exponential,polynomial_degree_(1 <= k <= 7),fallbackDefault:
(exponential, linear)Choices: List of floats; each float >= 1
Default:
(1, 1.5, 2)forPEA, and(1, 3, 5)otherwise
How much resilience to build against errors. Higher levels generate more accurate results at the expense of longer processing times. See the resilience levels section in the Noise management topic to learn more.
Choices:
0,1,2Default:
1Options to pass when simulating a backend
Choices: List of basis gate names to unroll to
Default: The set of all basis gates supported by Qiskit Aer simulator
Choices: List of directed two-qubit interactions
Default: None, which implies no connectivity constraints (full connectivity).
Choices: Qiskit Aer NoiseModel, or its representation
Default: None
Choices: Integer
Default: None
Twirling options
Choices: True, False
Default: False
Choices: True, False
Default: True
Choices:
auto, Integer >= 1Default:
autoChoices:
auto, Integer >= 1Default:
autoChoices:
active,active-circuit,active-accum,allDefault:
active-accum
Experimental options, when available.
Feature compatibility
Certain runtime features cannot be used together in a single job. Click the appropriate tab for a list of features that are incompatible with the selected feature:
Incompatible with:
- Gate twirling
- PEA
- PEC
Incompatible with:
- PEA
- PEC
Might not work when using custom gates.
Incompatible with fractional gates or with stretches.
Other notes:
- Measurement twirling can only be applied to terminal measurements.
- Does not work with non-Clifford entanglers.
Incompatible with:
- Fractional gates
- Gate-folding ZNE
- PEC
Incompatible with:
- Fractional gates
- Gate-folding ZNE
- PEA
Next steps
- Find more details about the
EstimatorV2methods in the Estimator API reference. - Decide what execution mode to run your job in.
- Learn about noise management with Estimator.