Skip to content

Commit

Permalink
Add options for summit PF (#1245)
Browse files Browse the repository at this point in the history
* Add options for summit PF

* Linting

* Cherry pick 1197
  • Loading branch information
chriseclectic committed Nov 30, 2023
1 parent 19df80f commit 012dfe9
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 11 deletions.
14 changes: 14 additions & 0 deletions qiskit_ibm_runtime/estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,20 @@ def _validate_options(self, options: dict) -> None:
"When the backend is a simulator and resilience_level == 3,"
"a coupling map is required."
)

zne_amplifier = options.get("resilience").get("zne_amplifier")
if zne_amplifier != "gate_folding":
if not options.get("execution").get("fast_parametric_update"):
raise ValueError(
f"Unable to use zne_amplifier = {zne_amplifier} with"
" fast_parametric_update=False",
)
if "parameters" not in self._backend.configuration().supported_features:
raise ValueError(
f"Unable to use zne_amplifier = {zne_amplifier} with a backend"
" that does not support 'parameters' feature.",
)

Options.validate_options(options)

@staticmethod
Expand Down
34 changes: 23 additions & 11 deletions qiskit_ibm_runtime/options/execution_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"""Execution options."""

from dataclasses import dataclass
from typing import Literal, get_args, Optional
from typing import Literal, get_args, Optional, Union
from numbers import Integral


Expand All @@ -22,7 +22,9 @@
"init_qubits",
"samples",
"shots_per_sample",
"interleave_samples",
"max_circuits",
"max_concurrent_jobs",
"fast_parametric_update",
]


Expand All @@ -34,7 +36,7 @@ class ExecutionOptions:
shots: Number of repetitions of each circuit, for sampling. Default: 4096.
init_qubits: Whether to reset the qubits to the ground state for each shot.
Default: ``True``.
Default: ``True``
samples: The number of samples of each measurement circuit to run. This
is used when twirling or resilience levels 1, 2, 3. If None it will
Expand All @@ -48,17 +50,27 @@ class ExecutionOptions:
``samples`` (if specified).
Default: None
interleave_samples: If True interleave samples from different measurement
circuits when running. If False run all samples from each measurement
circuit in order.
Default: False
max_circuits: Specify a custom maximum number of circuits run in a single job.
Default: None
max_concurrent_jobs: Specify a custom maximum number of concurrent jobs that can
be actively running on a backend during primitive execution. If `"auto"` this
will be set automatically depending on the backend type and capabilities.
Default: ``"auto"``
fast_parametric_update: Specify if parametric update should be used for execution
of parametric circuits. If ``"auto"`` it will be enabled automatically on
supported backends.
Default": ``"auto"``
"""

shots: int = 4096
init_qubits: bool = True
samples: Optional[int] = None
shots_per_sample: Optional[int] = None
interleave_samples: bool = False
max_circuits: Optional[int] = None
max_concurrent_jobs: Union[int, str] = "auto"
fast_parametric_update: Union[bool, str] = "auto"

@staticmethod
def validate_execution_options(execution_options: dict) -> None:
Expand Down Expand Up @@ -86,16 +98,16 @@ def validate_execution_options(execution_options: dict) -> None:
if not isinstance(shots, Integral):
raise ValueError(f"shots must be None or an integer, not {type(shots)}")
if shots < 0:
raise ValueError("shots must be None or >= 1")
raise ValueError("shots must be None or >= 0")
if samples is not None:
if not isinstance(samples, Integral):
raise ValueError(f"samples must be None or an integer, not {type(samples)}")
if samples < 0:
raise ValueError("samples must be None or >= 1")
raise ValueError("samples must be None or >= 0")
if shots_per_sample is not None:
if not isinstance(shots_per_sample, Integral):
raise ValueError(
f"shots_per_sample must be None or an integer, not {type(shots_per_sample)}"
)
if shots_per_sample < 0:
raise ValueError("shots_per_sample must be None or >= 1")
raise ValueError("shots_per_sample must be None or >= 0")
61 changes: 61 additions & 0 deletions qiskit_ibm_runtime/options/resilience_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ class ResilienceOptions:
Only applicable if ZNE is enabled.
Default: ``("exponential, "linear")``
zne_amplifier: The method to use when amplifying noise to the intended noise factors.
Default: `"gate_folding"`.
zne_stderr_threshold: A standard error threshold for accepting the ZNE result of Pauli basis
expectation values when using ZNE mitigation. Any extrapolator model resulting an larger
standard error than this value, or mean that is outside of the allowed range and threshold
Expand All @@ -87,6 +90,22 @@ class ResilienceOptions:
Only applicable if ZNE is enabled.
Default: 0.25
zne_return_all_extrapolated: If True return an array of the extrapolated expectation values
for all input ``zne_extrapolator`` models, along with the automatically selected
extrapolated value. If False only return the automatically selected extrapolated value.
Default: False
zne_return_unextrapolated: If True return the unextrapolated expectation values for each
of ihe input ``zne_noise_factors`` along with the extrapolated values as an array
valued result. If False only return the extrapolated values.
Default: False
zne_extrapolated_noise_factors: Specify 1 or more noise factor values to evaluate the
extrapolated models at. If a sequence of values the returned results will be array
valued with specified noise factor evaluated for the extrapolation model. A value
of 0 corresponds to zero-noise extrapolation.
Default: 0
pec_mitigation: Whether to turn on Probabilistic Error Cancellation error mitigation method.
By default, PEC is enabled for resilience level 3.
Expand All @@ -97,6 +116,34 @@ class ResilienceOptions:
sampling overhead.
Only applicable if PEC is enabled.
Default: 100
measure_noise_learning_shots: Specify a custom number of total shots to run for learning
the Pauli twirled measure noise when applying measure noise mitigation. If `"auto"`
the number of shots will be determined based on the execution options.
Default: ``"auto"``
measure_noise_learning_samples: Specify the number of twirling samples to run when
learning the Pauli twirled measure noise model.
Default: 32
layer_noise_learning_max_experiments: Specify the maximum number of layer noise learning
experiments that can be run when characterization layer noise for PEC.
Default: 3
layer_noise_learning_shots: Specify the total number of shots to run for each Pauli
twirled measurement circuit to run when learning the layer noise of an
individual layer for PEC.
Default: 4096
layer_noise_learning_samples: Specify the number of twirling samples to run per
measurement circuit when learning the layer noise of an individual layer for
PEC.
Default: 32.
layer_noise_learning_depths: Specify a custom sequence of layer pair depths to use when
running learning experiments for layer noise for PEC. If None a default
value will be used.
Default: None
"""

noise_amplifier: NoiseAmplifierType = None
Expand All @@ -113,12 +160,26 @@ class ResilienceOptions:
"exponential",
"linear",
)
zne_amplifier: str = "gate_folding"
zne_stderr_threshold: float = None
zne_return_all_extrapolated: bool = False
zne_return_unextrapolated: bool = False
zne_extrapolated_noise_factors: Union[float, Sequence[float]] = 0

# PEC
pec_mitigation: bool = None
pec_max_overhead: float = None

# Measure noise learning options
measure_noise_learning_shots: Union[int, Literal["auto"]] = "auto"
measure_noise_learning_samples: int = 32

# Layer noise learning options
layer_noise_learning_max_experiments: int = 3
layer_noise_learning_shots: int = 32 * 128
layer_noise_learning_samples: int = 32
layer_noise_learning_depths: Sequence[int] = None

@staticmethod
def validate_resilience_options(resilience_options: dict) -> None:
"""Validate that resilience options are legal.
Expand Down
3 changes: 3 additions & 0 deletions test/unit/test_data_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import subprocess
import tempfile
import warnings
from unittest import skip
from datetime import datetime

import numpy as np
Expand Down Expand Up @@ -91,6 +92,7 @@ def test_coder_qc(self):
decoded = [decoded]
self.assertTrue(all(isinstance(item, QuantumCircuit) for item in decoded))

@skip("Skip until qiskit-ibm-provider/736 is merged")
def test_coder_operators(self):
"""Test runtime encoder and decoder for operators."""

Expand Down Expand Up @@ -172,6 +174,7 @@ def test_encoder_ndarray(self):
decoded = json.loads(encoded, cls=RuntimeDecoder)
self.assertTrue(np.array_equal(decoded["ndarray"], obj["ndarray"]))

@skip("Skip until qiskit-ibm-provider/736 is merged")
def test_encoder_instruction(self):
"""Test encoding and decoding instructions"""
subtests = (
Expand Down

0 comments on commit 012dfe9

Please sign in to comment.