One option is to create a new class that inherits from GenericBackendV2
and accepts "noise settings". The below code shows how to do that
class MyFakeBackend(GenericBackendV2):
def __init__(
self,
num_qubits: int,
basis_gates: list[str] | None = None,
*,
coupling_map: list[list[int]] | CouplingMap | None = None,
control_flow: bool = False,
calibrate_instructions: bool | InstructionScheduleMap | None = None,
noise_settings: dict,
dtm: float | None = None,
seed: int | None = None,
):
self.noise_settings = noise_settings
super().__init__(num_qubits, basis_gates,
coupling_map=coupling_map,
control_flow=control_flow,
calibrate_instructions=calibrate_instructions,
dtm=dtm,
seed=seed)
def _get_noise_defaults(self, name: str, num_qubits: int) -> tuple:
if name in self.noise_settings:
return self.noise_settings[name]
if num_qubits == 1:
return _NOISE_DEFAULTS_FALLBACK["1-q"]
return _NOISE_DEFAULTS_FALLBACK["multi-q"]
Now, you can instantiate your fake backend as follow:
cmap = CouplingMap.from_full(27)
noise_settings = {
"cz": (7.992e-08, 8.99988e-07, 1e-5, 5e-3),
"id": (2.997e-08, 5.994e-08, 9e-5, 1e-4),
"rz": (0.0, 0.0),
"sx": (2.997e-08, 5.994e-08, 9e-5, 1e-4),
"x": (2.997e-08, 5.994e-08, 9e-5, 1e-4),
"measure": (6.99966e-07, 1.500054e-06, 1e-5, 5e-3),
"delay": (None, None),
"reset": (None, None),
}
fake = MyFakeBackend(num_qubits=27,
basis_gates=['cz', 'id', 'rz', 'sx', 'x'],
coupling_map=cmap,
noise_settings=noise_settings)
Note that, noise_settings
follows the same structure used internally in GenericBackendV2
for defining _NOISE_DEFAULTS
, where there are two possible formats:
(min_duration, max_duration, min_error, max_error)
, for ranges.
(duration, error)
, for fixed values.