Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Barebone generic backend options #12747

Merged
merged 7 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
59 changes: 40 additions & 19 deletions qiskit/providers/fake_provider/generic_backend_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ def __init__(
calibrate_instructions: bool | InstructionScheduleMap | None = None,
dtm: float | None = None,
seed: int | None = None,
pulse_channels: bool = True,
noise_info: bool = True,
):
"""
Args:
Expand Down Expand Up @@ -159,6 +161,8 @@ def __init__(
None by default.

seed: Optional seed for generation of default values.
pulse_channels: If true, sets default pulse channel information on the backend.
noise_info: If true, associates gates and qubits with default noise information.
"""

super().__init__(
Expand All @@ -175,6 +179,10 @@ def __init__(
self._control_flow = control_flow
self._calibrate_instructions = calibrate_instructions
self._supported_gates = get_standard_gate_name_mapping()
self._include_errors = noise_info

if calibrate_instructions and not noise_info:
raise QiskitError("Must set parameter noise_info when calibrating instructions.")

if coupling_map is None:
self._coupling_map = CouplingMap().from_full(num_qubits)
Expand All @@ -198,7 +206,8 @@ def __init__(
self._basis_gates.append(name)

self._build_generic_target()
self._build_default_channels()
if pulse_channels:
self._build_default_channels()

@property
def target(self):
Expand Down Expand Up @@ -340,22 +349,31 @@ def _build_generic_target(self):
"""
# the qubit properties are sampled from default ranges
properties = _QUBIT_PROPERTIES
self._target = Target(
description=f"Generic Target with {self._num_qubits} qubits",
num_qubits=self._num_qubits,
dt=properties["dt"],
qubit_properties=[
QubitProperties(
t1=self._rng.uniform(properties["t1"][0], properties["t1"][1]),
t2=self._rng.uniform(properties["t2"][0], properties["t2"][1]),
frequency=self._rng.uniform(
properties["frequency"][0], properties["frequency"][1]
),
)
for _ in range(self._num_qubits)
],
concurrent_measurements=[list(range(self._num_qubits))],
)
if not self._include_errors:
self._target = Target(
description=f"Generic Target with {self._num_qubits} qubits",
num_qubits=self._num_qubits,
dt=properties["dt"],
qubit_properties=None,
concurrent_measurements=[list(range(self._num_qubits))],
)
else:
self._target = Target(
description=f"Generic Target with {self._num_qubits} qubits",
num_qubits=self._num_qubits,
dt=properties["dt"],
qubit_properties=[
QubitProperties(
t1=self._rng.uniform(properties["t1"][0], properties["t1"][1]),
t2=self._rng.uniform(properties["t2"][0], properties["t2"][1]),
frequency=self._rng.uniform(
properties["frequency"][0], properties["frequency"][1]
),
)
for _ in range(self._num_qubits)
],
concurrent_measurements=[list(range(self._num_qubits))],
)

# Generate instruction schedule map with calibrations to add to target.
calibration_inst_map = None
Expand All @@ -380,8 +398,11 @@ def _build_generic_target(self):
f"Provided basis gate {name} needs more qubits than {self.num_qubits}, "
f"which is the size of the backend."
)
noise_params = self._get_noise_defaults(name, gate.num_qubits)
self._add_noisy_instruction_to_target(gate, noise_params, calibration_inst_map)
if self._include_errors:
noise_params = self._get_noise_defaults(name, gate.num_qubits)
self._add_noisy_instruction_to_target(gate, noise_params, calibration_inst_map)
else:
self._target.add_instruction(gate, properties=None, name=name)

if self._control_flow:
self._target.add_instruction(IfElseOp, name="if_else")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
features:
- |
Added two parameters to :class:`.GenericBackendV2` to exclude error (`noise_info`) and
pulse channel information (`pulse_channels`) from the construction of the backend. These parameters
are true by default, replicating the initial default behavior of the constructor. A memory-sensitive
user may set these options to `False` to reduce the memory overhead by 40x when transpiling on large-
scale :class:`.GenericBackendV2`.
Loading