Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
174 changes: 141 additions & 33 deletions docs/guides/estimator-options.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,128 @@
"source": [
"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`](/docs/api/qiskit/qiskit.primitives.BaseEstimatorV2) and [`qiskit_aer.BaseEstimatorV2`](https://qiskit.github.io/qiskit-aer/stubs/qiskit_aer.primitives.EstimatorV2.html) options.\n",
"\n",
"Notes :\n",
"<Admonition type=\"note\" title=\"Notes about specifying options in the Estimator primitives\">\n",
"- You can see the available options and update option values during or after Estimator initialization.\n",
"- Use the `update()` method to apply changes to the `options` attribute.\n",
"- If you do not specify a value for an option, it is given a special value of `Unset` and the server defaults are used.\n",
"- The `options` attribute is the `dataclass` Python type. You can use the built-in `asdict` method to convert it to a dictionary.\n",
"</Admonition>\n",
"\n",
"<span id=\"pass-options\"></span>\n",
"## Set Estimator options\n",
"\n",
"You can set options when initializing Estimator, after initializing Estimator, or you can update the options after Estimator has been initialized. For instructions to use these techniques, see the [Introduction to options](/docs/guides/runtime-options-overview#options-precedence) topic.\n",
"You can set options when initializing Estimator, after initializing Estimator, or (for `precision` only), in the `run()` method.\n",
"\n",
"### Primitive initialization\n",
"\n",
"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.\n",
"\n",
"#### Options class\n",
"\n",
"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`\n",
"\n",
"Example:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "a20ed38a-31b7-4f0a-aed1-bd11046ab10e",
"metadata": {},
"outputs": [],
"source": [
"from qiskit_ibm_runtime import QiskitRuntimeService\n",
"from qiskit_ibm_runtime import EstimatorV2 as Estimator\n",
"from qiskit_ibm_runtime.options import EstimatorOptions\n",
"\n",
"service = QiskitRuntimeService()\n",
"backend = service.least_busy(operational=True, simulator=False)\n",
"\n",
"options = EstimatorOptions(\n",
" resilience_level=2,\n",
" resilience={\"zne_mitigation\": True, \"zne\": {\"noise_factors\": [1, 3, 5]}},\n",
")\n",
"\n",
"# or...\n",
"options = EstimatorOptions()\n",
"options.resilience_level = 2\n",
"options.resilience.zne_mitigation = True\n",
"options.resilience.zne.noise_factors = [1, 3, 5]\n",
"\n",
"estimator = Estimator(mode=backend, options=options)"
]
},
{
"cell_type": "markdown",
"id": "dc5ba623-45f2-4abf-9478-ff83490b480c",
"metadata": {},
"source": [
"#### Dictionary\n",
"\n",
"You can specify options as a dictionary when initializing Estimator."
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "869e4bf1-a7f9-4a66-8876-f327dcb87811",
"metadata": {},
"outputs": [],
"source": [
"from qiskit_ibm_runtime import QiskitRuntimeService\n",
"from qiskit_ibm_runtime import EstimatorV2 as Estimator\n",
"\n",
"service = QiskitRuntimeService()\n",
"backend = service.least_busy(operational=True, simulator=False)\n",
"\n",
"# Setting options during initialization\n",
"estimator = Estimator(\n",
" backend,\n",
" options={\n",
" \"resilience_level\": 2,\n",
" \"resilience\": {\n",
" \"zne_mitigation\": True,\n",
" \"zne\": {\"noise_factors\": [1, 3, 5]},\n",
" },\n",
" },\n",
")"
]
},
{
"cell_type": "markdown",
"id": "498899b6-3253-4348-9589-19dbbd6bc22b",
"metadata": {},
"source": [
"### Update options after initialization\n",
"\n",
"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.\n",
"\n",
"The `EstimatorV2` options class ([`EstimatorOptions`](/docs/api/qiskit-ibm-runtime/options-estimator-options)) does not need to be instantiated if you are setting options after initializing the primitive."
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "1cd195bb-50a5-4c64-aa0b-effb1ea621ce",
"metadata": {},
"outputs": [],
"source": [
"from qiskit_ibm_runtime import QiskitRuntimeService\n",
"from qiskit_ibm_runtime import EstimatorV2 as Estimator\n",
"\n",
"service = QiskitRuntimeService()\n",
"backend = service.least_busy(operational=True, simulator=False)\n",
"\n",
"estimator = Estimator(mode=backend)\n",
"\n",
"Additionally, you can set the `precision` value in the `run()` method, as is described in the following section."
"# Setting options after initialization\n",
"# This uses auto-complete.\n",
"estimator.options.default_precision = 0.01\n",
"# This does bulk update.\n",
"estimator.options.update(\n",
" default_precision=0.02, resilience={\"zne_mitigation\": True}\n",
")"
]
},
{
Expand All @@ -72,17 +188,17 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 16,
"id": "c0606f38-2bed-4b56-8202-708669e5ea66",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<RuntimeJobV2('d82868ftjchs73bnokm0', 'estimator')>"
"<RuntimeJobV2('d7amh42k86tc73a1sa20', 'estimator')>"
]
},
"execution_count": 1,
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -140,7 +256,7 @@
"\n",
"1. If the PUB specifies precision, use that value.\n",
"2. If the precision keyword argument is specified in `run`, use that value.\n",
"3. If `twirling` is enabled (True by default), then the product of `num_randomizations` and `shots_per_randomization`, as specified in [`twirling` options](/docs/api/qiskit-ibm-runtime/options-twirling-options), is used.\n",
"3. If `twirling` is enabled (True by default), then the product of `num_randomizations` and `shots_per_randomization`, as specified as [`twirling` options](/docs/api/qiskit-ibm-runtime/options-twirling-options), is used.\n",
"4. If `estimator.options.default_shots` is specified, use that value to control the amount of data.\n",
"5. If `estimator.options.default_precision` is specified, use that value.\n",
"\n",
Expand Down Expand Up @@ -756,47 +872,40 @@
"\n",
"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:\n",
"\n",
"<Tabs>\n",
"\n",
" <TabItem value=\"Fractional\" label=\"Fractional gates\">\n",
" Incompatible with:\n",
"<Accordion>\n",
" <AccordionItem title=\"Fractional gates\">\n",
" Incompatible with:\n",
" - Gate twirling\n",
" - PEA\n",
" - PEC\n",
"\n",
" </TabItem>\n",
"\n",
" <TabItem value=\"ZNE\" label=\"Gate-folding ZNE\">\n",
" Incompatible with:\n",
" </AccordionItem>\n",
" <AccordionItem title=\"Gate-folding ZNE\">\n",
" Might not work when using custom gates. Incompatible with:\n",
" - PEA\n",
" - PEC\n",
"\n",
" Might not work when using custom gates.\n",
" </TabItem>\n",
" <TabItem value=\"Twirling\" label=\"Gate twirling\">\n",
" Incompatible with fractional gates or with stretches.\n",
"\n",
" Other notes:\n",
" </AccordionItem>\n",
" <AccordionItem title=\"Gate twirling\">\n",
" Incompatible with:\n",
" - Fractional gates\n",
" - Stretches\n",
" \n",
" Other notes:\n",
" - Measurement twirling can only be applied to terminal measurements.\n",
" - Does not work with non-Clifford entanglers.\n",
"\n",
" </TabItem>\n",
"\n",
" <TabItem value=\"PEA\" label=\"PEA\">\n",
" </AccordionItem>\n",
" <AccordionItem title=\"PEA\">\n",
" Incompatible with:\n",
" - Fractional gates\n",
" - Gate-folding ZNE\n",
" - PEC\n",
" </TabItem>\n",
"\n",
" <TabItem value=\"PEC\" label=\"PEC\">\n",
" </AccordionItem>\n",
" <AccordionItem title=\"PEC\">\n",
" Incompatible with:\n",
" - Fractional gates\n",
" - Gate-folding ZNE\n",
" - PEA\n",
" </TabItem>\n",
"\n",
"</Tabs>"
" </AccordionItem>\n",
"</Accordion>"
]
},
{
Expand All @@ -807,7 +916,6 @@
"## Next steps\n",
"\n",
"<Admonition type=\"tip\" title=\"Recommendations\">\n",
" - Review the [Introduction to options](/docs/guides/runtime-options-overview) guide.\n",
" - Find more details about the `EstimatorV2` methods in the [Estimator API reference](/docs/api/qiskit-ibm-runtime/estimator-v2).\n",
" - Decide what [execution mode](/docs/guides/execution-modes) to run your job in.\n",
" - Learn about [noise management with Estimator](/docs/guides/estimator-noise-management).\n",
Expand Down
39 changes: 17 additions & 22 deletions docs/guides/sampler-options.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -485,40 +485,35 @@
"\n",
"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:\n",
"\n",
"<Tabs>\n",
" <TabItem value=\"Dynamic\" label=\"Dynamic circuits\">\n",
" Incompatible with:\n",
"<Accordion>\n",
" <AccordionItem title=\"Dynamic circuits\">\n",
" Incompatible with:\n",
" - Dynamical decoupling\n",
"\n",
" Other notes:\n",
" - Gate twirling can be applied to dynamic circuits, but only to gates not inside conditional blocks. Measurement twirling can only be applied to terminal measurements.\n",
" - Compatible with fractional gates when using `qiskit-ibm-runtime` v0.42.0 or later.\n",
"\n",
" </TabItem>\n",
" <TabItem value=\"DD\" label=\"Dynamical decoupling\">\n",
" Incompatible with dynamic circuits.\n",
"\n",
" </TabItem>\n",
"\n",
" <TabItem value=\"Fractional\" label=\"Fractional gates\">\n",
" Incompatible with:\n",
" </AccordionItem>\n",
" <AccordionItem title=\"Dynamical decoupling\">\n",
" Incompatible with:\n",
" - Dynamic circuits\n",
" </AccordionItem>\n",
" <AccordionItem title=\"Fractional gates\">\n",
" Incompatible with:\n",
" - Gate twirling\n",
"\n",
" Compatible with dynamic circuits when using `qiskit-ibm-runtime` v0.42.0 or later.\n",
"\n",
" </TabItem>\n",
"\n",
" <TabItem value=\"Twirling\" label=\"Gate twirling\">\n",
" Incompatible with fractional gates or with stretches.\n",
" </AccordionItem>\n",
" <AccordionItem title=\"Gate twirling\">\n",
" Incompatible with:\n",
" - Fractional gates\n",
" - Stretches\n",
"\n",
" Other notes:\n",
" - Gate twirling can be applied to dynamic circuits, but only to gates not inside conditional blocks. Measurement twirling can only be applied to terminal measurements.\n",
" - Does not work with non-Clifford entanglers.\n",
"\n",
" </TabItem>\n",
"\n",
"\n",
"</Tabs>"
" </AccordionItem>\n",
"</Accordion>"
]
},
{
Expand Down
Loading