Specify Estimator options
Die Seide is noch nich ibersetzt worn. Se guggen de englsche Originalversion.
Package versions
The code on this page was developed using the following requirements. We recommend using these versions or newer.
qiskit[all]~=2.4.0
qiskit-ibm-runtime~=0.46.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:
# Added by doQumentation — required packages for this notebook
!pip install -q qiskit qiskit-ibm-runtime
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,
)
<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.
These precision parameters are only for specifying target precision, and the results are not guaranteed to reach the specified 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.
Although precision specified in the PUB and in run have higher precedence, the job fails if twirling is enabled and the product of num_randomizations and shots_per_randomization is smaller than the shots needed to achieve the precision. In this scenario, EstimatorV2 is unable to allocate the shots among the specified num_randomizations.
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,
)
<RuntimeJobV2('d8286b00bvlc73d1vn50', 'estimator')>
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 = 0
Available 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.
default_shots
The total number of shots to use per circuit per configuration.
Choices: Integer >= 0
Default: None
default_precision
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))
dynamical_decoupling
Control dynamical decoupling error mitigation settings.
dynamical_decoupling API documentation
dynamical_decoupling.enable
Choices: True, False
Default: False
dynamical_decoupling.extra_slack_distribution
Choices: middle, edges
Default: middle
dynamical_decoupling.scheduling_method
Choices: asap, alap
Default: alap
dynamical_decoupling.sequence_type
Choices: XX, XpXm, XY4
Default: XX
dynamical_decoupling.skip_reset_qubits
Choices: True, False
Default: False
environment
environment.callback
Callable function that receives the Job ID and Job result.
Choices: None
Default: None
environment.job_tags
List of tags.
Choices: None
Default: None
environment.log_level
Choices: DEBUG, INFO, WARNING, ERROR, CRITICAL
Default: WARNING
environment.private
Choices: True, False
Default: False
execution
execution.init_qubits
Whether to reset the qubits to the ground state for each shot.
Choices: True, False
Default: True
execution.rep_delay
The delay between a measurement and the subsequent quantum circuit.
Choices: Value in the range supplied by backend.rep_delay_range
Default: Given by backend.default_rep_delay
max_execution_time
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)
resilience
Advanced resilience options to fine tune the resilience strategy.
resilience.layer_noise_learning
Options for learning layer noise.
resilience.layer_noise_learning.layer_pair_depths
Choices: list[int] of 2-10 values in the range [0, 200]
Default: (0, 1, 2, 4, 16, 32)
resilience.layer_noise_learning.max_layers_to_learn
Choices: None, Integer >= 1
Default: 4
resilience.layer_noise_learning.num_randomizations
Choices: Integer >= 1
Default: 32
resilience.layer_noise_learning.shots_per_randomization
Choices: Integer >= 1
Default: 128
resilience.layer_noise_model
Choices: NoiseLearnerResult, Sequence[LayerError]
Default: None
resilience.measure_mitigation
Choices: True, False
Default: True
resilience.measure_noise_learning
Options for measurement noise learning.
resilience.measure_noise_learning.num_randomizations
Choices: Integer >= 1
Default: 32
resilience.measure_noise_learning.shots_per_randomization
Choices: Integer, auto
Default: auto
resilience.pec_mitigation
Choices: True, False
Default: False
resilience.pec
Probabilistic error cancellation mitigation options.
resilience.pec.max_overhead
Choices: None, Integer >= 1
Default: 100
resilience.pec.noise_gain
Choices: auto, float in the range [0, 1]
Default: auto
resilience.zne_mitigation
Choices: True, False
Default: False
resilience.zne
resilience.zne.amplifier
Choices: gate_folding, gate_folding_front, gate_folding_back, pea
Default: gate_folding
resilience.zne.extrapolated_noise_factors
Choices: List of floats
Default: [0, *noise_factors]
resilience.zne.extrapolator
Choices: One or more of: exponential, linear, double_exponential, polynomial_degree_(1 <= k <= 7), fallback
Default: (exponential, linear)
resilience.zne.noise_factors
Choices: List of floats; each float >= 1
Default: (1, 1.5, 2) for PEA, and (1, 3, 5) otherwise
resilience_level
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, 2
Default: 1
seed_estimator
simulator
Options to pass when simulating a backend
simulator.basis_gates
Choices: List of basis gate names to unroll to
Default: The set of all basis gates supported by Qiskit Aer simulator
simulator.coupling_map
Choices: List of directed two-qubit interactions
Default: None, which implies no connectivity constraints (full connectivity).
simulator.noise_model
Choices: Qiskit Aer NoiseModel, or its representation
Default: None
simulator.seed_simulator
Choices: Integer
Default: None
twirling
Twirling options
twirling.enable_gates
Choices: True, False
Default: False
twirling.enable_measure
Choices: True, False
Default: True
twirling.num_randomizations
Choices: auto, Integer >= 1
Default: auto
twirling.shots_per_randomization
Choices: auto, Integer >= 1
Default: auto
twirling.strategy
Choices: active, active-circuit, active-accum, all
Default: active-accum
experimental
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:
Fractional gates
Incompatible with:
- Gate twirling
- PEA
- PEC
Gate-folding ZNE
Might not work when using custom gates. Incompatible with:
- PEA
- PEC
Gate twirling
Incompatible with:
- Fractional gates
- Stretches
Other notes:
- Measurement twirling can only be applied to terminal measurements.
- Does not work with non-Clifford entanglers.
PEA
Incompatible with:
- Fractional gates
- Gate-folding ZNE
- PEC
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.